Rolle's Theorem: why do we need the premise $f(a) = f(b)$? 
If a real-valued function $f$ is continuous on a closed interval $[a, b]$, differentiable on the open interval $(a, b)$, and $f(a) = f(b)$, then there exists at least one $c$ in the open interval $(a, b)$ such that $f'(c) = 0$.

Above you can see Rolle's theorem. It contains three premises:


*

*$f$ must be continuous on the interval $[a,b]$

*$f$ must be differentiable on the open interval $(a,b)$

*$f(a) = f(b)$


I understand why we need the first two premises, but I don't see the meaning of the third one. Could you please tell me why do we need $f(a) = f(b)$?
Thank you for your help!
 A: Suppose we don't have $f(a)=f(b)$. The function $f(x)=x$ is a valid counerexample on any interval.
A: The proof of Rolle's theorem says that (since $f$ is continuous on the closed interval $[a,b]$), it must attain both a minimum and a maximum value there.  Let $m = \min_{x\in [a,b]} f(x)$, $M = \max_{x \in [a,b]} f(x)$.  If $m = M$, then $f$ is constant, so it has a zero derivative everywhere on $(a,b)$.  Now, suppose $m < M$.  
If $f(a) = f(b)$, then we can conclude that either $m \not\in \{f(a), f(b)\}$ or $M \not\in \{f(a), f(b)\}$, so $f$ has either a local minimum or a local maximum at some point $c \in (a,b)$.  By playing with the definition of minimum (maximum), we can see that $f'(c) = 0$.
On the other hand, if $f(a) \not= f(b)$, then $f$ could be a strictly increasing (or decreasing) function, so, say, $f(a) = m$, $f(b) = M$, and $f'(x) > 0$ for all $x \in (a,b)$.
A: Take $f(x) = x, a = 0, b = 1$. Then there's no point in the unit interval such that $f' = 0$. 
The generalization of this theorem is of course the mean value theorem: there will be a point $c$ such that
$$
f'(c) = \frac{f(b) - f(a)}{b-a}.
$$
Rolle's theorem is just the special case that $f(a) = f(b)$, and so the numerator of the fraction above is necessarily $0$.
