-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiffusion_images.py
More file actions
38 lines (33 loc) · 944 Bytes
/
diffusion_images.py
File metadata and controls
38 lines (33 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
import matplotlib.pyplot as plt
# implement equation 6.11
def tg(x, t, x0=0, kappa=1):
"""
Return a normalized Gaussian of x, centered at x0
with sigma = sqrt(2*kappa*t)
"""
sigma = np.sqrt(2*kappa*t)
prefactor = 1.0/(sigma*np.sqrt(2*np.pi))
expl = np.exp(-(x-x0)**2/(2*sigma**2))
return(prefactor*expl)
# implement equation 6.16
def T_analy(x, t, L=1):
"""
returns analytical solution to diffusion eqn
using method of images
"""
Nval = 50 # why 50? it seemed to work. 10 was also OK.
Tsum = 0
for n in range(-Nval, Nval): # sum the Gaussians
Tsum += (-1)**n * tg(x + n*L, t)
return(Tsum)
def main():
# reproducing Figure 6.6, bottom panel
L = 1
xpts = np.arange(-1.5*L, 1.5*L, step=0.1)
T1 = T_analy(xpts, 0.03)
fig,ax = plt.subplots()
ax.plot(xpts, T1)
ax.set_xlabel('x/L')
ax.set_ylabel('T(x,t)')
plt.show()