<s>[INST] integration by integration by parts: $\cos^2(\frac{\pi}{L}\,x)$ (inner argument) Really simple integrale that can by solved much easier, but I wanna try straight integration by parts:
$\begin{array}{ccc}
&D&I \\
+&\cos(\frac{\pi}{L}\,x)&\cos\frac{\pi}{L}\,x \\ \\
-&-\dfrac{L}{\pi}\,\sin(\frac{\pi}{L}\,x)& \dfrac{L}{\pi}\,\sin(\frac{\pi}{L}\,x)
\\\\\\
&\Rightarrow \int\cos^2(\frac{\pi}{L}\,x)
 =& \dfrac{L}{\pi}\cos(\frac{\pi}{L}\,x)\,\sin(\frac{\pi}{L}\,x)+\int\left(\dfrac{L}{\pi}\right)^2\sin\left((\frac{\pi}{L})\right)^2 \\\\ 
&&  \dfrac{L}{\pi}\cos(\frac{\pi}{L}\,x)\,\sin(\frac{\pi}{L}\,x)+\int\left(\dfrac{L}{\pi}\right)^2\left(1-\cos\left((\frac{\pi}{L})\right)^2\right)\\\\
&\Rightarrow 2\,\int\left(\dfrac{L}{\pi}\right)^2\cos^2(\frac{\pi}{L}\,x) 
=&\dfrac{L}{\pi}\cos(\frac{\pi}{L}\,x)\,\sin(\frac{\pi}{L}\,x)-\left(\dfrac{L}{\pi}\right)^2\,x \\\\
&\Rightarrow \int\cos^2(\frac{\pi}{L}\,x) = &\dfrac{\pi\,(\cos(\frac{\pi}{L}\,x)\,\sin(\frac{\pi}{L}\,x))}{2\,L}-\dfrac{x}{2} \\\\
&\text{However, checking the integral gives:} \\\\
&\int\cos^2(\frac{\pi}{L}\,x) = &\dfrac{L\,(\cos(\frac{\pi}{L}\,x)\,\sin(\frac{\pi}{L}\,x))}{2\,\pi}-\dfrac{x}{2}\\\\
&\text{Where does the difference come from? } 
\end{array}$
 [/INST] We have
\begin{align*}
\int \cos^{2}\left(\frac{\pi x}{L}\right) \ dx &= \frac{L}{\pi}\cos\left(\frac{\pi x}{L}\right)\sin\left(\frac{\pi x}{L}\right) + \int \sin^{2}\left(\frac{\pi x}{L}\right) \ dx \\
&= \frac{L}{\pi}\cos\left(\frac{\pi x}{L}\right)\sin\left(\frac{\pi x}{L}\right) + \int\left(1-\cos^{2}\left(\frac{\pi x}{L}\right)\right)\end{align*}
Therefore
$$2\int \cos^{2}\left(\frac{\pi x}{L}\right) \ dx =\frac{L}{\pi}\cos\left(\frac{\pi x}{L}\right)\sin\left(\frac{\pi x}{L}\right)+x$$
</s>