# 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?

• Hint: if a function is second-differentiable, and $f''(x)>0$ for all $x\in A$, then $f$ is convex in $A$. – Hayden Nov 25 '13 at 18:20
• @Hayden From a few books and online I saw that the derivative method is used much, but I try to figure out using the definition. Unfortunately, I still cannot do this for other functions such as $x^3$, $\log x$, $x \log x$ and $e^{-x}$. – groove Nov 26 '13 at 18:11

You made a mistake in your rearranging. The following are equivalent: $$\lambda x_1^2+(1-\lambda)x_2^2\ge\bigl(\lambda x_1+(1-\lambda)x_2\bigr)^2\\\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\\\lambda x_1^2+x_2^2-\lambda x_2^2\ge\lambda^2 x_1^2+2\lambda(1-\lambda)x_1x_2+x_2^2-2\lambda x_2^2+\lambda^2x_2^2\\0\ge(\lambda^2-\lambda)x_1^2+2\lambda(1-\lambda)x_1x_2+(\lambda^2-\lambda)x_2^2\\0\ge(\lambda^2-\lambda)x_1^2-2(\lambda^2-\lambda)x_1x_2+(\lambda^2-\lambda)x_2^2\\0\ge(\lambda^2-\lambda)(x_1-x_2)^2$$

The final inequality is true for all $\lambda$ if $x_1=x_2,$ and if $x_1\ne x_2,$ then the final inequality holds exactly when $\lambda\in[0,1].$

$$\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...)

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.