Exercise: trapezoid and Simpson on a smooth integral

Approximation of the integral of sin(x)ex\sin(x)e^{-x} from 0 to π/2\pi/2 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.

  1. The exact reference value is:

    I=1eπ/22=0.396060211824619I=\frac{1-e^{-\pi/2}}{2}=0.396060211824619
  2. Composite trapezoid gives these approximations:

    T4=0.380590604382816,T8=0.392182862002726T_4=0.380590604382816,\qquad T_8=0.392182862002726
  3. Composite Simpson gives:

    S4=0.395839444235324,S8=0.396046947876029S_4=0.395839444235324,\qquad S_8=0.396046947876029
  4. The absolute errors are:

    E=(0.015469607441803, 0.003877349821893, 0.000220767589295, 0.000013263948590)|E|=(0.015469607441803,\ 0.003877349821893,\ 0.000220767589295,\ 0.000013263948590)

Reducing h improves each method; for the same n, Simpson is much more accurate because its error is of order h^4.