Convex function with modulus Find the values of the real parameter $a$ such that the function
$f:[0,1] \to R, f(x)=x^2-|x-a|$ is a convex function.
It is clear that if $a=0$ or $a=1$ the function will be the restriction of a quadratic function, thus convex.
And intutively f is not convex when $ a \in (0,1)$ because in that case the function would have "a concavity" around the point $a$. but i would be interested in a rigorous approach in this case.
 A: You said:

It is clear that if $a=0$ or $a=1$ the function will be the restriction of a quadratic function, thus convex.

That is correct, and holds even for  $a \le 0$ and for $a \ge 1$.
Then you said:

And intutively f is not convex when $ a \in (0,1)$ because in that case the function would have "a concavity" around the point $a$.

For a rigorous approach we can compute 
$$
\frac 12 \bigl( f(a-h) + f(a+h)\bigr) - f(a)
$$
which should be $\ge 0$ for a convex function. But if $0 < a < 1$ and $0 < h < \min(a, 1-a)$ (so that all terms are defined) this expression evaluates to
$$
 h^2-2h = (1-h)^2 - 1 < 0 \, ,
$$
so that $f$ is not convex.
Alternatively: If $f$ were convex then
$$
 f(x) \le (1-x)f(0) + x f(1) = (1-x)(-a) + xa = -a + 2ax
$$
for all $x \in [0, 1]$, this is violated at $x=a$ with $f(a) = a^2$.
Yet another approach for the case $0 < a < 1$ would be to observe that
$$
 f'(x) = \begin{cases}
2x + 1 & \text{for } 0 \le x < a \\
2x - 1 & \text{for } a < x \le 1 \\
\end{cases}
$$
which also demonstrates that $f$ is not convex on $[0, 1]$, because
a convex function has a right (and left) derivative at every point, and the right (and left) derivative is monotonically increasing.
