# How to integrate by using imaginary and real part of $e^{ix}$

I want to calculate integrals with $\sin(x)$ and $\cos(x)$ by real and imaginary part of $e^{ix}$.

Assume $e^{ix}=\cos(x)+i\sin(x)$

For example \begin{align*} \int \sin(x)dx &= \int Im(e^{ix})dx = Im\left(\int e^{ix}dx\right)= Im\left(\frac{1}{i}e^{ix}+c\right) = Im\left(-ie^{ix}+c\right) \\ &= Im(-i[\cos(x)+i\sin(x)]+c) = Im(-i[\cos(x)+i\sin(x)]+c) \\ &= Im(-i\cos(x)+\sin(x)+c) = -\cos(x) + c \end{align*}

How to use this method (if it is possible) to calculate $\int \sin^{2}(x) dx$ and $\int x^{2}\sin^{2}(x) dx$ ?

How to handle higher exponent of $\sin(x)$ and $\cos(x)$ in integrals like $\int \sin^{n}(x) dx$, $\int \sin^{n}(x) \cos^{m}(x) dx$ where $n,m\geq 2$ ?

-
I would not recommend working with Re and Im if higher powers (or even quotients) are involved. Use $$\cos x={1\over2}\bigl(e^{ix}+e^{-ix}\bigr)\ ,\quad \sin x={1\over2i}\bigl(e^{ix}-e^{-ix}\bigr)$$ instead. –  Christian Blatter Jan 10 '13 at 9:31

$$e^{2ix}=\cos 2x+i\sin 2x=1-2\sin^2x+i\sin 2x\Longrightarrow$$
$$\int\sin^2x\,dx=\frac{1}{2}\int\left(1-Re(e^{i2x})\right)dx=\frac{1}{2}\left(x-Re\int e^{i2x}dx\right)=$$
$$=\frac{1}{2}\left(x-Re\left(\frac{1}{2i}e^{2ix}\right)\right)+C=\frac{1}{2}\left(x-Re\left(\frac{1}{2i}\left[\cos 2x+i\sin 2x\right]\right)\right)+C=$$
$$=\frac{1}{2}x-\frac{1}{4}\sin 2x+C=\frac{x-\sin x\cos x}{2}+C$$