Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import matplotlib
- import matplotlib.pyplot as plt
- import math
- n = 20000
- h = 0.000051
- y = [1]
- z = [5]
- t = [6]
- x = []
- for i in range (0, n):
- x.append(i*h)
- for _ in range (1, n):
- tmp_y = y[-1] + h*(z[-1])
- tmp_z = z[-1] + h*(t[-1])
- tmp_t = t[-1] + h*(-12*t[-1] - 48*z[-1] - 64*y[-1])
- y.append(tmp_y)
- z.append(tmp_z)
- t.append(tmp_t)
- x1 = [0]
- y1 = [1]
- for i in range (1, n):
- x1.append(i*h)
- y1.append(math.exp((-4)*x1[-1]) + 9*x1[-1]*math.exp((-4)*x1[-1]) + 31*math.exp((-4)*x1[-1])*x1[-1]**2)
- plt.plot(x,y)
- plt.plot(x1,y1)
- plt.show()
- d = []
- for i in range(1, n):
- d.append(abs(y[i]-y1[i])/y[i])
- print(max(d)*100, '%')
Add Comment
Please, Sign In to add comment