Advertisement
UF6

Group project 2, Problem 5

UF6
May 4th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #Josh
  2. %matplotlib notebook
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. def plot_fun(ax,x,t):
  7.     ax.cla()
  8.     ax.plot(x,y,lw=2)
  9.     ax.set_xlim([-1,1]), ax.set_ylim([-1.5,1.5])
  10.     ax.set_xlabel('x'), ax.set_ylabel('f(x,t)')
  11.  
  12. fig = plt.figure()
  13. ax = plt.axes()
  14.  
  15. x = np.linspace(-1, 1, 101)
  16.  
  17. t = 0
  18. y = 1/(1+16*((x-t)**2))
  19. plot_fun(ax,x,t)
  20. plt.show()
  21.  
  22. tfin = 1
  23. k = 0.01
  24. while t < tfin:
  25.     t = t + k
  26.     y = 1/(1+16*((x-t)**2))
  27.     plot_fun(ax,x,t)
  28.     plt.draw()
  29.     fig.canvas.draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement