I stack about Error Bounds of Trapezoidal Rule. The question says

How large should $n$ be to guarantee the Trapezoidal Rule approximation for $\int_{0}^{\pi}x\cos x\,dx$ be accurate to within 0.0001 ?

I used $|E_{T}| <= \frac{K(b-a)^3}{12n^2}$ On the process of this formula, I did take 3rd derivative of given function which was $x\cos x$ to find out max of 2nd derivative. However, I got some strange number. So I just stack there. Is there easy way to find the $K$ ?

If you have any idea, Please post on the wall Thank you !


The $K$ in your formula is the largest possible absolute value of the second derivative of your function. So let $f(x)=x\cos x$. We calculate the second derivative of $f(x)$.

We have $f'(x)=-x\sin x+\cos x$. Differentiate again. We get $$f''(x)=-x\cos x-\sin x-\sin x=-(2\sin x+x\cos x).$$

Now in principle, to find the best value of $K$, we should find the maximum of the absolute value of the second derivative. But we won't do that, it is too much trouble, and not really worth it.

So how big can the absolute value of the second derivative be? Let's be very pessimistic. The number $x$ could be as large as $\pi$. The absolute value of $\cos x$ and $\sin x$ is never bigger than $1$, so for sure the absolute value of the second derivative is $\le 2+\pi$. Thus, if we use $K=2+\pi$, we can be sure that we are taking a pessimistically large value for $K$.

Note that at $\pi$, the cosine is $-1$ and the sine is $0$, so the absolute value of the second derivative can be as large as $\pi$.

We can be less pessimistic. In the interval from $0$ to $\pi/2$, our second derivative is less than $2+\pi/2$. We can do better than that by looking at the second derivative in more detail, say between $0$ and $\pi/4$, and between $\pi/4$ and $\pi/2$.

In the interval from $\pi/2$ to $\pi$, the cosine is negative, while the sine is positive. The sine is definitely $\le 2$. The $x\cos x$ term is negative, so in the interval $[\pi/2,\pi]$, the absolute value of the derivative is less than or equal to the larger of $2$ and $\pi$, which is $\pi$.

So we have reduced our upper bound on the absolute value of the second derivative to $2+\pi/2$, say about $3.6$. We could do a bit better by graphing the second derivative on a graphing calculator, and eyeballing the largest absolute value.

It's not worth it. Use $K\le 3.6$ (or even $2+\pi$). Then we know that the error has absolute value which is less than or equal to $$\frac{3.6\pi^3}{12n^2}.$$ We want to make sure that the above quantity is $\le 0.0001$. Equivalently, we want $$n^2\ge \frac{3.6\pi^3}{(12)(0.0001}.$$ Finally, calculate. I get something like $n=305$.

Remark: There are many reasons not to work too hard to find the largest possible absolute value of the second derivative. If we are using numerical integration on $f$, it is probably because $f$ is at least a little unpleasant. Usually then, $f''$ will be more unpleasant still, and finding the maximum of its absolute value could be very difficult.

In addition, using the maximum of $|f''(x)|$ usually gives a needlessly pessimistic error estimate. I am certain that for the Trapezoidal Rule with your function, in reality we only need an $n$ much smaller than $305$ to get error $\le 0.0001$. The error estimate for the Trapezoidal Rule is close to the truth only for some really weird functions. For "nice" functions, the error bound you were given is unduly pessimistic.

The usual procedure is to calculate say $T_2$, $T_4$, $T_8$, and so on until successive answers change by less than one's error tolerance. This is theoretically not good enough, but works well in practice, particularly if you cross your fingers.


Hint: You don't say what K is, nor n. The absolute value of the first derivative of $x \cos (x)$ is limited by $|x \sin(x)|+|\cos(x)|=|x \sin (x)|+1$

  • $\begingroup$ Thank you for posting the hint !! but I still can't see the next step and why |$cos(x)$| became 1... Would you mind if you explain more ? $\endgroup$
    – Ryu
    Feb 28 '12 at 5:47
  • $\begingroup$ @Ryu: André Nicolas has done a very good job, so I will refer you to his answer. $\endgroup$ Feb 28 '12 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.