Simpson's Rule - Sample Implementation

Sample Implementation

An implementation of the composite Simpson's rule in Python:

def simpson(f, a, b, n): """f=function, a=initial value, b=end value, n=number of intervals of size h, n must be even""" h = float(b - a) / n S = f(a) for i in range(1, n, 2): x = a + h * i S += 4 * f(x) for i in range(2, n-1, 2): x = a + h * i S += 2 * f(x) S += f(b) F = h * S / 3 return F

Read more about this topic:  Simpson's Rule

Famous quotes containing the word sample:

    The present war having so long cut off all communication with Great-Britain, we are not able to make a fair estimate of the state of science in that country. The spirit in which she wages war is the only sample before our eyes, and that does not seem the legitimate offspring either of science or of civilization.
    Thomas Jefferson (1743–1826)