TITLE: Maximize $\int_0^1 x^2f(x)~\mathrm dx - \int_0^1 xf(x)^2~\mathrm dx$ among continuous $f:[0,1]\to\Bbb R$
QUESTION [12 upvotes]: For a function $f$, let 
$$
a = \int_{0}^{1} x^2f(x) \mathrm{d}x\\
b = \int_{0}^{1} xf^2(x) \mathrm{d}x,
$$
where $f$ is a continuous function from $[0,1]$ to $\mathbb{R}$.
  Then find $\text{max}\{a-b\}$ for all such $f$.

I am getting $\dfrac {1}{16}$. Note that it can be written as $\int_{0}^{1} \left({\dfrac{x^3}{4}-x(f(x)-\dfrac{x}{2})^2}\right)dx$. I guess that's less than $\int_{0}^{1} \dfrac{x^3}{4} dx$ which is $\dfrac {1}{16}$.

REPLY [5 votes]: Here is another approach in the case we can't express the integral in the way you did (see the comment of @DanielFischer). Let $X=C([0,1])$ and $I:X\to\mathbb{R}$ be defined by $$I(f)=\int_0^1 x^2f(x)-\int_0^1xf(x)^2$$
Note that $I$ is a continuously differentiable function and $$\langle I'(f),g\rangle =\int_0^1 (x^2 g(x)-2xf(x)g(x)),\ \forall\ f,g\in X$$
We want to find $f\in X$ such that $$\langle I'(f),g\rangle=0,\ \forall\ g\in X$$
Therefore $$f(x)=\frac{x}{2}$$
To verify that $f$ is a maximum, note that $$I(f+h)=\int_0^1\left(\frac{x^3}{4}-xh(x)^2\right)$$