Trapezoidal Rule Accuracy
For this formula $f(x)=2 \cos \left(\frac{\pi}{4} x\right)+2$
How come if we use the trapezoidal rule for 2 separate parts,
i.e. the area of $y=f(x)$ for the interval $[0,2]$ and adding it to the area of $y=f(x)$ for the interval $[2,4]$,
why does this not give the same value as finding the area of $y=f(x)$ for the interval $[0,4]$?
Furthermore, why does taking the area between the interval $[0,4]$ give the exact same answer to $\int_{0}^{4} f(x) d x$?
$\endgroup$ 61 Answer
$\begingroup$For your final question, the reason the trapezoidal rule gives the exact area under this curve is that this particular curve is symmetric about its midpoint $(2,2)$. So the shortfall from the true curve on the left side is exactly matched by the excess above the true curve on the right. If the interval chosen had not been one for which the curve was symmetric (say [0,3] or [0,5]), the trapezoidal rule would not give the exact value.
Now The area of the 4 trapeziums are $$\begin{array}{c|c}\text{Interval}&\text{Area}\\\hline [0,1]&3 + \frac {\sqrt2}2\\ [1,2]&2+\frac{\sqrt 2}2\\ [2,3] & 2 - \frac{\sqrt 2}2\\ [3,4]&1 - \frac{\sqrt2}2\end{array}$$while the curve itself has areas $$\begin{array}{c|c}\text{Interval}&\text{Area}\\\hline [0,1]&2 + \frac {4\sqrt2}\pi \\ [1,2]&2 + \frac {8-4\sqrt2}\pi \\ [2,3] & 2 - \frac {8-4\sqrt2}\pi\\ [3,4]&2 - \frac {4\sqrt2}\pi \end{array}$$
This gives an absolute error on $[0,2]$ of $(5 + \sqrt2) -\left(4 + \frac 8\pi\right) \approx -0.1323$ and on $[2,4]$ of $(3 - \sqrt 2) - \left(4 - \frac 8\pi\right) \approx = 0.1323$. If you add those, you get an absolute error on $[0,4]$ of $0$, just as expected.
But you were calculating relative error, which on $[0,2]$ is $$\frac{(5 + \sqrt2) -\left(4 + \dfrac 8\pi\right)}{4 + \dfrac 8\pi} \approx -2.0204\%$$ and on $[2,4]$ is $$\frac{(3 - \sqrt2) -\left(4 - \dfrac 8\pi\right)}{4 - \dfrac 8\pi} \approx 9.0997\%$$which indeed do not add up to $0$. Why not? Because they are relative errors, but the operation here ia addition!
Remember:
- The absolute error of a sum is the sum of the absolute errors.
- The relative error of a product is approximately the sum of the relative errors.