Advertisement
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 = 100000
- h = 0.00001
- e = math.exp(1)
- y = [0]
- z = [0]
- t = [0]
- x = []
- for i in range (0, n):
- x.append(i*h)
- for i in range (1, n):
- tmp_y = y[-1] + h*(z[-1])
- tmp_z = z[-1] + h*(t[-1])
- tmp_t = t[-1] + h*(12 - 12*t[-1] - 48*z[-1] - 64*y[-1])
- y.append(tmp_y)
- z.append(tmp_z)
- t.append(tmp_t)
- x1 = [0]
- y1 = [0]
- for _ in range (1, n):
- x1.append(i*h)
- 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]))
- plt.plot(x,y)
- plt.plot(x1,y1)
- plt.show()
- d = []
- for i in range(0, n):
- if y[i] > 0:
- d.append(abs(y[i]-y1[i])/y[i])
- print(max(d)*100, '%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement