Use the Trapezoidal Rule in order to approximate $\displaystyle \int_0^1 \frac{\sin(x)}{x}~ dx$, with error bounded by $10^{-4}$.
I've tried to bound $|f''(x)|$ at $[0,1$]...I want to prove it's monotonic at $[0,1]$ but I don't know how I can prove it easily...
Thanks
The Trapezoidal Rule is given by:
$$\int_a^b f(x) ~ dx = \dfrac{b-a}{2n}(f(x_0) + 2f(x_1) + \ldots + 2f(x_{n-1}) + f(x_n))$$
The error term is given by:
$$|e_n| \le \dfrac{max_{a,b} |f''(x)|}{12 n^2} (b-a)^3$$
We have:
$$f(x) = \dfrac{\sin(x)}{x}, x \in (0,1)$$
We find the second derivative:
$$f''(x) = \frac{2 \sin (x)}{x^3}-\frac{2 \cos (x)}{x^2}-\frac{\sin (x)}{x}$$
A plot of $f(x), f'(x), f''(x)$ shows:
We need to find the maximum of $f''(x), x \in (0,1)$, which yields $|-0.34375|$ at $x = 0$.
To find the number of iterations, we find $n$ from the error bound, thus:
$$|e_n| \le \dfrac{max_{a,b} |~f''(x)|~}{12 n^2} (b-a)^3 = \dfrac{|-0.34375|}{12 n^2} (1-0)^3\le 10^{-4} \implies n \ge 16.9251 $$
So, we choose $n = 17$.
Doing $17-$steps of the Trapezoidal Rule yields:
$$\int_0^1 \dfrac{\sin(x)}{x} ~dx \approx 0.9459962252$$
Using WA, we get the value as:
$$ \int_0^1 \dfrac{\sin(x)}{x} ~dx \approx 0.9460830704$$
So, our error estimate produces:
$$ \Delta =0.9460830704 - 0.9459962252 = 0.000086845$$
This satisfies our requirement of less than $10^{-4}$ error.
Aside: Sometimes using the second derivative as an error bound can have issues, see Deriving the Trapezoidal Rule Error. Sometimes it is better to just take a much more pessimistic value for the max when using second derivative estimates, for example, $1$ in this problem and just avoid the second derivative altogether.