Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from math import exp
  4.  
  5. def get_x(T, x0, h, a):
  6. all_x = [x0]
  7. x_prior = x0
  8. for i in range(0, int(T/h)):
  9. x = x_prior + x_prior*h*a
  10. all_x.append(x)
  11. x_prior = x
  12. return all_x
  13.  
  14. def get_x_2(T, x0, a, h, time):
  15. all_x = [x0]
  16. x_prior = x0
  17. for i in range(0, int(T/h)):
  18. x = x_prior * exp(a*time[i])
  19. all_x.append(x)
  20. x_prior = x
  21. return all_x
  22.  
  23. def get_x_4(T, x0, a, h):
  24. all_x = [x0]
  25. x_prior = x0
  26. for i in range(0, int(T / h)):
  27. x = x_prior * exp(a * i)
  28. all_x.append(x)
  29. x_prior = x
  30. return all_x
  31.  
  32. #print(get_x_3(13,0.2))
  33.  
  34. fig = plt.figure()
  35.  
  36. T, x0, t0, h, a1, a2 = 13, 1, 0, 0.8, 1, -1
  37.  
  38. y = np.arange(t0, T, h).tolist()
  39.  
  40. x1 = get_x(T, x0, h, a1)
  41. x2 = get_x(T, x0, h, a2)
  42. x3 = get_x_2(T, x0, a1, h, y)
  43. x4 = get_x_2(T, x0, a2, h, y)
  44. x41 = get_x_4(T, x0, a2, h)
  45. print(x4)
  46. print(x41)
  47.  
  48. ax1 = fig.add_subplot(211)
  49. ax1.plot(y,x1)
  50. ax1.plot(y,x3,'1')
  51.  
  52. ax2 = fig.add_subplot(212)
  53. ax2.plot(y,x2)
  54. ax2.plot(y,x4,'1')
  55.  
  56. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement