# Differentiating under integral sign — trig counterexample

I really hate integration by parts, so when faced with $\int_{-\pi}^\pi x^2 \cos n x \, dx$ I tried writing it as $$\int_{-\pi}^\pi x^2 \cos n x \, dx = \frac{d}{dn} \int_{-\pi}^\pi x \sin n x \, dx = \frac{d^2}{dn^2} \int_{-\pi}^\pi \cos n x \, dx$$1

I have done something wrong. The integrand is continuously differentiable with respect to n and I thought that was enough. How can I get differentiating under the integral sign to work?

-
The last term should have a negative sign, but other than that I don't see what's wrong. This is not a good application of differentiation under the integral sign, though, since generally people only care about integer $n$; I would instead compute $\int_{-\pi}^{\pi} e^{tx} \cos nx \, dx$. – Qiaochu Yuan Jul 20 '11 at 15:53
Your Laplace transform example is complicated. Instead, I should just evaluate the RHS for arbitrary n, even though I just want integer n. This was for my multivariate calculus class, which I am teaching :-/ – cactus314 Jul 20 '11 at 16:09

It did work (except you are missing a negative sign). Remember $n$ is not always an integer, so that $$-\int_{-\pi}^\pi \cos(nx)dx=-\frac{2\sin(\pi n)}{n}.$$

Then $$\frac{d^2}{dn^2} \left(-\int_{-\pi}^\pi \cos(nx)dx\right) =\frac{d}{dn} \left( -\frac{2\pi\cos (\pi n)}{n}+\frac{2\sin(\pi n)}{n^2}\right)$$

$$=\frac{2\pi^2\sin(\pi n)}{n}-\frac{4\sin(\pi n)}{n^3}+\frac{4\pi\cos(\pi n)}{n^2}.$$

-

Well, if there are cases in which you can't avoid integration by parts, then please use the below formula:

• If $u$ and $v$ are functions of $x$ and dashes denote differentiation and suffixes integration with respect to $x$, then $$\small\int uv \ dx = uv_{1} -u'v_{2}+ u''v_{3} - u'''v_{4} + \cdots + (-1)^{n-1}u^{(n-1)}v_{n} + (-1)^{n} \int u^{(n)}\cdot v_{n} \ dx$$
-
What do the $v_n$ stand for in your formula? – Pedro Tamaroff Feb 26 '12 at 17:43
I read you answer. You clarify $v_n$ stands for integration. – Pedro Tamaroff Feb 27 '12 at 18:03

Differentiating under the integral sign is fine here, but for such situations ("a polynomial times a trig function") I prefer to use this method. The basic idea is that you know ahead of time how integration by parts will affect the sign of each consecutive integral, so clever bookkeeping saves you from having to use excessive parentheses and making errors.

-