This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: try: from numpy import * except: print "ERROR: The Integral class requires the Numpy module." class Integral: ''' Example of an Integral class which uses either Trapazoid or Simpson's 1/3 rule to evaluate an integral. ''' def __init__(self,funct,lower,upper,N): self.lower = lower self.upper = upper self.h = (upper - lower)/float(N-1) self.numpts = int(N) self.x = linspace(self.lower,self.upper,self.numpts) self.y = funct(self.x) def evalTrap(self): self.Isum=0. for i in range(self.numpts-1): self.Isum+=(self.y[i+1]+self.y[i])*self.h/2. return self.Isum def evalSimp13(self): self.Isum=0. for i in range(0,self.numpts-2,2): self.Isum+=(self.y[i]+4*self.y[i+1]+self.y[i+2])*self.h/3 return self.Isum class Work(Integral): pass...
View Full Document
This note was uploaded on 10/05/2010 for the course PHYS phy503 taught by Professor Gladden during the Spring '09 term at Ole Miss.
- Spring '09