Advertisement
Sephinroth

prog for lab

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