Integration by parts: $\int e^{ax}\cos(bx)\,dx$ I need to evaluate the following function and then check my answer by taking the derivative:
$$\int e^{ax}\cos(bx)\,dx$$
where $a$ is any real number and $b$ is any positive real number.

I know that you set $u=\cos(bx)$  and $dv=e^{ax} dx$,
and the second time you need to integrate again you set $u=\sin(bx)$ and $dv=e^{ax}dx$ again.
It eventually simplifies down to
$$\int e^{ax}\cos(bx)dx = \frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a}\left(\frac{1}{a}e^{ax}\sin(bx) - \frac{b}{a}\int e^{ax}\cos(bx)\,dx\right).$$
Now I know to move the integral on the left side to the right side so that I can just divide by the constant to solve.
Here is my problem:
I know I need to solve the right side to be: 
$$\frac{e^{ax}\left(a\cos(bx) + b\sin(bx)\right)}{a^2+b^2} + C.$$
To divide by the constant, I multiplied everything on the right side by 
$$\frac{a^2}{b^2+1}.$$
but this leads me to get $b^2 + 1$ on the bottom instead of $a^2 + b^2$.
I will show what I am doing in detail:
After setting the initial integral equal to:
$$\frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a}\left(\frac{1}{a}e^{ax}\sin(bx) - \frac{b}{a}\int e^{ax}\cos(bx)\,dx\right) + C$$
I simplify:
$$\int e^{ax}\cos(bx)\,dx = \frac{a^2}{b^2+1}\left(\frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a}\left(\frac{1}{a}e^{ax}\sin(bx)\right)\right) + C$$
If this is already wrong, can someone point be in the right direction?  
If I have not gone wrong yet, I can edit to show the rest of my work. 
 A: Another solution to your original question can be using complex numbers.
$$\begin{align}
I&=\displaystyle\int e^{ax}\cos {bx}dx \\
&=\Re\left(\displaystyle\int e^{ax}(\cos {bx}+i\sin {bx})\right)dx\\
&=\Re\left(\displaystyle\int e^{(a+ib)x}dx\right)\\
&=\Re\left(\dfrac{e^{(a+ib)x}}{a+ib}\right)\\
&=\Re\left(\dfrac{e^{ax}(\cos {bx}+i\sin {bx})}{a+ib}\right)\\
&=\Re\left(\dfrac{e^{ax}}{a^2+b^2}(\cos {bx}++i\sin {bx})(a-ib)\right)+C\\
\therefore I&=\dfrac{e^{ax}}{a^2+b^2}(a\cos {bx}+b\sin {bx})+C
\end{align}$$
A: So you have
$$\int e^{ax}\cos(bx)dx = \frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a}\left(\frac{1}{a}e^{ax}\sin(bx) - \frac{b}{a}\int e^{ax}\cos(bx)\,dx\right).$$
Multiplying out you get
$$\int e^{ax}\cos(bx)\,dx = \frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a^2}e^{ax}\sin(bx) - \frac{b^2}{a^2}\int e^{ax}\cos(bx)\,dx.$$
At this point, you should move that last integral on the right hand side to the left hand side and add in the constant of integration on the right.
Moving the last integral to the left hand side, you get
$$\left(1 + \frac{b^2}{a^2}\right)\int e^{ax}\cos(bx)\,dx = \frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a^2}e^{ax}\sin(bx) + C,$$
and I think this is where you made your mistake.
You tried to clear that $1 + \frac{b^2}{a^2}$ by  multiplying through by $\frac{a^2}{1+b^2}$. But this is incorrect:
$$1 + \frac{b^2}{a^2} = \frac{a^2+b^2}{a^2} \neq \frac{1+b^2}{a^2}$$
so that what you multiplied through did not clear that factor. You need to multiply by $\frac{a^2}{a^2+b^2}$ (or, more horribly, by
$$\frac{1}{1+\frac{b^2}{a^2}}$$
which is too horrible for words) for things to cancel out.
If you do that, from
$$\frac{a^2+b^2}{a^2}\int e^{ax}\cos(bx)\,dx = \frac{1}{a}e^{ax}\cos(bx) + \frac{b}{a^2}e^{ax}\sin(bx) + C,$$
multiplying both sides by $\frac{a^2}{a^2+b^2}$, we get:
$$\int e^{ax}\cos(bx)\,dx = \frac{a}{a^2+b^2}e^{ax}\cos(bx) + \frac{b}{a^2+b^2}e^{ax}\sin(bx) + C$$
the intended answer.
By the way: you don't need to have the "$+C$" on the right hand side until there are no more indefinite integrals there; the constant of integration is implicit in the indefinite integral, so for example, in your penultimate displayed equation, the "$+C$" is superfluous.
