The question is to find the following integral, where $n$, $L$ and $\pi$ are constants :
$$I = \frac{2}{L} \int_{0}^{L} x^2 \sin^2 \left( \frac{n \pi x}{L} \right) dx$$
I gave it a try and my answer is $I = \frac{L^2}{3}$, whereas the correct answer is $I = \left( \frac{1}{3} − \frac{1}{2n^{2}\pi^{2}} \right)L^2$. I've attached a picture of my work, please help me find what I am doing wrong.
The last but one step should be integrated by parts again.
$I = 0 + \frac{L}{n\pi} \int x sin(\frac{2n\pi x}{L})dx$
Put $u = x$ and $dv = sin(\frac{2n\pi x}{L})dx$
$du = dx$ and $v = -\frac{L}{2n\pi} cos(\frac{2n\pi x}{L})$
Integration by parts
$\int udv = uv - \int vdu$
Thus $ I = -\frac{L^2}{2n^2\pi^2} x cos(\frac{2n\pi x}{L}) + \frac{L^2}{n\pi}\int cos(\frac{2n\pi x}{L})dx$
$ I = -\frac{L^2}{2n^2\pi^2} x cos(\frac{2n\pi x}{L}) + \frac{L^3}{2n^2\pi^2} sin(\frac{2n\pi x}{L}) $
Now evaluate with L and 0
You get $I = -\frac{L^3}{2n^2\pi^2} $
Now substitute in the first step you get
Integral $ = \frac{1}{L} \left[ \frac{L^3}{3} - \frac{L^3}{2n^2\pi^2}\right]$
And finally Integral $ = \frac{L^2}{3} - \frac{L^2}{2n^2\pi^2}$