daily pastebin goal
59%
SHARE
TWEET

Untitled

dimabest92 Dec 16th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. def euler(h, yz, y0, t0, dt, steps):
  5.     ys = np.empty(int(steps/dt))
  6.     ts = np.empty(int(steps/dt))
  7.     ys[0] = y0
  8.     ts[0] = t0
  9.     u1 = yz + 1
  10.     u2 = yz - 1
  11.     u = u1
  12.  
  13.     for i in range(2, steps):
  14.         ts[i] = ts[i - 1] + dt
  15.         if (yz - (h / 2) - ys[i - 1]) > 1:
  16.             u = u1
  17.  
  18.         if (yz - (h / 2) - ys[i - 1]) < 0:
  19.             u = u2
  20.  
  21.         ys[i] = ys[i - 1] + dt * (3 * u - 3 * ys[i - 1])
  22.  
  23.     y = ys
  24.     t = ts
  25.  
  26.     return y, t
  27.  
  28.  
  29. y, t = euler(1, 20, 0, 0, 0.1, 50)
  30.  
  31. plt.plot(t, y)
  32. 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