Exercise: trapezoid and Simpson on a smooth integral
Approximation of the integral of from 0 to with 4 and 8 subintervals, comparing errors.
Computation and comparison
ExampleIntegral of sin(x)e^{-x}
Compute I=∫_0^{π/2} sin(x)e^{-x} dx with composite trapezoid and Simpson using n=4 and n=8. The exact value is (1-e^{-π/2})/2.
The exact reference value is:
Composite trapezoid gives these approximations:
Composite Simpson gives:
The absolute errors are:
Reducing h improves each method; for the same n, Simpson is much more accurate because its error is of order h^4.