Proof of convexity of $f(x)=x^2$ I know that a function is convex if the following inequality is true:
$$\lambda f(x_1) + (1-\lambda)f(x_2) \ge f(\lambda x_1 + (1-\lambda)x_2)$$ 
for $\lambda \in [0, 1]$ and $f(\cdot)$ is defined on positive real numbers.
If $f(x)=x^2$, I can write the following:
$$\lambda x_1^2 + (1-\lambda)x_2^2 \ge (\lambda x_1 + (1-\lambda)x_2)^2$$
$$0 \ge (\lambda ^2 - \lambda) (x_1^2 - x_2 ^ 2) $$
But I am not sure if this is true or not. How can I prove this?
 A: $$\lambda x_1^2 + (1-\lambda)x_2^2 \ge (\lambda x_1 + (1-\lambda)x_2)^2\iff$$
$$\lambda x_1^2+(1-\lambda)x_2^2\ge\lambda^2 x_1^2+2\lambda(1-\lambda)x_1x_2+(1-\lambda)^2x_2^2\iff$$
$$\lambda x_1^2(1-\lambda)+(1-\lambda)x_2^2(1-(1-\lambda))-2\lambda(1-\lambda)x_1x_2\ge 0\stackrel{\text{assuming}\;\lambda\neq1}\iff$$
$$\lambda x_1^2+\lambda x_2^2-2\lambda x_1x_2\ge 0\iff\lambda(x_1-x_2)^2\ge 0$$
and since the last inequality is obvious we're done (if $\;\lambda=1\;$ there's nothing to prove...)
A: You made a mistake in your simplification, it should reduce to showing
$(1-\lambda) \lambda (x_1-x_2)^2 \ge 0$.
Since $\lambda \in [0,1]$, we have $(1-\lambda) \lambda \ge 0$ from which the result follows.
A: You made a mistake in your rearranging. The following are equivalent: $$\begin{eqnarray*}\lambda x_1^2+(1-\lambda)x_2^2 & \ge & \bigl(\lambda x_1+(1-\lambda)x_2\bigr)^2\\(1-\lambda)x_2^2 + \lambda x_1^2 & \ge & \lambda^2 x_1^2+2\lambda(1-\lambda)x_1x_2+(1-\lambda)^2x_2^2\\\lambda x_1^2 & \ge & \lambda^2 x_1^2+2\lambda(1-\lambda)x_1x_2+\bigl[(1-\lambda)^2-(1-\lambda)\bigr]x_2^2\\\lambda x_1^2 & \ge & \lambda^2 x_1^2+2\lambda(1-\lambda)x_1x_2+(1-\lambda)\bigl[(1-\lambda)-1\bigr]x_2\\\lambda x_1^2 & \ge & \lambda^2x_1^2+2\lambda(1-\lambda)x_1x_2+(1-\lambda)(-\lambda) x_2^2\\0 & \ge & (\lambda^2-\lambda)x_1^2+2\lambda(1-\lambda)x_1x_2+(1-\lambda)(-\lambda) x_2^2\\0 & \ge & \lambda(\lambda-1)x_1^2-2\lambda(\lambda-1)x_1x_2+\lambda(\lambda-1)x_2^2\\0 & \ge & \lambda(\lambda-1)(x_1-x_2)^2\end{eqnarray*}$$
The final inequality is true for all $\lambda$ if $x_1=x_2.$ If $x_1\ne x_2,$ then since $\lambda\ge\lambda-1,$ the final inequality holds exactly when $\lambda\geq 0\geq \lambda-1,$ or equivalently, when $\lambda\in[0,1].$
