Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MatveyPanchenko DSAI-03
- import numpy as np, matplotlib.pyplot as plt
- from scipy.integrate import solve_ivp
- osc = lambda t, y: (y[1], -y[0]) # x' = v, v' = –x
- sol = solve_ivp(osc, (0, 10), (1., 0.), t_eval=np.linspace(0, 10, 200))
- t, x, v = sol.t, *sol.y
- fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
- ax1.plot(t, x, label='x(t)')
- ax1.plot(t, v, label='v(t)')
- ax1.set(title='Time Domain', xlabel='t'); ax1.legend(); ax1.grid()
- ax2.plot(x, v, 'r-', label='Phase')
- ax2.set(title='Phase Plot', xlabel='x', ylabel='v'); ax2.legend(); ax2.grid()
- fig.tight_layout(); plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement