Maximum value of $\int_0 ^1 f(x)(x^2) dx - \int_0^1 x(f(x)^2) dx $ 
Let $f: [0,1] \to \mathbb R$ be a continuous function. What is the maximum value of the following functional?
$$\displaystyle \int_0 ^1 f(x)(x^2) \,\mathrm d x - \int_0^1 x(f(x)^2) \,\mathrm d x $$

Unable to understand how to solve this problem. I have thought about it analytically and think that the following points are important:

*

*$x^2 \le x$ for $x\in [0,1]$

*$(f(x) )^2 x ^2 \le x(f(x))^2$
How do I proceed from here?
 A: We have
$$
\begin{aligned}
\int_0^1 f(x) \cdot x^2 \,dx  - \int_0^1 f^2(x) x \,dx &\leq \sqrt{\left(\int_0^1 f^2(x) x \,dx \right)\left(\int_0^1 x^3 \,dx\right)}  - \int_0^1 f^2(x) x \,dx \\
&= \frac{1}{2}\sqrt{\int_0^1 f^2(x) x \,dx } - \int_0^1 f^2(x) x \,dx\\
&\leq \frac{1}{16} +  \int_0^1 f^2(x) x  \,dx -  \int_0^1 f^2(x) x  \,dx\\
&= \frac{1}{16},
\end{aligned}
$$
where the first inequality follows from the Cauchy-Schwarz inequality, and the second inequality follows from the AM-GM inequality. It can be verified that all inequalities become equalities when $f(x) = x/2$.
A: This sort of hand wavy, but I think it works.  
Let $g(s,t) = st(s-t)$ and find its max and min on $[0,1]\times [0,1].$
The max turns out to be at $(1,1/2),$  which is on the boundary of the
domain.  When we need this result, we can scale it to any square $[0,a]\times [0,a].$
Now take your expression, and push the integrals together to get
$$\int_0^1 x^2f(x) - x(f(x)^2) \; dx = \int_0^1 xf(x)(x-f(x)) \; dx.$$
Rescale $f(x)$ so that its range is $[0,1]$.  (I suppose we just divide $f(x)$ by its maximum value on $[0,1].$) 
The integrand is of the form $st(s-t)$ so to make it as large as possible we want $t=s/2$ by from the result above.  So I think that shows that $f(x) = x/2$ and the integrand is $x(x/2)(x/2)$ making the max $1/16$.  
A: $$I=\int_{0}^{1}x\left(xf(x)-(f(x))^{2}\right)\,dx$$
$$I=\int_{0}^{1}x\left(-\left((f(x))^{2}-xf(x)+\frac{x^{2}}4\right)+\frac{x^{2}}4\right)\,dx$$
$$I=\int_{0}^{1}x\left(\frac{x^{2}}4-\left(f(x)-\frac{x}{2}\right)^{2}\right)\,dx$$
$$\le\int_{0}^{1}\frac{x^{3}}4\,dx=\frac1{16}$$
Following along in the proof, we clearly have equality in this integral if we let $\displaystyle f(x)=\frac{x}2.$
A: The Lagrangian is
$$\mathcal L (x,y) := x^2 y - x y^2$$
Since there is no $y'$ in $\mathcal L$, the Euler-Lagrange equation is simply
$$\partial_y \mathcal L (x,y) = x^2 - 2 x y = x ( x - 2 y) = 0$$
and, thus, $y = \frac{x}{2}$ is critical. Let $y = \frac{x}{2} + \varepsilon (x)$. Hence,
$$\int_0^1 \mathcal L \left( x, \frac{x}{2} + \varepsilon (x) \right) \, \mathrm d x = \cdots = \underbrace{\frac 14 \int_0^1 x^3 \,\mathrm d x}_{=\frac{1}{16}} - \underbrace{\int_0^1  x \left( \varepsilon (x) \right)^2 \, \mathrm d x}_{\geq 0} \leq \frac{1}{16}$$
Thus, $y = \frac{x}{2}$ corresponds to a maximum.
