Solving this rather tedious integral I need help solving this integral
$$\left \langle x \right \rangle = \frac{2}{a}\int_{0}^{a}x\sin^{2}\left ( \frac{m \pi x}{a} \right )\,dx$$.
I have tried to reduce $$\sin^{2}\left ( \frac{m \pi x}{a} \right )\,dx$$
down to $$\frac{1-\cos\left ( \frac{2n \pi x}{a} \right )}{2}$$
Note that $n$ is an integrer.
But it gets more complicated. Spent a good hour or so trying.
The solution should be $$\frac{a}{2}$$ but I have no means of arriving at. I would appreciate any help.
 A: HINT:
$$\frac{2}{a}\int_{0}^{a}x\sin^{2}\left(\frac{\pi mx}{a}\right)\space\text{d}x=$$
$$a\int_{0}^{a}x\left(1-\cos\left(\frac{2\pi mx}{a}\right)\right)\space\text{d}x=$$
$$a\int_{0}^{a}\left(x-x\cos\left(\frac{2\pi mx}{a}\right)\right)\space\text{d}x=$$
$$a\left(\int_{0}^{a}x\space\text{d}x-\int_{0}^{a}x\cos\left(\frac{2\pi mx}{a}\right)\space\text{d}x\right)=$$
$$a\left(\frac{1}{2}\left[x^2\right]_{x=0}^{a}-\int_{0}^{a}x\cos\left(\frac{2\pi mx}{a}\right)\space\text{d}x\right)=$$
$$a\left(\frac{a^2}{2}-\int_{0}^{a}x\cos\left(\frac{2\pi mx}{a}\right)\space\text{d}x\right)=$$

Integrate by parts, $\int f\space\text{d}g=fg-\int \space\text{d}f$
Where $f=x$, $\text{d}g=\cos\left(\frac{2\pi mx}{a}\right)\space\text{d}x$, $\text{d}f=\text{d}x$ and $g=\frac{a\sin\left(\frac{2\pi mx}{a}\right)}{2\pi m}$:

$$a\left(\frac{a^2}{2}-\left[\frac{a\sin\left(\frac{2\pi mx}{a}\right)}{2\pi m}\right]_{x=0}^{a}-\frac{a}{2\pi m}\int_{0}^{a}\sin\left(\frac{2\pi mx}{a}\right)\space\text{d}x\right)$$
A: It is useful to set $x=az$ for first. That, together with the cosine duplication formula, leads to:
$$ I = 2a\int_{0}^{1}z \sin^2(m\pi z)\,dz =a\int_{0}^{1}z\left(1-\cos(2m\pi z)\right)\,dz,\tag{1}$$
then applying integration by parts:
$$ I = \frac{a}{2}-\int_{0}^{1}az\cos(2m\pi z)\,dz = \frac{a}{2}-\left.\frac{az}{2m\pi}\sin(2m\pi z)\right|_{0}^{1}+\frac{a}{2m\pi}\int_{0}^{1}\sin(2m\pi z)\,dz\tag{2}$$
but due to the periodicity of the sine function the last two terms equal zero, hence, simply:
$$ I = \color{red}{\frac{a}{2}}.\tag{3}$$
