> Kirby got the trapezoidal integration rule wrong.

Right, I was just doing a simple average, not any trapezoid.  My rectangles
took the mean between f(x-h) and f(x+h), nothing more.  Not the best
approximation, I agree, but simple to think about, and some text books show
it.

> This is the corrected version.
> 
> def integrate(f,a,b,n=1000):
>     sum = 0
>     h = (b-a)/float(n)
>     for i in range(1,n):
>            sum += f(a+i*h)
>     return h*(0.5*f(a)+sum+0.5*f(b))
> 

So now we should come up with the @integral decorator to wrap any function
in its integral.  How would that look? 

Kirby


_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to