Guest User

Untitled

a guest
Jul 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #integrates the lorenz equations
  3. #usage: lorenz.py
  4. #with no options specified, the defaults makes a nice attractor
  5. import sys, getopt
  6. tstop=100
  7. dt=.02
  8. a=5.
  9. b=15.
  10. c=1.
  11. (options,arguements)=getopt.getopt(sys.argv[1:],'a:b:c:',["tstop=","dt="])
  12. for op,ar in options:
  13.     if op=="--tstop": tstop=eval(ar)
  14.     if op=="--dt": dt=eval(ar)
  15.     if op=="-a": a=eval(ar)
  16.     if op=="-b": b=eval(ar)
  17.     if op=="-c": c=eval(ar)
  18. pfile=open('lorenz.dat','w')
  19. pfile.write("#Lorenz attractor written by lorenz.py \n")
  20. pfile.write("#a=%6.2f  b=%6.2f   c=%6.2f \n" % (a,b,c))
  21. t=0
  22. x=1
  23. y=0
  24. z=0
  25. while t<tstop:
  26.     t=t+dt
  27.     dxdt=a*y-a*x
  28.     dydt=b*x-y-z*x
  29.     dzdt=x*y-c*z
  30.     x=x+dxdt*dt
  31.     y=y+dydt*dt
  32.     z=z+dzdt*dt
  33.     pfile.write("%f %f %f %f\n" % (t,x,y,z))
  34. pfile.close()
  35. print "file lorenz.dat was written"
Add Comment
Please, Sign In to add comment