Let $I$ be an interval and let $f : I\rightarrow\mathbb{R}$ be a function. Show that $f$ is convex on $I$ Let $I$ be an interval and let $f : I\rightarrow\mathbb{R}$ be a function. Show that $f$ is
convex on $I$ if and only if the slope of the chord joining $(x_1, f(x_1))$ and
$(x, f(x))$ is less than or equal to the slope of the chord joining $(x, f(x))$
and $(x_2, f(x_2))$ for all $x_1 < x < x_2$ in $I$.
Geometrically the result I have verified but I have not been able to give a formal proof.
 A: for any $x \in (x_1,x_2)$ we can write : $x=tx_1+(1-t)x_2$ which $t \in (0,1)$. if you solve it for $t$ you get :
$$
t = \frac{x_2-x}{x_2-x_1} 
$$
so $x$ become :
$$
x = \big( \frac{x_2-x}{x_2-x_1} \big)x_1 + \big( \frac{x-x_1}{x_2-x_1} \big)x_2
\quad \forall x \in (x_1,x_2) $$
with this transformation the proof of both side is just writing down given equation:
$$
\frac{f(x)-f(x_1)}{x-x_1} \leq \frac{f(x_2)-f(x)}{x_2-x}  
\\ \iff (x_2-x+x-x_1)f(x) \leq (x_2-x)f(x_1)+(x-x_1)f(x_2)
\\ \iff f(x) \leq  \big( \frac{x_2-x}{x_2-x_1} \big)f(x_1) +\big( \frac{x-x_1}{x_2-x_1} \big)f(x_2) 
\\ \iff f(tx_1+(1-t)x_2) \leq tf(x_1)+(1-t)f(x_2) \qquad \forall t \in (0,1) \quad \square$$
A: You want to show that for any fixed $x_1<x<x_2$ in $I$ the following statements are equivalent:
(a) $\quad$ $(x,f(x))$ is below the line joining $x_1,f(x_1)$ and $x_2,f(x_2)$;
(b) $\quad$ the slope of the chord joining $(x_1, f(x_1))$ and
$(x, f(x))$ is less than or equal to the slope of the chord joining $(x, f(x))$
and $(x_2, f(x_2))$.
Let us formalise the geometric intuition: Define $\lambda \in (0,1)$ be such that $x = (1-\lambda) x_1 + \lambda x_2$, and let $a_1$ and $a_2$ the slopes of the cords from condition (b):
$$
  a_1 = \frac{f(x)-f(x_1)}{x-x_1},
\quad \text{and} \quad
  a_2 = \frac{f(x)-f(x_2)}{x-x_2}.
$$
Then conditions (a) and (b) can be formulated as:
(a) $\quad$ $f(x) \leq (1-\lambda) f(x_1) + \lambda f(x_2) \tag{*};$
(b) $\quad$ $a_1\leq a_2$.
Subtracting $f(x)$ from both sides of the inequality (*) we obtain an equivalent inequality
$$
 0 \leq (1-\lambda) [f(x_1)-f(x)] + \lambda [f(x_2)-f(x)],
$$
$$
 0 \leq (1-\lambda) a_1(x_1-x) + \lambda a_2 (x_2-x), \tag{**}
$$
From the definition of $\lambda$ we have
$$
 0 = (1-\lambda) (x_1-x) + \lambda (x_2-x).
$$
Multiplying this equation by $a_1$ and subtracting it from (**), we obtain the following equivalent inequality
$$
 0 \leq \lambda (a_2-a_1) (x_2-x).
$$
Since $\lambda>0$ and $x_2>x$, the obtained inequality is equivalent to $a_2 \geq a_1$.
We conclude that conditions (a) and (b) are equivalent for any $x_1<x<x_2$ in $I$.
