TITLE: Minimizing the value of this integral $ I \equiv \int_{0}^{\pi/2}\left\vert\,\cos\left(x\right) - kx^{2}\,\right\vert \,{\rm d}x $
QUESTION [9 upvotes]: Given the integral
$$
I \equiv \int_{0}^{\pi/2}\left\vert\,\cos\left(x\right) - kx^{2}\,\right\vert
\,{\rm d}x
$$
Find the value of $k$ so that $I$ is minimum.

How do I start?

REPLY [7 votes]: 1. Heuristic Calculation
Differentiating under the integral sign, we have
$$ I'(k) = \int_{0}^{\pi/2} \operatorname{sign}(\cos x - kx^{2}) (-x^{2}) \, dx. $$
Let $k_{0}$ be the minimum point and $\cos\alpha - k_{0}\alpha^{2} = 0$. Then
$$ 0 = I'(k_{0}) = - \int_{0}^{\alpha} x^{2} \, dx + \int_{\alpha}^{\pi/2} x^{2} \, dx = \frac{\pi^{3}}{24} - \frac{2\alpha^{3}}{3}. $$
Solving this, we get $\alpha = \frac{\pi}{2^{4/3}}$ and therefore
$$k_{0} = \frac{\cos \alpha}{\alpha^{2}} = \frac{2^{8/3}}{\pi^{2}} \cos \left( \frac{\pi}{2^{4/3}} \right) \approx 0.20485055820305523635\cdots. $$
2. Preliminary
The following observations are introduced for rigor. You can skip the detail when you are only interested in the actual calculation.

Observation 1. $I(k)$ has a minimum point, and every minimum point of $I(k)$ lies on $[0, \infty)$.

Proof. By the triangle inequality,
$$ I(k) \geq \int_{0}^{\pi/2} |k| x^{2} - \cos x \, dx = \frac{\pi^{3}|k|}{24} - 1 \xrightarrow{|k|\to\infty} \infty. $$
and hence $I(k) \to \infty$ as $|k| \to \infty$. In other words, $I(k)$ is coercive. So $I$ attains a minimum at some point. Also, if $k \leq 0$, then $|\cos x - kx^{2}| = \cos x  - kx^{2}$ and hence
$$ I(k) = 1 - \frac{\pi^{3}k}{24}, \quad k \leq 0, $$
which is decreasing. This shows that if $I$ has the minimum, then it occurs when $k \geq 0$. ////

Observation 2. If $k > 0$, the unique solution $x = \alpha(k)$ to
  $$\cos x - kx^{2} = 0, \quad 0 < x < \tfrac{\pi}{2} $$
  defines a smooth function $\alpha : k \mapsto \alpha(k)$.

Proof. Let $D = \{ (x, k) : 0 < x < \frac{\pi}{2} \text{ and } k > 0 \}$ and $F : D \to \Bbb{R}$ be defined as
$$F(x, k) = \cos x - kx^{2}.$$
Then $F$ is strictly decreasing for each $k > 0$:
$$ \frac{\partial F}{\partial x} = -\sin x - 2kx < 0. \tag{*} $$
Moreover, $F(0, k) = 1$ and $F(\frac{\pi}{2}, k) < 0$.  Thus by Intermediate Value Theorem, for each $k > 0$ there exists a unique $\alpha(k) \in (0, \frac{\pi}{2})$ such that $F(\alpha(k), k) = 0$.
Now by Implicit Function Theorem with $\text{(*)}$, the level set $F(x, k) = 0$ is locally graph of smooth function. But we already know that the set $F(x, k) = 0$ is the graph of $\alpha$. Therefore $\alpha$ is smooth. ////
3. Justification of Heuristics
Now we are ready to calculate the minimum point. Notice that
\begin{align*}
I(k)
&= \int_{0}^{\alpha(k)} (\cos x - kx^{2}) \, dx - \int_{\alpha(k)}^{\pi/2} (\cos x - kx^{2}) \, dx. \tag{1}
\end{align*}
is a smooth function of $k$ for $k > 0$. Differentiating $\text{(1)}$ and utilizing the identity
$$\cos\alpha(k) - k \alpha(k)^{2} = 0,$$
we get the following simple result for $ k > 0$:
\begin{align*}
I'(k)
&= \int_{0}^{\alpha(k)} (-x^{2}) \, dx - \int_{\alpha(k)}^{\pi/2} (-x^{2}) \, dx
 = \frac{\pi^{3}}{24} - \frac{2\alpha(k)^{3}}{3}.
\end{align*}
Since $\alpha(0^{+}) = \frac{\pi}{2}$, we have $I(0^{+}) < 0$ and hence $I$ is also decreasing near $k = 0$. So any minimum point $k_{0}$ of $I$ occurs on $k_{0} > 0$.
Thus we must get $I'(k_{0}) = 0$, and solving this equation in terms of $\alpha(k_{0})$ gives
$$ \alpha(k_{0}) = \frac{\pi}{2^{4/3}} \approx 1.2467418707910012667\cdots. $$
Therefore the minimum point $k_{0}$ is unique and it is given by
$$ k_{0} = \frac{\cos \alpha(k_{0})}{\alpha(k_{0})^{2}} = \frac{2^{8/3}}{\pi^{2}} \cos \left( \frac{\pi}{2^{4/3}} \right) \approx 0.20485055820305523635\cdots. $$