# Help with integration by parts

$$\int x\cos(x) dx$$

So I just the integration by parts: $\int f(x) . g'(x) dx = f(x)g(x) - \int f'(x) \cdot g(x) dx$

$f(x) = x$ and $g'(x) = \cos(x)$, we get:

$$x \cos(x) dx = x\sin(x) - \int 1 \cdot \sin(x)dx$$

Here is where the problem starts. I am in doubt as to whether which of the following answer (if any) are correct:

$x \cos(x) dx = x\sin(x) - -x\cos(x)dx$ (does $1$ turn into $x$?, and if not, why not?)

or

$x \cos(x) dx = x\sin(x) - - \cos(x)dx$

$x \cos(x) dx = x\sin(x) + \cos(x)dx$

$x\sin(x) = 0$? Which must be totally incorrect. Please help me out.

• Your first equality is incorrect, the $1$ does not turn into a $x$, simply because it is a $1$ who multiplies a $\sin$. Your next two are what you need to do, but your third one is wrong, you seem to have simplified $x\cos(x)-\cos(x)$ to $0$ – Jean-Sébastien Nov 26 '12 at 19:16
• But isn't the integral of 1 x? – Jijbentlekker Nov 26 '12 at 19:17
• See answer underneath – Jean-Sébastien Nov 26 '12 at 19:21
• Oh, nevermind, the 1 would only turn into an $x$ if it was a subtraction or addition, right? – Jijbentlekker Nov 26 '12 at 19:22
• Note that you can typeset $sin$ and $cos$ with $"\"sin$. this gives a better result $sin(x)$ compared to $\sin(x)$ – Jean-Sébastien Nov 26 '12 at 19:27

Your first couple of steps are correct. Why are you hesitating? Just do the last integral so that your answer becomes $$\int x\cos(x)\text{d}x = x\sin(x) + \cos(x) +C .$$ Why do you think this is wrong? You can always take its derivative to check your answer.
Integration by parts is definitely the right idea, here. You must be cautious, though, that you don't drop one of the integrations (which I'll deal with in a moment), and that you don't leave any extra differential terms lying about after you've integrated--as you did when you concluded that $\int\sin x\,dx=-\cos x\,dx$ in your second proposed answer (the $dx$ on the right should not be there).
Now, you've got $$x\cos x\,dx=x\sin x-\int 1\cdot \sin x\,dx,$$ which is very similar looking to what integration by parts should give you, but if you compare this to the general formula, you'll see that you've lost an integration! You should have $$\int x\cos x\,dx=x\sin x-\int 1\cdot \sin x\,dx,$$ or, since $1\cdot\sin x=\sin x$ and you know how to take the indefinite integral of $\sin x$, we get $$\int x\cos x\,dx=x\sin x+\cos x+C.$$ This is similar to the second answer you suggested, but that integration sign on the left-hand side makes a big difference!
You need to be careful not to do $$\int f(x)g(x)dx=\int f(x)dx\int g(x) dx.$$ This equality is wrong in most case. Just take $f=g=1$. This is why the $1$ does not turn into a $x$. Using the formula you provide, you get $$\int x\cos(x)dx=x\sin(x)-\int \sin(x)dx=x\sin(x)- (-\cos(x))=x\sin(x)+\cos(x)$$
$x \sin(x)+\cos(x)$ is the right answer. See here.