Consider a 2D Poisson equation $$ \Delta u \equiv \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = f, \quad (x,y)\in [0,1]^2 $$ with boundary conditions as follows $$ u\big|_{x=0} = 0, \quad u\big|_{x=1} = 0, \quad \frac{\partial u}{\partial y} \big|_{y=0} = 0, \quad \frac{\partial u}{\partial y}\big|_{y=1} = 0, $$ with known function $f$ and unknown $u$. Choose $f(x,y)$ such that $\sin\pi x \cos \pi y $ is a solution.
In [1]:
Consider a 1D first kind Fredholm equation $$ \left( Au \right)(x)\equiv \int_0^1 K(x,y) u(y) dy = f(x),\quad x\in [0,1] \quad (1) $$ with known functions $K(x,y)$, $f(x)$ and unknown $u(x)$.
In [15]:
#http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/Interactive%20Widgets/Using%20Interact.ipynb
%matplotlib inline
from IPython.html.widgets import interact
from IPython.display import display
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
plt.close(fig)
def set_cursor(x):
ax.clear()
ax.set_xlim([0, np.pi])
ax.set_ylim([-1, 1])
x1 = np.linspace(0,np.pi,50)
ax.plot(x1, np.sin(x * x1))
display(fig)
interact(set_cursor, x=(1., 2., 0.1))
In [ ]:
Consider the following time dependent equation in 2D $$ \frac{\partial u}{\partial t} = \Delta u, \quad (x,y)\in [0,1]^2, \quad t\in [0,1] $$ $$ u(x,y)\big|_{t=0} = \sin\pi x \cos \pi y, $$ with boundary conditions from the Problem 1. Spatial discretization looks as follows $$ \frac{du_h}{dt} = A_h u_h, $$ where $A_h\in \mathbb{R}^{256^2 \times 256^2}$ is a matrix from the Problem 1. To solve this equation one can use several approaches:
Explicit scheme (Euler scheme) $$ \frac{u_h^{i+1} - u_h^{i}}{\tau} = A_h u_h^{i}, \quad i=1,\dots,N_\tau, \quad N_\tau \tau = 1 $$
Implicit scheme $$ \frac{u_h^{i+1} - u_h^{i}}{\tau} = A_h u_h^{i+1}, \quad i=1,\dots,N_\tau, \quad N_\tau \tau = 1 $$
Matrix exponential $$ u_h(t) = e^{At}u_h(0) $$
In [ ]: