In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
l = 4
N = 100
x = np.linspace(-l/2,l/2,N)
y = np.linspace(-l/2,l/2,N)
X,Y = np.meshgrid(x,y)
In [6]:
dt =1e-4
Niter=1000
D=1
t = Niter*dt
P = 1/(4*np.pi*D*t)*np.exp(-(X**2+Y**2)/(4*D*t) )
In [8]:
plt.imshow(P)
Out[8]:
In [10]:
plt.plot( X[50,:],P[50,:])
Out[10]:
In [13]:
u = np.zeros((N,N))
dx = l/ (N-1.)
u[N//2, N//2 ]= 1.0/dx**2
C = D*dt/ (dx**2)
print C
In [14]:
for i in range(Niter):
u[1:-1,1:-1] = u[1:-1,1:-1] +\
C*(u[1:-1,:-2]+ u[1:-1,2:]+ u[:-2, 1:-1]+ u[2:,1:-1] -\
4*u[1:-1,1:-1])
In [15]:
plt.imshow(u)
Out[15]:
In [ ]:
Zaimplementować ten sam algorytm z np.diff(..., axis=...)
In [13]:
Out[13]: