Understanding the Composite Trapezoidal Rule
The Composite Trapezoidal Rule is a numerical integration technique used to approximate the definite integral of a function when an exact antiderivative is difficult to find or when dealing with discrete data points.
The formula for the composite trapezoidal rule is:
$$\int_{a}^{b} f(x) \, dx \approx \frac{h}{2} \left[ f(x_0) + 2f(x_1) + 2f(x_2) + \dots + 2f(x_{n-1}) + f(x_n) \right]$$
Where:
- $h = \frac{b-a}{n}$ is the step size.
- $x_i = a + i \cdot h$.
Solving the Problem
We need to evaluate $\int_{0}^{\pi} \sin(x) \, dx$ with $n=4$.
1. Determine parameters
- $a = 0$, $b = \pi$
- $n = 4$
- $h = \frac{\pi - 0}{4} = \frac{\pi}{4}$
2. Identify the nodes ($x_i$)
- $x_0 = 0$
- $x_1 = \frac{\pi}{4}$
- $x_2 = \frac{2\pi}{4} = \frac{\pi}{2}$
- $x_3 = \frac{3\pi}{4}$
- $x_4 = \pi$
3. Evaluate $f(x) = \sin(x)$ at each node
- $f(x_0) = \sin(0) = 0$
- $f(x_1) = \sin(\frac{\pi}{4}) = \frac{\sqrt{2}}{2} \approx 0.7071$
- $f(x_2) = \sin(\frac{\pi}{2}) = 1$
- $f(x_3) = \sin(\frac{3\pi}{4}) = \frac{\sqrt{2}}{2} \approx 0.7071$
- $f(x_4) = \sin(\pi) = 0$
4. Apply the formula
$$\text{Integral} \approx \frac{\pi/4}{2} \left[ 0 + 2(0.7071) + 2(1) + 2(0.7071) + 0 \right]$$ $$\approx \frac{\pi}{8} [1.4142 + 2 + 1.4142]$$ $$\approx \frac{\pi}{8} [4.8284] \approx 1.896$$
(Note: The exact value is $\int_0^\pi \sin x dx = [-\cos x]_0^\pi = 2$. The approximation is close given $n=4$.)