[Edu-sig] RE: Integration correction
henrik at nada.kth.se
Tue Mar 29 20:18:13 CEST 2005
Kirby got the trapezoidal integration rule wrong.
This is the corrected version.
sum = 0
h = (b-a)/float(n)
for i in range(1,n):
sum += f(a+i*h)
The interval must be divided into n equal parts, so
an arbitrary h will not do. With this version, the
error in Kirby's integration of x^2 from 0 to 3 will
decrease by a factor of 100000.
But you never use the trapezoidal rule in real life!
Simpson gives much smaller error for the same amount
of computation. In fact, it is exact for Kirby's example!
More information about the Edu-sig