Skip to content

Worked Examples

We compare all four methods on the same problem: integrating f(x)=exf(x) = e^x over [0,2][0, 2]. The exact value is known analytically, so we can compute a precise relative error for each approximation and observe how accuracy improves as we use more nodes or a higher-degree rule.


Setup

Problem: Approximate ∫02ex dx\displaystyle\int_0^2 e^x\,dx using (i) the basic Trapezoidal Rule, (ii) the Composite Trapezoidal Rule with m=2m = 2, (iii) the Composite Trapezoidal Rule with m=3m = 3, and (iv) Simpson’s Rule. Compute the relative error for each.

The exact value is:

∫02ex dx=[ex]02=e2−e0=e2−1≈6.389\int_0^2 e^x\,dx = \left[e^x\right]_0^2 = e^2 - e^0 = e^2 - 1 \approx 6.389

The relative error is defined as:

Relative Error=∣Exact−ApproximateExact∣×100%\text{Relative Error} = \left|\frac{\text{Exact} - \text{Approximate}}{\text{Exact}}\right| \times 100\%


(i) Basic Trapezoidal Rule

Step 1 — Identify parameters

a=0,b=2,f(x)=exa = 0, \quad b = 2, \quad f(x) = e^x

Step 2 — Evaluate ff at both endpoints

f(0)=e0=1,f(2)=e2≈7.389f(0) = e^0 = 1, \qquad f(2) = e^2 \approx 7.389

Step 3 — Apply the Trapezoidal Rule

I1=b−a2[f(a)+f(b)]=2−02[f(0)+f(2)]=1⋅[1+7.389]=8.389I_1 = \frac{b - a}{2}\left[f(a) + f(b)\right] = \frac{2 - 0}{2}\left[f(0) + f(2)\right] = 1 \cdot \left[1 + 7.389\right] = \boxed{8.389}

Step 4 — Compute the relative error

Relative Error=∣6.389−8.3896.389∣×100%≈31.30%\text{Relative Error} = \left|\frac{6.389 - 8.389}{6.389}\right| \times 100\% \approx 31.30\%


(ii) Composite Trapezoidal Rule (m=2m = 2)

Step 1 — Compute the step size and nodes

h=b−am=2−02=1h = \frac{b - a}{m} = \frac{2 - 0}{2} = 1

x0=0,x1=0+1=1,x2=1+1=2x_0 = 0, \qquad x_1 = 0 + 1 = 1, \qquad x_2 = 1 + 1 = 2

Step 2 — Evaluate ff at all nodes

f(x0)=f(0)=1,f(x1)=f(1)=e≈2.718,f(x2)=f(2)=e2≈7.389f(x_0) = f(0) = 1, \qquad f(x_1) = f(1) = e \approx 2.718, \qquad f(x_2) = f(2) = e^2 \approx 7.389

Step 3 — Apply the Composite Trapezoidal formula

C1,2=h2[f(x0)+2f(x1)+f(x2)]=12[1+2(2.718)+7.389]C_{1,2} = \frac{h}{2}\left[f(x_0) + 2f(x_1) + f(x_2)\right] = \frac{1}{2}\left[1 + 2(2.718) + 7.389\right]

=12[1+5.436+7.389]=12(13.825)=6.913= \frac{1}{2}\left[1 + 5.436 + 7.389\right] = \frac{1}{2}(13.825) = \boxed{6.913}

Step 4 — Compute the relative error

Relative Error=∣6.389−6.9136.389∣×100%≈8.20%\text{Relative Error} = \left|\frac{6.389 - 6.913}{6.389}\right| \times 100\% \approx 8.20\%


(iii) Composite Trapezoidal Rule (m=3m = 3)

Step 1 — Compute the step size and nodes

h=2−03=23h = \frac{2 - 0}{3} = \frac{2}{3}

x0=0,x1=23,x2=43,x3=2x_0 = 0, \qquad x_1 = \frac{2}{3}, \qquad x_2 = \frac{4}{3}, \qquad x_3 = 2

Step 2 — Evaluate ff at all nodes

f(x0)=e0=1,f(x1)=e2/3≈1.948f(x_0) = e^0 = 1, \qquad f(x_1) = e^{2/3} \approx 1.948

f(x2)=e4/3≈3.794,f(x3)=e2≈7.389f(x_2) = e^{4/3} \approx 3.794, \qquad f(x_3) = e^2 \approx 7.389

Step 3 — Apply the Composite Trapezoidal formula

C1,3=h2[f(x0)+2f(x1)+2f(x2)+f(x3)]C_{1,3} = \frac{h}{2}\left[f(x_0) + 2f(x_1) + 2f(x_2) + f(x_3)\right]

=2/32[1+2(1.948)+2(3.794)+7.389]= \frac{2/3}{2}\left[1 + 2(1.948) + 2(3.794) + 7.389\right]

=13[1+3.896+7.588+7.389]=13(19.873)=6.624= \frac{1}{3}\left[1 + 3.896 + 7.588 + 7.389\right] = \frac{1}{3}(19.873) = \boxed{6.624}

Step 4 — Compute the relative error

Relative Error=∣6.389−6.6246.389∣×100%≈3.68%\text{Relative Error} = \left|\frac{6.389 - 6.624}{6.389}\right| \times 100\% \approx 3.68\%


(iv) Simpson’s Rule

Step 1 — Identify parameters

a=0,b=2,a+b2=1a = 0, \qquad b = 2, \qquad \frac{a+b}{2} = 1

Step 2 — Evaluate ff at all three nodes

f(0)=1,f(1)=e≈2.718,f(2)=e2≈7.389f(0) = 1, \qquad f(1) = e \approx 2.718, \qquad f(2) = e^2 \approx 7.389

Step 3 — Apply Simpson’s Rule

I2=b−a6[f(a)+4f ⁣(a+b2)+f(b)]I_2 = \frac{b - a}{6}\left[f(a) + 4f\!\left(\frac{a+b}{2}\right) + f(b)\right]

=2−06[f(0)+4f(1)+f(2)]=13[1+4(2.718)+7.389]= \frac{2 - 0}{6}\left[f(0) + 4f(1) + f(2)\right] = \frac{1}{3}\left[1 + 4(2.718) + 7.389\right]

=13[1+10.873+7.389]=13(19.262)=6.421= \frac{1}{3}\left[1 + 10.873 + 7.389\right] = \frac{1}{3}(19.262) = \boxed{6.421}

Step 4 — Compute the relative error

Relative Error=∣6.389−6.4216.389∣×100%≈0.50%\text{Relative Error} = \left|\frac{6.389 - 6.421}{6.389}\right| \times 100\% \approx 0.50\%


Comparison

MethodNodesApproximate ValueRelative Error
Exact—6.3896.3890.00%0.00\%
Trapezoidal I1I_128.3898.38931.30%31.30\%
Composite C1,2C_{1,2} (m=2m=2)36.9136.9138.20%8.20\%
Composite C1,3C_{1,3} (m=3m=3)46.6246.6243.68%3.68\%
Simpson’s I2I_236.4216.4210.50%0.50\%