Find the maximum value of $\int_0^1 x^2f(x) - xf^2(x) dx$ 
given $f:[0,1] \to \Bbb{R}$, find the maximum value of $$\int_0^1 x^2f(x) - xf^2(x) dx$$

I tried to factorize it as such:
$$I = \int_0^1 xf(x) ( x - f(x) )dx$$
Then tried Cauchy-Schwarz 
$$\int_0^1 xf(x)(x-f(x))dx \le \sqrt{\int_0^1(xf(x))^2dx \cdot \int_0^1 (x-f(x))^2 dx}$$
RHS is maximum when $\int_0^1 (xf(x))^2 dx = \int_0^1 (x-f(x))^2 dx$. Solving this, 
$$\int_0^1x^2 f^2(x) dx= \int_0^1 x^2 + f^2(x) - 2xf(x)dx \\
\int_0^1 f^2(x)(1-x^2)-2xf(x)+x^2 dx = 0 \\
\int_0^1 f(x)(f(x)(1-x^2) + 2x) = -\frac 13$$
And I got stuck here. I think I'm just overcomplicating things with this method. Is there a simpler way to do this?
 A: I don't know if you are aware of the Euler-Lagrange Identity, but that would solve this in one line. So for any integral of the form
$$J[f] = \int_{x_1}^{x_2} L(x,f(x), f'(x))dx$$
The minima or maxima will occur when $f$ satisfies the following differential equation
$$\frac{\partial L}{\partial f} - \frac{d}{dx}\frac{\partial L}{\partial f'} = 0$$
The derivation is quite well explained here, and should be easy enough to follow: https://en.wikipedia.org/wiki/Calculus_of_variations
So using this, with $L(x,f(x)) = x^2f(x) - xf^2(x)$,
$$\frac{\partial L}{\partial f} = x^2 - 2xf(x) = 0$$
Hence $f(x) = \frac{x}{2}$, and maximum value is $\frac{1}{16}$
Alternate Solution
Rewrite the integral as
$$I = \int_0^1x^3\left(\frac{f(x)}{x} - \left(\frac{f(x)}{x}\right)^2\right)dx$$
Let $\frac{f(x)}{x} = y(x)$
$$I = \int_0^1x^3y(1-y)dx$$
Now, tha maximum attainable value for $y(1-y)$ is when $y = \frac{1}{2}$
Hence, $$I  \leq \int_0^1 \frac{x^3}{4}dx$$
With equality occuring only when $f(x) = \frac{x}{2}$
A: One only has to maximize the value of $x^2f(x)-xf(x)^2$ for every $x\in [0,1]$. The function $y\mapsto x^2y-xy^2$ has derivative $x^2-2xy$, so it attains its maximum when $y=x/2$.
Hence we have
$$
\int_0^1 x^2f(x) - xf^2(x) \,\mathrm{d}x \leq \int_0^1 x^2\frac{x}{2}-x\left(\frac{x}{2}\right)^2 \,\mathrm{d}x = \frac{1}{16},
$$
and the equality holds for $f(x)=x/2$.
A: Starting with the conjecture that
$f(x) = x/2$,
let $f(x) = x/2+g(x)$.
Then
$f(x)(x-f(x))
= (x/2+g(x))(x-(x/2+g(x)))
= (x/2+g(x))(x/2-g(x))
=(x/2)^2-g^2(x)
$
so
$I
 = \int_0^1 xf(x) ( x - f(x) )dx
 = \int_0^1 x((x/2)^2-g^2(x))dx
 = \int_0^1 x((x/2)^2)dx-\int_0^1 xg^2(x))dx
\le 1/16
$
with equality only when
$g(x) \equiv 0$.
Therefore the maximum is when
$f(x) = x/2$.
