# Exercise on properties of integration

Suppose $f(x)$ is continuous on $[a, b]$ and differentiable on $(a, b)$. Suppose $m \leq f' \leq M$ on $(a, b)$ and denote $\mu = \dfrac{f(b) - f(a)}{b-a}$. Prove that $$\left|\int_{a}^{b} f(x) \,\mathrm{d}x - \frac{f(a) + f(b)}{2}(b-a)\right| \leq \frac{(M-\mu)(\mu - m)}{2(M-m)}(b-a)^2.$$

The book suggested to compare $f(x)$ with piecewise linear functions, but I do not really know how to go about it. I tried using MVT since $\mu$ was in that form, but I do not know how to proceed.

$\def\d{\mathrm{d}}$First, define$$g(x) = f(x) - \frac{f(b) - f(a)}{b - a} x - \frac{b f(a) - a f(b)}{b - a},$$ then $g(a) = g(b) = 0$, $m - μ \leqslant g' \leqslant M - μ$, and$$\left| \int_a^b f(x) \,\d x - \frac{1}{2} (f(a) + f(b))(b - a) \right| = \left| \int_a^b g(x) \,\d x \right|.$$
Now define $M' = M - μ \geqslant 0$, $m' = m - μ \leqslant 0$, and$$x_1 = \frac{M' a - m' b}{M' - m'},\ x_2 = \frac{M' b - m' a}{M' - m'},$$\begin{align*} g_1(x) &= \begin{cases} M'(x - a); & a \leqslant x \leqslant x_1\\ m'(x - b); & x_1 < x \leqslant b \end{cases}\\ g_2(x) &= \begin{cases} m'(x - a); & a \leqslant x \leqslant x_2\\ M'(x - b); & x_2 < x \leqslant b \end{cases} \end{align*} Here is a figure:
Note that $g_1$ and $g_2$ are both continuous and piecewise linear. Next it will be proved that$$g_2(x) \leqslant g(x) \leqslant g_1(x). \quad \forall a \leqslant x \leqslant b$$ Suppose there exists $x_0 \in (a, b)$ such that $g(x_0) > g_1(x_0)$. If $a < x_0 \leqslant x_1$, then$$M' < \frac{g(x_0) - g(a)}{x_0 - a} = g'(ξ_1) \leqslant M',$$ a contradiction. If $x_1 < x_0 < b$, then$$m' > \frac{g(b) - g(x_0)}{b - x_0} = g'(ξ_2) \geqslant m',$$ a contradiction. Thus $g(x) \leqslant g_1(x)$ for $x \in [a, b]$. Analogously, $g(x) \geqslant g_2(x)$ for $x \in [a, b]$. Therefore,$$\int_a^b g(x) \,\d x \leqslant \int_a^b g_1(x) \,\d x = -\frac{M' m'}{2(M' - m')} (b - a)^2,\\ \int_a^b g(x) \,\d x \geqslant \int_a^b g_2(x) \,\d x = \frac{M' m'}{2(M' - m')} (b - a)^2,$$ which implies$$\left| \int_a^b g(x) \,\d x \right| \leqslant \left| -\frac{M' m'}{2(M' - m')} (b - a)^2 \right| = -\frac{M' m'}{2(M' - m')} (b - a)^2,$$ then\begin{align*} &\mathrel{\phantom{=}}{} \left| \int_a^b f(x) \,\d x - \frac{1}{2} (f(a) + f(b))(b - a) \right| = \left| \int_a^b g(x) \,\d x \right|\\ &\leqslant -\frac{M' m'}{2(M' - m')} (b - a)^2 = \frac{(M - μ)(μ - m)}{2(M - m)} (b - a)^2. \end{align*}