TITLE: Second mean value theorem proof
QUESTION [8 upvotes]: I am asked to prove the second mean value theorem:
Let $f$ and $g$ be defined on $[a,b]$ with $g$ continuous, $f\ge 0$, and $f$ integrable. Then there is a point $x_0 \in (a,b)$ such that
$$
\int_{a}^{b}f(x)g(x)dx = g(x_0) \int_{a}^{b}f(x)dx.
$$
My (incomplete) proof goes as follows:
Since $ [a,b] $ is compact and $ g $ is continuous, we know there exist $ x_1, x_2 \in [a,b] $ such that $ g(x_1) \le g(x) \le g(x_2) $ for any $ x \in [a,b] $. Thus, we have the following string of inequalities
$$
f(x)g(x_1) \le f(x)g(x) \le f(x)g(x_2), \, \, \forall x \in [a,b],
$$
$$
\Rightarrow g(x_1)\int_{a}^{b} f(x)dx \,\le \, \int_{a}^{b} f(x)g(x) dx \, \le  \, g(x_2)\int_{a}^{b}f(x)dx.
$$
My problem now is to show the final equality. It seems to me the intermediate value theorem is somehow involved, but I cannot see how to use it. Furthermore, how do I make use of the $f\ge 0$ condition in the hypothesis?

REPLY [8 votes]: You're almost there. 
Let $\displaystyle h(x) = g(x) \int_a^b f(t) \ dt$. As $g$ is continuous, $h$ is also continuous. Without loss of generality, let $x_1 < x_2$.
By what you've shown above, $\int_a^b f(x)g(x) \ dx$ is a number between $h(x_1)$ and $h(x_2)$. As $h$ is continuous, by the IVP there must be a value $x_0 \in (x_1, x_2)$ such that 
$$h(x_0) = \int_a^b f(x)g(x) \ dx$$
That is, there is an $x_0 \in (x_1, x_2) \subset (a,b) \ $ such that
$$ g(x_0) \int_a^b f(x) \ dx = \int_a^b f(x)g(x) \ dx$$