Advertisement
Sephinroth

3

Apr 5th, 2020
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4. import math
  5.  
  6. n = 20000
  7. h = 0.0001
  8. e = math.exp(1)
  9. y = [0]
  10. z = [0]
  11. t = [0]
  12. x = []
  13. for i in range (0, n):
  14.     x.append(i*h)
  15.    
  16. for i 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 - 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 = [0]
  25. for i in range (1, n):
  26.     x1.append(i*h)
  27.     y1.append((3/16) - (3/16)*e**((-4)*x1[-1]) - (3/4)*x1[-1]*e**((-4)*x1[-1]) - (3/2) * x1[-1]**2 * e**((-4) * x1[-1]))
  28. plt.plot(x,y)
  29. plt.plot(x1,y1)
  30. plt.show()
  31.  
  32. d = []
  33. for i in range(1, n):
  34.     if i > 10000:
  35.         d.append(abs(y[i]-y1[i])/y[i])
  36. print(max(d)*100, '%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement