Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #integrates the lorenz equations
- #usage: lorenz.py
- #with no options specified, the defaults makes a nice attractor
- import sys, getopt
- tstop=100
- dt=.02
- a=5.
- b=15.
- c=1.
- (options,arguements)=getopt.getopt(sys.argv[1:],'a:b:c:',["tstop=","dt="])
- for op,ar in options:
- if op=="--tstop": tstop=eval(ar)
- if op=="--dt": dt=eval(ar)
- if op=="-a": a=eval(ar)
- if op=="-b": b=eval(ar)
- if op=="-c": c=eval(ar)
- pfile=open('lorenz.dat','w')
- pfile.write("#Lorenz attractor written by lorenz.py \n")
- pfile.write("#a=%6.2f b=%6.2f c=%6.2f \n" % (a,b,c))
- t=0
- x=1
- y=0
- z=0
- while t<tstop:
- t=t+dt
- dxdt=a*y-a*x
- dydt=b*x-y-z*x
- dzdt=x*y-c*z
- x=x+dxdt*dt
- y=y+dydt*dt
- z=z+dzdt*dt
- pfile.write("%f %f %f %f\n" % (t,x,y,z))
- pfile.close()
- print "file lorenz.dat was written"
Add Comment
Please, Sign In to add comment