# Trouble integrating square of a sine

I have the following expression which I am trying to evaluate:

$$\frac{2}{L} \int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2 kx$$ where $$k = \frac{\pi}{L}$$.

According to my calculator, the answer should be $$\frac{1}{6}$$ but I can't seem to get this result by manual integration.

Here's what I've tried so far:

\begin{align} &\frac{2}{L} \int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2 kx dx \\ &= \frac{1}{L} \int^{\frac{L}{3}}_{\frac{L}{6}} (1 - \cos 2kx) dx \\ &= \frac{1}{L} \left[ x - \frac{1}{2k} \sin2kx \right]^{\frac{L}{3}}_{\frac{L}{6}} \\ &= \frac{1}{3} + \frac{1}{L} \left[- \frac{L}{2 \pi} \sin \frac{2 \pi x}{L} \right]^{\frac{L}{3}}_{\frac{L}{6}} \\ &= \frac{1}{3} - \left[\frac{1}{2 \pi} \sin \frac{2 \pi}{x} \right]^{3}_{6} \\ &= \frac{1}{3} + \frac{\sqrt{3}}{2 \pi} \neq \frac{1}{6} \end{align}

There are two errors: First, $$\frac{1}{L} \bigl[ x \bigr]^{\frac{L}{3}}_{\frac{L}{6}} = \frac 16$$ and not $$1/3$$. Second, $$\left[\frac{1}{2 \pi} \sin \frac{2 \pi}{x} \right]^{3}_{6} = \frac{1}{2 \pi} \left( \sin \frac{2\pi}{3}- \sin \frac{ \pi}{3}\right) = 0 \, .$$ It seems that you added the terms instead of subtracting them.
With these corrections you'll get the expected result $$1/6$$.
There is a trick. Integrate by parts $$\int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2(kx)~\mathrm{d}x = -\frac{1}{k}\cos(kx)\sin(kx) \bigg \vert^{\frac{L}{3}}_{\frac{L}{6}} + \int^{\frac{L}{3}}_{\frac{L}{6}} \cos^2(kx)~\mathrm{d}x = \int^{\frac{L}{3}}_{\frac{L}{6}} \cos^2(kx)~\mathrm{d}x$$ So: $$\left(\frac{L}{3}-\frac{L}{6}\right) = \int^{\frac{L}{3}}_{\frac{L}{6}} 1~\mathrm{d}x = \int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2(kx) + \cos^2(kx)~\mathrm{d}x =$$ $$\int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2(kx) ~\mathrm{d}x+ \int^{\frac{L}{3}}_{\frac{L}{6}} \cos^2(kx)~\mathrm{d}x =2\int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2(kx) ~\mathrm{d}x$$ Rearrange to get $$\int^{\frac{L}{3}}_{\frac{L}{6}} \sin^2(kx) ~\mathrm{d}x = \frac{1}{2} \left(\frac{L}{3}-\frac{L}{6}\right).$$