Last active
August 29, 2015 13:56
-
-
Save jesuscast/9295885 to your computer and use it in GitHub Desktop.
Calculates simpson's sum, receives the interval and the the number of intervals. An extra y function needs to be created separetely. Uses numpy. This function takes the results of the y function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import * | |
def simpsonSum(xRange,n): | |
tot = 0 | |
width = 0 | |
width = (xRange[1]-xRange[0])/n | |
x = [ interval for interval in arange(xRange[0],xRange[1]+width, width) ] | |
yRange = [ y(n) for n in x ] | |
tot += yRange[0]+yRange[n] | |
tot += sum([ 2*yRange[i] if (i%2==0) else 4*yRange[i] for i in range(1,n) ]) | |
tot = tot*width/3 | |
return tot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment