Nugroho's blog.: Lorenz Attractor using Python 2.7 and Vpython Module on Mac OS X Lion

Monday, December 12, 2011

Lorenz Attractor using Python 2.7 and Vpython Module on Mac OS X Lion

From Blogsy Photos
Lorenz attractor's generated by three nonlinear simultaneous equation.

x1=x0+h*a*(y0-x0)
y1=y0+h*(x0*(b-z0)-y0)
z1=z0+h*(x0*y0-c*z0)

 
where

a=10
b=28
c=8./4.

We can play with a,b and c to see the effect.

Here the code to visualize Lorenz attractor on Python. We need VPython module to visualize it.


from visual import *
from operator import mod
jl=1.
h=0.01
a=10
b=28
c=8./4.
x0=0.1
y0=0
z0=0
n=10000.
r=1.
while jl < n:
rate(1000)
rd=mod(n,jl)/1000
sphere(pos=(x0,y0,z0),radius=r, color=(rd,1,rd))
x1=x0+h*a*(y0-x0)
y1=y0+h*(x0*(b-z0)-y0)
z1=z0+h*(x0*y0-c*z0)
jl=jl+1
x0=x1
y0=y1
z0=z1


Since Vpython's not support 64bit platform, we must execute the code using 32-bit python like this

Nugrohos-MacBook-Pro:cellular nugroho$ python2.7-32 lorenz.py

Here the result
From Blogsy Photos

No comments:

323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)