Written by Colin+ in ask uncle colin, integration.

Dear Uncle Colin,

How would you integrate $e^x \sin(x)$ (with respect to $x$, obviously)?

– Difficult Integral, Just Kan’t See The Right Answer

Hi, DIJKSTRA, and thanks for your message! As seems to be the way recently, there are several ways to approach this.

One of the best bits about further maths for me were things like proof by induction, reduction formulas, and setting a value on an integral to help you solve it. They all feel like cheating, somehow, and I get a small frisson of excitement every time I get to use them.

Here, we can let $I = \int e^x \sin(x) \dx$ and proceed by parts (it really doesn’t matter which part we pick to differentiate.) Let’s let $u = e^x$ and $\diff vx = \sin(x)$, making $\diff ux = e^x$ and $v = -\cos(x)$.

This gives us $I = -\cos(x)e^x + \int e^x \cos(x) \dx$

Repeating the trick, with $U = e^x$ and $\diff Vx = \cos(x)$, gives us $\diff Ux = e^x$ and $V = \sin(x)$. This means:

$I = -\cos(x) e^x + \sin(x) e^x – \int e^x \sin(x)\dx$.

However, that last term is just $I$! With a bit of rearrangement and tidying up:

$2I = e^x \br{\sin(x) – \cos(x)}$, so $I = \frac{1}{2} e^x \br{\sin(x) – \cos(x)}$. Plus a constant.

I don’t have a good translation for *Ansatz*, a word introduced to me by a German lecturer in my final year; the best I have is ‘template’: you make a guess about what the answer ought to look like and work backwards from there. It’s very much a Mathematical Pirate trick, but it does drop out nicely.

Here, we might assume an answer of the form $e^x \br{a \sin(x) + b\cos(x)}$. The derivative of this (which ought to match the thing we’re trying to integrate) is $e^x \br{(a-b)\sin(x) + (a+b)\cos(x) }$.

Matching coefficients with the integrand gives $a-b=1$ and $a+b=0$, so $a=\frac{1}{2}$ and $b=-\frac{1}{2}$ – which leads to the same answer as before.

A third option is to use the representation $\sin(x) = \frac{e^{ix}-e^{-ix}}{2i}$ to make the integral $\frac{1}{2i} \br{e^{(1+i)x}-e^{(1-i)x}}$.

This integrates to $\frac{1}{2i} \br { \frac{1}{1+i}e^{(1+i)x} – \frac{1}{1-i}e^{(1-i)x}}$, which is a bit of a mess.

Let’s note that $\frac{1}{1+i} = \frac{1-i}{2}$ if you realise the denominator; similarly, $\frac{1}{1-i} = \frac{1+i}{2}$. There’s also a factor of $e^x$ all the way through, so I’ll bring that out. This leaves us with:

$\frac{e^x}{4i} \br { (1-i)e^{ix} – (1+i)e^{-ix}}$

We could try to pattern-match $\sin(x)$ and $\cos(x)$ back onto that, but it’s probably simpler to say $e^{\pm ix} = \cos(x) \pm i\sin(x)$.

We’ve then got $\frac{e^x}{4i} \br{ (1-i)(\cos(x)+i\sin(x))- (1+i)(\cos(x)-i\sin(x))}$.

Multiplying out: $\frac{e^x}{4i} \br{ (\cos(x)+\sin(x)-\cos(x)-\sin(x)) + i(\sin(x)-\cos(x)+\sin(x)-\cos(x))}$. There’s a lot of cancelling available there – the “real” part of the bracket vanishes, and the $i$ alongside the complex part and the $i$ on the bottom of the fraction simplify out. This gives us: $\frac{e^x}{4} \br{2\sin(x)+2\cos(x)}$, which simplifies down as before.

Plus a constant.

There are probably several other ways to approach it – I’d love to hear of them – but I hope that helps.

– Uncle Colin