Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- # x' = y
- # y' = - x - a * y
- T_s = 0
- T_f = 20
- h = 0.01
- a = 0.5
- x_init = 1
- y_init = 0
- t = np.arange(T_s, T_f, h)
- x = np.zeros(t.shape)
- y = np.zeros(t.shape)
- x[0] = y_init
- y[0] = x_init
- for i in range(t.size-1):
- x[i+1] = x[i] + h * y[i]
- y[i+1] = y[i] + h * (-x[i] - a * y[i])
- plt.plot(t, x, t, y, markersize=3)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement