Guest User

Untitled

a guest
Nov 14th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using ODE;
  2. function f(t, r)
  3. # Extract the coordinates from the r vector
  4. (x, y, z) = r
  5.  
  6. # The Lorenz equations
  7. dx_dt = sigma*(y - x)
  8. dy_dt = x*(rho - z) - y
  9. dz_dt = x*y - bet*z
  10.  
  11. # Return the derivatives as a vector
  12. [dx_dt; dy_dt; dz_dt]
  13. end;
  14.  
  15. # Define time vector and interval grid
  16. const dt = 0.001
  17. const tf = 100.0
  18. t = 0:dt:tf
  19.  
  20. # Initial position in space
  21. const r0 = [0.1; 0.0; 0.0]
  22.  
  23. # Constants sigma, rho and beta
  24. const sigma = 10.0
  25. const rho = 28.0
  26. const bet = 8.0/3.0;
  27.  
  28. (t, pos) = ode45(f, r0, t)
  29. x = map(v -> v[1], pos)
  30. y = map(v -> v[2], pos)
  31. z = map(v -> v[3], pos);
  32.  
  33. using PyPlot
  34. plot3D(x, y, z);
  35.  
  36. #fig, ax = subplots(1, 3, sharex=true, sharey=true, figsize=(16,8))
  37.  
  38. #ax[1][:plot](x, y)
  39. #ax[1][:set_title]("X-Y cut")
  40.  
  41. #ax[2][:plot](x, z)
  42. #ax[2][:set_title]("X-Z cut")
  43.  
  44. #ax[3][:plot](y, z)
  45. #ax[3][:set_title]("Y-Z cut");
Add Comment
Please, Sign In to add comment