integration by parts for $\int e^x\cos(x)\text{d}x$ I was given the following indefinite integral and asked to solve it using the integration by parts method: $$\int e^x\cos(x)\text{d}x$$ I did so but seemed to get two different answers. The first was: $$\frac12e^x(\sin x+\cos x)+C$$ The other was simply: $$e^x\sin x+e^x\cos x +C$$ The difference in solutions seems to come from how I choose the parts - If I put cosine as my f(x), I end up with a negative sine. However, if I avoid negatives, then my answer is different.
Based on the comments, it seems that my second answer is incorrect. I will show the work I put in for that one, maybe someone can help me understand what I did wrong?
$$\int e^x\cos(x)\text{d}x = \cos(x)e^x+\int\sin(x)e^x=\cos(x)e^x+\sin(x)e^x+\int\cos(x)e^x $$  Is this correct? Is there simply a sign error somewhere?
 A: The error is that you forgot a minus sign when performing the second integration by parts.
Let $\text{u}=\cos(x)$ and $\text{dv}=e^xdx$ so that $\text{du}=-\sin(x)dx$ and $\text{v}=e^x$. Therefore
$$\int e^x\cos(x)\text{d}x=\mathrm{uv}-\int \mathrm{vdu}=\cos(x)e^x+\int e^x\sin(x){d}x\tag{1}$$
We then need to evaluate
$$\int e^x\sin(x){d}x$$
Let $\text{u}=\sin(x)$ and $\text{dv}=e^xdx$ so that $\text{du}=\cos(x)dx$ and $\text{v}=e^x$. Then
$$\int e^x\sin(x){d}x=\mathrm{uv}-\int \mathrm{vdu}=\sin(x)e^x-\int e^x\cos(x){d}x\tag{2}$$
Combining $(1)$ and $(2)$
$$\int e^x\cos(x)\text{d}x=\cos(x)e^x+\int e^x\sin(x){d}x=\cos(x)e^x+\sin(x)e^x-\int e^x\cos(x){d}x$$
which reduces to
$$\int e^x\cos(x)\text{d}x=\frac{1}{2}e^x\big(\cos(x)+\sin(x) \big)+C$$
A: I did it just now:
$$
\begin{aligned}
\int e^x \cos (x) \, dx &= e^x \cos(x) +\int e^x \sin (x) \, dx \\
&=e^x \cos(x) + e^x \sin(x) - \int e^x \cos(x) \, dx
\end{aligned}
$$
then
$$
2\int e^x \cos (x) \, dx = e^x \cos(x) + e^x \sin(x)
$$
which implies
$$
\int e^x \cos (x) \, dx = \frac12e^x(\sin x+\cos x)+C
$$
And I don't know in which step you are wrong.
