Prove that $[a,b]$ is connected space. Prove that $[a,b]$ is connected space.
I know that $\mathbb{R}$ with euclidean metric is connected space. I would like find surjective function $f: \mathbb{R} \rightarrow [a,b]$. Because $\mathbb{R}$ is connected and $f$ is surjective function then $[a,b]$ is also connected space. Is it possible to find these function? I can't imagine how can look this function and how can I make a draw? 
I tried with function $f(x) = \frac{1}{1+x^2}$ which is bounded ($0<f(x) \le 1$) and scale them such that $a<f(x) \le b$.
 A: Simply define it piecewise:
$$f ( x ) = \begin{cases}
a, &\text{if }x \leq a \\
x, &\text{if }a \leq x \leq b \\
b, &\text{if }x \geq b.
\end{cases}$$
A: $[a,b]$ is connected because it is path connected. For every $x,y\in [a,b]$ we have $f(t)=(1-t)x+ty$ being a continuous path from $x$ to $y$. 
A: consider the 'nice' function $h(x) = \frac{b+a}{2} + \frac{b-a}{2}\sin x$ on $\mathbb{R}$ which has range $[a,b]$. Clearly $h$ is continuous (infinitely differentiable) and hence $[a,b]$ is connected.
A: You don't need to find a continuous surjective function. You can use the fact:

If $A$ is connected and $A\subset B\subset \overline{A}$ then $B$ is also connected.

It is easy to check that $(a,b)$ is connected and $\overline{(a,b)}=[a,b]$.
A: You don't need to write $[a,b]$ as the image of $\mathbb R$ by a continuous function. You can use the following characterization of connected spaces: $X$ is connected if and only if every continuous map from $X$ into $Y=\{0,1\}$ (with the discrete topology) is constant (*).
Thus, the fact that $[a,b]$ is connected follows from the Intermediate Value Theorem
(*) you can substitute any discrete space to $Y$ in the characterization.
A: Why not prove straight ahead that any interval $J$ is connected?  Recall that $J$ is an interval of $\mathbb R$ iff for all $a,b\in J$ with $a\leq b$ we have $\{x\in\mathbb R\mid a\leq x\leq b\}\subset J$.
If $J$ Is a singleton or empty, we're done.
Assume otherwise there are open, non-empty sets $A$ and $B$ s.t. $J\subset A\cup B$ and $A\cap B=\emptyset$; let $x\in A\cap J$, $y\in B\cap J$ and $x<y$. Define $s:=\sup(A\cap [x,y])$.  Convince yourself that $s\notin A$ and $s\notin B$ as $A$ and $B$ are open.  But $s\in[x,y]\subset J$.
