Advertisement
Guest User

Numerical Analysis

a guest
Dec 8th, 2010
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. import numpy
  2. from numpy import *
  3.  
  4. import matplotlib
  5. matplotlib.use("TKAgg", False)
  6. import pylab
  7.  
  8. import os, warnings, time, random
  9.  
  10. def F(f,x):
  11.     x=numpy.array(x)
  12.     return eval(f)
  13.  
  14. def isZero(x,lim=1E-16):
  15.     return x is None or abs(x)<=lim
  16.  
  17. __scrub_nums = '0123456789'
  18. def scrub(f):
  19.     nf=''
  20.     for i in range(len(f)):
  21.         nf += f[i]
  22.         if f[i] in __scrub_nums:
  23.             if i+1 < len(f) and f[i+1] != '.' and f[i+1] not in __scrub_nums:
  24.                     nf += '.0'
  25.             elif i+1 == len(f):
  26.                 nf +='.0'
  27.        
  28.     return nf      
  29.  
  30. def JDraw(pause = .001):
  31.     """Any pause < .001 = .001"""
  32.     pylab.draw()
  33.     warnings.simplefilter("ignore")
  34.     pylab.gcf().canvas.start_event_loop(timeout = pause)
  35.     warnings.simplefilter("always")
  36.    
  37. def rebound(x,f,p=10):
  38.     xr=max(x)-min(x)
  39.     fr=max(f)-min(f)
  40.     dx=xr/100.*p
  41.     df=fr/100.*p
  42.     xmin=min(x)-.5*dx
  43.     xmax=max(x)+.5*dx
  44.     fmin=min(f)-.5*df
  45.     fmax=max(f)+.5*df
  46.     return (xmin,xmax,fmin,fmax)
  47.  
  48. def qjplot(x,f,*args,**kwargs):
  49.     pylab.ion()
  50.     do_rebound = kwargs.pop('rebound',0)    
  51.     pylab.plot(x,f,*args,**kwargs)
  52.     if do_rebound:
  53.         (xmin,xmax,fmin,fmax)=rebound(x,f)
  54.         pylab.xlim(xmin,xmax)
  55.         pylab.ylim(fmin,fmax)
  56.    
  57. def qjclf():
  58.     pylab.clf()
  59.  
  60. def qjwait():
  61.     raw_input("Press enter to continue: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement