SHARE
TWEET

Untitled

a guest May 22nd, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. #  x' = y
  6. #  y' = - x - a * y
  7.  
  8. T_s = 0
  9. T_f = 20
  10. h = 0.01
  11. a = 0.5
  12. x_init = 1
  13. y_init = 0
  14.  
  15. t = np.arange(T_s, T_f, h)
  16. x = np.zeros(t.shape)
  17. y = np.zeros(t.shape)
  18. x[0] = y_init
  19. y[0] = x_init
  20.  
  21. for i in range(t.size-1):
  22.     x[i+1] = x[i] + h * y[i]
  23.     y[i+1] = y[i] + h * (-x[i] - a * y[i])
  24.  
  25.  
  26. plt.plot(t, x, t, y, markersize=3)
  27. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top