from visual import * #modifications GF 13sep11 scene.title = "Lorenz differential equation" scene.center = vector(25,0,0) traj = curve( color = color.black, radius=0.3 ) #read the "vpy-curve" discussion of this object # The grid is nice, but needed only later # Draw grid #for x in arange(0,51,10): # box(pos=(x,0,0), axis=(0,0,50), height=0.4, width=0.4, color=(0.6,0.6,0.6) ) #for z in arange(-25,26,10): # box(pos=(25,0,z), axis=(50,0,0), height=0.4, width=0., color=(0.6,0.6,0.6) ) h = 0.01 #step size, using "dt" is kinda engineering pp = vector(35, -10, -7) #the original "y" is bad notation #traditional constants beta = 8.0/3 #has no famous name sigma = 10 #the Prandtl number rho = 28 #the Rayleigh number for t in arange(0,10,h): x = pp[0]; y = pp[1]; z=pp[2]; xdot = y*z - beta*x ydot = sigma*(z-y) zdot = y*(rho-x) - z pdot = vector(xdot, ydot, zdot) pp = pp + pdot*h # Draw lines colored by speed c = clip( [mag(pdot) * 0.005], 0, 1 )[0] traj.append( pos=pp, color=(c,0, 1-c) ) rate( 500 )