30 lines
837 B
Python
30 lines
837 B
Python
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
from copy import deepcopy
|
|
|
|
tau = 0.25 # Size of the time step
|
|
N = 4 # Number of grid points
|
|
c = 1 # Normalized speed of light
|
|
L = 1 # Size of the system
|
|
h = L / N # Spacing of grids (0.25)
|
|
hct = h / (c*tau) # 1 here
|
|
coef = 1 / 2*(hct) # 1/2 here
|
|
sig = 1 # Width of the pulse
|
|
|
|
z = np.arange(-L/2 + h/2, L/2 + h/2, h)
|
|
|
|
phi = [0, 1, 1, 0]
|
|
|
|
phinew = [0]*N
|
|
|
|
steps = 5
|
|
for i in range(steps):
|
|
for k in range(N):
|
|
if k != 0 and k != N-1:
|
|
phinew[k] = (0.5 - coef)*phi[k+1] + (0.5 + coef)*phi[k-1]
|
|
else:
|
|
phinew[0] = (0.5 - coef)*phi[1] + (0.5 + coef)*phi[N-1]
|
|
phinew[N-1] = (0.5 - coef)*phi[0] + (0.5 + coef)*phi[N-2]
|
|
phi = deepcopy(phinew)
|
|
print(phi)
|