Sephinroth

2

Apr 5th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import matplotlib
  4. import matplotlib.pyplot as plt
  5. import math
  6.  
  7. n = 20000
  8. h = 0.000051
  9. y = [1]
  10. z = [5]
  11. t = [6]
  12. x = []
  13. for i in range (0, n):
  14.     x.append(i*h)
  15.    
  16. for _ in range (1, n):
  17.     tmp_y = y[-1] + h*(z[-1])
  18.     tmp_z = z[-1] + h*(t[-1])
  19.     tmp_t = t[-1] + h*(-12*t[-1] - 48*z[-1] - 64*y[-1])
  20.     y.append(tmp_y)
  21.     z.append(tmp_z)
  22.     t.append(tmp_t)
  23. x1 = [0]
  24. y1 = [1]
  25. for i in range (1, n):
  26.     x1.append(i*h)
  27.     y1.append(math.exp((-4)*x1[-1]) + 9*x1[-1]*math.exp((-4)*x1[-1]) + 31*math.exp((-4)*x1[-1])*x1[-1]**2)
  28. plt.plot(x,y)
  29. plt.plot(x1,y1)
  30. plt.show()
  31.  
  32. d = []
  33. for i in range(1, n):
  34.    d.append(abs(y[i]-y1[i])/y[i])
  35.  
  36. print(max(d)*100, '%')
Add Comment
Please, Sign In to add comment