Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import math
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- from time import sleep
- imp = 337.0
- x_steps = 100
- t_steps = 100
- x_borders = 1.0
- time = 1.0
- dx = x_borders/x_steps
- dt = time/t_steps
- s = dt/dx
- print(s)
- print(dt,dx)
- mid = int(x_steps/2)
- def init():
- Ez = np.zeros(x_steps)
- Hy = np.zeros(x_steps)
- return Ez,Hy
- def solve(i):
- Hy[x_steps-1] = Hy[x_steps-2]
- for j in range(x_steps-1):
- Hy[j] = Hy[j] + (Ez[j+1]-Ez[j])/imp
- Ez[0] = Ez[1]
- for j in range(1,x_steps):
- Ez[j] = Ez[j] +(Hy[j]-Hy[j-1])*imp
- Ez[mid] = math.exp(-(i-0.5/dt)**2/(0.5/dt))
- Hy[x_steps-1] = Hy[x_steps-2]
- for j in range(x_steps-1):
- Hy[j] = Hy[j] + (Ez[j+1]-Ez[j])/imp
- Ez[0] = Ez[1]
- for j in range(1,x_steps):
- Ez[j] = Ez[j] +(Hy[j]-Hy[j-1])*imp
- Ez[mid]= math.exp(-((i+1.0)-0.5/dt)**2/(0.5/dt))
- ax.clear()
- coor = np.linspace(0,x_borders,x_steps)
- ax.plot(coor,Ez)
- tmp1 = dt*i
- s = "%.2f" % tmp1
- ax.set_title('Time '+s +' sec ' + str(i))
- Ez,Hy = init()
- fig= plt.figure()
- ax = fig.add_subplot(111)
- # ax2 = fig.add_subplot(212)
- ani = animation.FuncAnimation(fig,solve,interval=1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement