Evaluating $\int_{0}^{\frac{\pi}{2}} x^{2} \ln (\cos x) d x$ Latest Edit
As suggested by Mr Claude Leibovici, I go further to investigate the integral in general,
$$I_{m}:=\int_{0}^{\frac{\pi}{2}} x^{m} \ln (\cos x) d x$$
By the Fourier Series of ln(cos x)
,
$ \displaystyle \ln (\cos x)=-\ln 2+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \cos (2 n x) \tag*{(*)} $
Multiplying (*) by $ x^m$ and then Integrating both sides from $0 $ to $\frac{\pi}{2}$ yields
$$\begin{aligned}
I_m&=-\int_{0}^{\frac{\pi}{2}} x^{m} \ln 2 d x+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n !} \int_{0}^{\frac{\pi}{2}} x^{m} \cos (2 n x) d x\\&= -\frac{\pi^{m+1}\ln 2}{(m+1) 2^{m+1}}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} J(m, n)\end{aligned}
$$
Next we need a reduction formula on $J(m,n)$.
Applying integration by parts twice, we obtain
$$
\begin{aligned}J(m, n)&=\frac{1}{2 n} \int_{0}^{\frac{\pi}{2}} x^{m} d(\sin 2 n x)\\ &= -\frac{m}{2 n} \int_{0}^{\frac{\pi}{2}} x^{m-1} \sin 2 n x d x\\&=\frac{m}{4 n^{2}} \int_{0}^{\frac{\pi}{2}} x^{m-1} d(\cos 2 n x)\\&=\frac{(-1)^{n} \pi^{m-1} m}{2^{m+1} n^{2}} -\frac{m(m-1)}{4 n^{2}} J (m-2, n)\end{aligned}
$$
By the reduction formula of $J(m,n)$, we can find $I_m$ by plugging $J(m,n)$.

By the Fourier Series of ln(cos x)
,
$ \displaystyle \ln (\cos x)=-\ln 2+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \cos (2 n x) \tag*{(*)} $
Multiplying (*) by $ x^2$ and then Integrating both sides from $0 $ to $\frac{\pi}{2}$ yields
$\displaystyle I=-\underbrace{\int_{0}^{\frac{\pi}{2}} x^{2} \ln 2 d x}_{\frac{\pi^{3} \ln 2}{24}}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \underbrace{ \int_{0}^{\frac{\pi}{2}} x^{2} \cos (2 n x) d x}_{J_n}\tag*{} $
Integrating by parts twice yields
$\displaystyle \begin{aligned}J_{n} &=\frac{1}{2 n} \int_{0}^{\frac{\pi}{2}} x^{2} d(\sin 2 n x) \\&=\frac{1}{2 n}\left[x^{2} \sin 2 n x\right]_{0}^{\frac{\pi}{2}}-\frac{1}{n} \int_{0}^{\frac{\pi}{2}} x \sin 2 n x d x \\&=\frac{1}{2 n^{2}} \int_{0}^{\frac{\pi}{2}} x d(\cos 2 n x) \\&=\left[\frac{1}{2 n^{2}} x \cos 2 n x\right]_{0}^{\frac{\pi}{2}}-\frac{1}{2 n^{2}} \int_{0}^{\frac{\pi}{2}} \cos 2 n x d x \\&=\frac{\pi}{4 n^{2}} \cos n \pi-\frac{1}{2 n^{2}}\left[\frac{\sin 2 n x}{2 n}\right]_{0}^{\frac{\pi}{2}} \\&=\frac{\pi}{4 n^{2}} \cos n \pi\end{aligned}\tag*{} $
We can now conclude that
$\displaystyle \begin{aligned}I &=-\frac{\pi^{3} \ln 2}{24}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \cdot \frac{\pi}{4 n^{2}} \cos n \pi \\&=-\frac{\pi^{3} \ln 2}{24}+\frac{\pi}{4} \sum_{n=1}^{\infty} \frac{(-1)^{n+1}(-1)^{n}}{n^{3}} \\&=-\frac{\pi^{3} \ln 2}{24}-\frac{\pi}{4} \sum_{n=1}^{\infty} \frac{1}{n^{3}} \\&=\boxed{-\frac{\pi^{3} \ln 2}{24}-\frac{\pi}{4} \zeta(3)}\end{aligned}\tag*{} $
Is there any other method to evaluate $I$?
 A: Using $(*)$, I think that we could even make the problem more general using the incomplete gamma function or the exponential integral function
$$\int x^p \cos(2nx)\,dx=-\frac{1}{2} x^{p+1} (E_{-p}(-2 i n x)+E_{-p}(2 i n x))$$
$$K_p=\int_0^{\frac \pi 2} x^p \cos(2nx)\,dx=$$ $$-i^{p+1} 2^{-p-2} n^{-p-1} \left(\Gamma (p+1,-i n \pi )-(-1)^p \Gamma (p+1,i n \pi
   )+\left((-1)^p-1\right) \Gamma (p+1)\right)$$ which simplifies a lot if $p$ is even
$$K_{2m}=i\,(-1)^{m+1} \,2^{-2 (m+1)}\,n^{-(2m+1)}\,(\Gamma (2 m+1,-i n \pi )-\Gamma (2 m+1,i n \pi ))$$
So, as you found
$$K_2=\frac{\left(\pi ^2 n^2-2\right) \sin (\pi  n)+2 \pi  n \cos (\pi  n)}{8 n^3}=(-1)^n\frac{\pi  }{4 n^2}$$
$$K_4=(-1)^n \frac{\pi   \left(\pi ^2 n^2-6\right)}{8 n^4}\qquad \qquad K_6=(-1)^n \frac{3 \pi  \left(\pi ^4 n^4-20 \pi ^2 n^2+120\right)}{64 n^6}$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_2=-\frac{\pi  }{4}\zeta (3)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_4=-\frac{\pi}{8}   \left(\pi ^2 \zeta (3)-6 \zeta (5)\right)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_6=-\frac{3\pi}{64}   \left(\pi ^4 \zeta (3)-20 \pi ^2 \zeta (5)+120 \zeta (7)\right)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_8=-\frac{\pi }{64}  \left(\pi ^6 \zeta (3)-42 \pi ^4 \zeta (5)+840 \pi ^2 \zeta (7)-5040
   \zeta (9)\right)$$
Edit
In fact, no much problem if $p$ is odd
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_1=-\frac{7 }{16}\zeta (3)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_3=-\frac{3}{128} \left(8 \pi ^2 \zeta (3)-31 \zeta (5)\right)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_5=-\frac{5}{512} \left(8 \pi ^4 \zeta (3)-96 \pi ^2 \zeta (5)+381 \zeta (7)\right)$$
$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} K_7=-\frac{7}{4096} \left(16 \pi ^6 \zeta (3)-480 \pi ^4 \zeta (5)+5760 \pi ^2 \zeta (7)-22995 \zeta
   (9)\right)$$
A: Hint for an alternative approach:
First, reduce the integral
$$
\int_0^{\pi/2} x^2\log(2\cos x)\,dx
= \frac{4\pi}7 \int_0^{\pi/2} x\log(2\cos x)\,dx
$$
and, then, show that
\begin{align}
&\int_0^{\pi/2} x\log(2\cos x)\,dx
= -\frac12\int_0^\infty \frac{\ln t\tan^{-1}t}{1+t^2} dt 
=- \frac 7{16}\zeta(3)
\end{align}
A: As Mr Claude Leibovici suggested, I go further to investigate the integral in general,
$$I_{m}:=\int_{0}^{\frac{\pi}{2}} x^{m} \ln (\cos x) d x$$
By the Fourier Series of ln(cos x)
,
$ \displaystyle \ln (\cos x)=-\ln 2+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \cos (2 n x) \tag*{(*)} $
Multiplying (*) by $ x^m$ and then Integrating both sides from $0 $ to $\frac{\pi}{2}$ yields
$$\begin{aligned}
I_m&=-\int_{0}^{\frac{\pi}{2}} x^{m} \ln 2 d x+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n !} \int_{0}^{\frac{\pi}{2}} x^{m} \cos (2 n x) d x\\&= -\frac{\pi^{m+1}\ln 2}{(m+1) 2^{m+1}}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} J(m, n)\end{aligned}
$$
Next we need a reduction formula on $J(m,n)$.
Applying integration by parts twice, we obtain
$$
\begin{aligned}J(m, n)&=\frac{1}{2 n} \int_{0}^{\frac{\pi}{2}} x^{m} d(\sin 2 n x)\\ &= -\frac{m}{2 n} \int_{0}^{\frac{\pi}{2}} x^{m-1} \sin 2 n x d x\\&=\frac{m}{4 n^{2}} \int_{0}^{\frac{\pi}{2}} x^{m-1} d(\cos 2 n x)\\&=\frac{(-1)^{n} \pi^{m-1} m}{2^{m+1} n^{2}} -\frac{m(m-1)}{4 n^{2}} J (m-2, n)\end{aligned}
$$
By the reduction formula of $J(m,n)$, we can find $I_m$ by plugging $J(m,n)$.

For example,
$$
\begin{aligned}
I_{3} &=-\frac{\pi^{4} \ln 2}{64}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} J(3, n) \\
&=-\frac{\pi^{4} \ln 2}{64}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n}\left[\frac{3(-1)^{n} \pi^{2}}{16 n^{2}}-\frac{3}{2 n^{2}} J(1, n)\right] \\
&=-\frac{\pi^{4} \ln 2}{64}-\frac{3 \pi^{2}}{16} \zeta(3)-\frac{3}{2} \sum_{n=1}^{\infty} \frac{(-1)^{n}}{n^{3}}\left[\frac{1}{4 n^{2}}(1-(-1)^n)\right] \\
&=-\frac{\pi^{4} \ln 2}{64}-\frac{3 \pi^{2}}{16} \zeta(3)+\frac{3}{4} \sum_{n=1}^{\infty} \frac{1}{(2 n+1)^{5}} \\
&=-\frac{\pi^{4} \ln 2}{64}-\frac{3 \pi^{2}}{16} \zeta(3)+\frac{93}{128}\zeta(5)
\end{aligned}
$$

$$
\begin{aligned}
I_{4}=&-\frac{\pi^{5} \ln 2}{160}+\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n}\left(\frac{(-1)^{n} \pi^{3}}{8 n^{2}}-\frac{3}{n^{2}} J(2, n)\right) \\
=&-\frac{\pi^{5} \ln 2}{160}-\frac{\pi^{3}}{8} \sum_{n=1}^{\infty} \frac{1}{n^{3}}+3 \sum_{n=1}^{\infty} \frac{(-1)^{n}}{n^{3}} \left(\frac{(-1)^{n} \pi}{4 n^{2}}-\frac{1}{2 n^{2}} J(0, n)\right) \\
=&-\frac{\pi^{5} \ln 2}{160}-\frac{\pi^{3}}{8} \zeta(3)+\frac{3 \pi}{4} \zeta(5) \end{aligned}
$$
Is there a closed form for the integral $I_m$ ?
A: Disclaimer: not an efficient way, just a doable one.
We may reduce the integral to standard hypergeometric series / Euler sums, since
$$ I = \int_{0}^{\pi/2}\left(\frac{\pi}{2}-x\right)^2\log(\sin x)\,dx=\int_{0}^{1}\left(\frac{\pi}{2}-\arcsin(x)\right)^2\frac{\log(x)}{\sqrt{1-x^2}}\,dx $$
and
$$ \int_{0}^{1}\frac{\log(x)}{\sqrt{1-x^2}}\,dx = -\frac{\pi}{2}\log(2) \tag{WellKnown} $$
$$\int_{0}^{1}\arcsin(x)\frac{\log(x)}{\sqrt{1-x^2}}\,dx=\int_{0}^{\pi/2}x\log(\sin x)\,dx =\frac{7}{16}\zeta(3)-\frac{\pi^2}{8}\log(2)\tag{ByFourierSeries}$$
$$ \arcsin^2(x)=\sum_{n\geq 1}\frac{4^n x^{2n}}{2n^2\binom{2n}{n}} \tag{SquaredArcsin}$$
as shown here. Since
$$ \int_{0}^{1}\frac{x^{2n}\log(x)}{\sqrt{1-x^2}}\,dx = -\frac{\pi}{4^{n+1}}\binom{2n}{n}\left(H_n-H_{n-1/2}\right)$$
by differentiation of a Beta function and $\sum_{n\geq 1}\frac{H_n}{n^2}=2\zeta(3)$ is also well-known, the whole problem boils down to the evaluation of
$$ \sum_{n\geq 1}\frac{H_{n-1/2}}{n^2} $$
which can be performed through standard tricks. The last series equals $-\frac{\pi^2}{3}\log(2)+\frac{7}{2}\zeta(3)$.
