×

Welcome to TagMyCode

Please login or create account to add a snippet.
3
0
 
1
Language: Ruby
Posted by: petecocoon
Added: Feb 18, 2011 3:38 PM
Modified: Feb 24, 2011 8:06 AM
Views: 346
This snippet print on stdout the first 10000 iterations of Lorenz attractor
  1. #Calcolo valori per l'attrattore di Lorenz
  2. #dx / dt = p (y - x)
  3. #dy / dt = x (r - z) - y
  4. #dz / dt = xy - c z
  5. #P = 10, R = 28, c = 8 / 3.
  6. #P = 28, R = 46.92, c = 4.
  7.  
  8. MAX_ITERATION = 10000
  9. h = 0.01;
  10. P = 10.0; #numero di Prandtl
  11. R = 28.0; #numero di Rayleigh
  12. c = 8.0 / 3.0;
  13. x, y, z = 0.1, 0, 0
  14.  
  15. 0.upto(MAX_ITERATION) do |i|
  16. next_x = x + h * P * (y - x);
  17. next_y = y + h * (x * (R - z) - y);
  18. next_z = z + h * (x * y - c * z);
  19. x, y, z = next_x, next_y, next_z;
  20. puts "#{i} - X: #{x} , Y: #{y}, Z: #{z}"
  21. end