Professional Documents
Culture Documents
Comp Simpson Rule For Integration (Python)
Comp Simpson Rule For Integration (Python)
defsimpson(f,a,b,n):
"""Approximatesthedefiniteintegralofffroma
tobby
thecompositeSimpson'srule,usingn
subintervals"""
h=(ba)/n
s=f(a)+f(b)
foriinrange(1,n,2):
s+=4*f(a+i*h)
foriinrange(2,n1,2):
s+=2*f(a+i*h)
returns*h/3
printsimpson(lambdax:x**9,0.0,10.0,100000)