Guest User

Untitled

a guest
Oct 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. function f(x)
  2. return [x[2], (1. - x[1]^2) * x[2] - x[1]]
  3. end
  4.  
  5.  
  6. function ode(; x0=[1., 0.], dt=1e-3, t_max=10., dim=2)
  7. ts = 0. : dt : t_max
  8. xs = zeros(dim, size(ts)[1])
  9.  
  10. x = x0
  11. xs[:, 1] = x
  12.  
  13. for i in 2 : size(ts)[1]
  14. dx = f(x) .* dt
  15. x += dx
  16. xs[:, i] = x
  17. end
  18. return (ts, xs)
  19. end
  20.  
  21.  
  22. function main()
  23. t_max = 10.
  24. @time ts, xs = ode(t_max=t_max)
  25. end
  26.  
  27.  
  28. main()
Add Comment
Please, Sign In to add comment