[Math] Minimum number of subintervals n for the Composite Trapezoidal Rule

integrationnumerical methods

I am trying to compute the minimum number of subintervals n for the Composite Trapezoidal Rule, in order for the approximation of the following integral to have 5 decimals correct. $$\int_0^2 \frac{1}{x+4}dx$$
So I am using:
$$|E_n^T(f)|\leq\frac{(b-a)h^2}{12}M_2<ε$$
where $\mathbf{M_2}=\max_{x\in [a,b]} |f''(x)|=\frac{1}{32}$, $\mathbf{h}=\frac{b-a}{n}$, $\mathbf{ε}=\frac{1}{2}\cdot10^{-5}$. Solving for $n$ I get $n>64.5497…$, so I say that the minimum number of subintervals to achieve 5 decimals is 65. However, using matlab (or an online tool) I see that the Trapezoidal Rule needs only $n=48$ subintervals to achieve this accuracy. What am I doing wrong? Is something wrong with my calculations or is it possible that the number of subintervals needed in practice can actually be less than 65?

Best Answer

If you look at the formula $\frac2{(x+4)^3}$ for the second derivative, you can see that at $x=2$ it will have a somewhat smaller value than at $x=0$. From this lower bound of the derivative you can compute a lower bound for $n$, the truly minimal $n$ will be somewhere in-between.

You could also use the more exact error formula $$ \int_a^b f(x)dx=T(h)-\frac{h^2}{12}(f'(b)-f'(a))+\frac{h^4(b-a)}{720}f^{(4)}(\eta) $$ to get from the term of second degree in $h$ the estimate $$ n^2\approx\frac{(b-a)^2}{12}\frac{6^2-4^2}{6^2\cdot 4^2}\cdot 2\cdot10^5=\frac{10^6}{12\cdot 36} \implies n\approx 48.1125, $$ giving $n=49$ as the best number of segments. The fourth-order correction should not change this value.