Proving two continuous functions that take on all values in interval must intersect Consider continuous real valued functions $f$ and $g$, defined over interval $I$.  In $I$, $f$ and $g$ each take on $a$ and $b$, and therefore, take on values in $[a,b]$.  I would like to prove that there must be an $x$ in $I$ where $f(x) = g(x)$.  Intuitively, this is obvious by definition of continuity; however, I've been unable to prove it.
Here is what I have been able to do so far:
Consider $h(x) = f(x) - g(x)$.  WLOG, assume that at the start of $I$, $f > g$, so that $h > 0$.  Now, if I can show that at some point $g >= $f, QED, by Intermediate Value Theorem.  However, I haven't been able to prove that there exists a point where $g >= $f.
I can make an intuitive argument that this is so, because if $g$ is always bounded by $f$ and never equal to $f$, $g$ will be "trapped" and not able to take on $b$.  Yet, even this is not clear, because perhaps $f > $g, and $g$ reaches $b$ when $f > b$.
An alternative approach is that since there exists a minimum $\epsilon$ such that $f = g + \epsilon$.  Show that $\epsilon$ must go to zero; again, I'm not sure how to prove this.
Finally, it seams to me that the Mean Value Theorem might be useful here, but, again, I can't figure out a means to use it.
A few notes:


*

*I thought of this problem while considering the well known brain teaser of a person climbing down a mountain on day 1, and a person climbing up the same mountain on day 2, that there must be a spot where both people were at at the same time.

*If I misused any terminology in writing this problem, please edit and correct.

*Would my assertion be true if I relaxed the initial conditions to be only all values in $(a,b)$? And, does it matter if the interval $I$ is open or closed (I think it doesn't.)

UPDATE
To address the comments, I will clarify the given conditions.  If there exists better terminology that would not necessitate correction, please help me to use it.


*

*Interval $I$ is an open or closed interval from $p$ to $q$

*$f$ and $g$ are continuous real valued functions defined on $I$

*There exists values $r,s,t,u$ in $I$ such that $f(r) = a, f(s) = b, g(t) = a, g(u) = b$.  I've called this "f and g each take on a and b"; if there is better terminology, please tell me.

*By virtue of #3 and the Intermediate Value Theorem, I conclude that for all $v$ in $[a,b]$, there exists a $w$ and $z$ in $I$ such that $f(w) = g(z) = v$.  This is what I mean that "f and g take on all values in [a,b]".


To respond to the questions:


*

*It seems that I must assume that $I$ is finite.

*$[a,b]$ is a subset of $f(I)$, not necessarily equal.


And, thank you to the commenters, who pointed out that I need another key condition: f and g are bounded by $[a,b]$.
 A: I think we need to assume $a \le f(x) \le b$ and $a \le g(x) \le b$for all $x \in I$ .  Other wise we can do $[a,b] = [1,2]$, $I = [0,1]$, $f(x) = 1000x$ and $g(x) = 1000x + .05$.
Let $f(x_1) = b$ then $g(x_1) \le b$.  If $g(x_1) = b$ we are done so suffices to assume $f(x_1) < b$.  Let $g(x_2) = b$ (suffices to assume $x_2 \ne x_1$) then $f(x_2) \le b$ (suffices to assume $f(x_2) < b$).
So if $h(x) = f(x) - g(x)$ then $h$ is continuous and $h(x_1) < 0$ and $h(x_2) > 0$ as so by Intermediate value theorem there is a $c$ between $x_1$ and $x_2$ so that $h(c) = f(c) - g(c) = 0$.
(Unless, of course $f(x_1) = g(x_1) = b$ or $f(x_2) = g(x_2) = b$.)
It need not be so for $(a,b)$ and $a < f(x) < b$ and $a < g(x) < b$.  Let $f(x) = x$ and $g(x) = x^2$ with $I=(a,b) = (0,1)$ we have $g(x) < f(x)$ for all $x\in (0,1)$ and we have all values of $(0,1)$ being reached by both $f$ and $g$.
A: Finally, with the last key condition, this becomes a true statement. Here's one possible way to prove it, along the lines of what you were doing. WLOG, let's assume that $a<b$ (which you've been assuming all along, I guess, judging by the appearance of the interval $[a,b]$.) Then we know that $a\le f(x)\le b$ and $a\le g(x)\le b$ on $I$, and both $f$ and $g$ attain both $a$ and $b$ on $I$.
Let $h(x)=f(x)-g(x)$, as you suggested. Let $x_1$ and $x_2$ be some points where $f(x_1)=a$ and $f(x_2)=b$. If also $g(x_1)=a$ or $g(x_2)=b$, we're done. Otherwise we know that: $g(x_1)>a=f(x_1)$ and thus $h(x_1)<0$; and $g(x_2)<b=f(x_2)$ and thus $h(x_2)>0$. Now apply the Intermediate Value Theorem on $[x_1,x_2]$ or $[x_2,x_1]$ (depending which one is to the left or to the right).
