# Show $|x-1|$ and $|2x-1|$ are convex functions

Show $|x-1|$ and $|2x-1|$ are convex functions using the fact that a convex function $f:\mathbb{R} \rightarrow \mathbb{R}$ satisfies: for any $x^{(1)},x^{(2)}\in\mathbb{R}$ and $\lambda_1,\lambda_2 \geq0$, where $\lambda_1+\lambda_2=1$ we have $f(\lambda_1x^{(1)}+\lambda_2x^{(2)})\leq\lambda_1f(x^{(1)})+\lambda_2f(x^{(2)})$

I figured out how to solve this for $|x|$ but I am having a hard time applying the same ideas to $|ax-b|$.

For $f(x)=|x|$ I did:

\begin{align} f(\lambda_1x^{(1)}+\lambda_2x^{(2)}) &= |\lambda_1x^{(1)}+\lambda_2x^{(2)}| \\&\leq |\lambda_1x^{(1)}|+|\lambda_2x^{(2)}| \\&= \lambda_1|x^{(1)}|+\lambda_2|x^{(2)}| \\&= \lambda_1f(x^{(1)})+\lambda_2f(x^{(2)}) \end{align}

• Use that $\lambda_1 + \lambda_2 = 1$. Jul 19 '17 at 22:10
• A V-shaped graph is pretty convex. Jul 19 '17 at 22:16

Put $f(x)=|x-1|$ and $g(x)=|2x-1|$. Then for any $x_1,x_2\in\mathbb R$ and $\lambda_1,\lambda_2\geq0$ with $\lambda_1+\lambda_2=1$, we have \begin{align*} f(\lambda_1x_1+\lambda_2x_2)&=|\lambda_1x_1+\lambda_2x_2-1|\\ &=|\lambda_1x_1-\lambda_1+\lambda_2x_2-\lambda_2|\\ &\leq|\lambda_1x_1-\lambda_1|+|\lambda_2x_2-\lambda_2|\\ &=\lambda_1f(x_1)+\lambda_2f(x_2). \end{align*} So $f$ is convex, and the proof that $g$ is convex is similar.