Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- from math import exp
- def get_x(T, x0, h, a):
- all_x = [x0]
- x_prior = x0
- for i in range(0, int(T/h)):
- x = x_prior + x_prior*h*a
- all_x.append(x)
- x_prior = x
- return all_x
- def get_x_2(T, x0, a, h, time):
- all_x = [x0]
- x_prior = x0
- for i in range(0, int(T/h)):
- x = x_prior * exp(a*time[i])
- all_x.append(x)
- x_prior = x
- return all_x
- def get_x_4(T, x0, a, h):
- all_x = [x0]
- x_prior = x0
- for i in range(0, int(T / h)):
- x = x_prior * exp(a * i)
- all_x.append(x)
- x_prior = x
- return all_x
- #print(get_x_3(13,0.2))
- fig = plt.figure()
- T, x0, t0, h, a1, a2 = 13, 1, 0, 0.8, 1, -1
- y = np.arange(t0, T, h).tolist()
- x1 = get_x(T, x0, h, a1)
- x2 = get_x(T, x0, h, a2)
- x3 = get_x_2(T, x0, a1, h, y)
- x4 = get_x_2(T, x0, a2, h, y)
- x41 = get_x_4(T, x0, a2, h)
- print(x4)
- print(x41)
- ax1 = fig.add_subplot(211)
- ax1.plot(y,x1)
- ax1.plot(y,x3,'1')
- ax2 = fig.add_subplot(212)
- ax2.plot(y,x2)
- ax2.plot(y,x4,'1')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement