$\mathbf{f}:M\to\mathbb{R^n}$ continuous iff the inverse image of all closed subsets of $\mathbb{R^m}$ under f is closed subset of $\mathbb{R^n}$ I am preparing for my exam and therefore am practicing by doing some exercises. I need help with the following one.

Let M be nonempty, closed subsets of $\mathbb{R^n}$ and $\mathbf{f}:M\to\mathbb{R^m}$: Show $\mathbf{f}:M\to\mathbb{R^m}$ is continuous if and only for every closed subset S of $\mathbb{R^m}$, $\mathbf{f}^{-1}[S]$ is a closed subset of $\mathbb{R^n}.$

I already proved this: Let M be nonempty, open subsets of $\mathbb{R^n}$ and $\mathbf{f}:M\to\mathbb{R^m}$: Show $\mathbf{f}:M\to\mathbb{R^m}$ is continuous if and only for every open subset S of $\mathbb{R^m}$, $\mathbf{f}^{-1}[S]$ is an open subset of $\mathbb{R^n}.$
And I wanted to use it for this task. But I guess its only working if we are working with $\mathbf{f}:\mathbb{R^n}\to\mathbb{R^m}$. Here we are working with a subset $M\subseteq\mathbb{R^n}$.
This is what I have: Since S is closed, $\mathbb{R^m}$\S is open. Thus $\mathbf{f}^{-1}$[$\mathbb{R^m}$\S] is open.
And here is the problem... if we would have $\mathbf{f}:\mathbb{R^n}\to\mathbb{R^m}$, we would have $\mathbf{f}^{-1}$[$\mathbb{R^m}$\S]=$\mathbb{R^n}$\ $\mathbf{f}^{-1}[S]$ is open and thus the complement $\mathbf{f}^{-1}[S]$ is closed.
But our domain is not $\mathbb{R^n}$ instead we have the subset M. Thats why $\mathbf{f}^{-1}$[$\mathbb{R^m}$\S]=M\ $\mathbf{f}^{-1}[S]$ and $\mathbf{f}^{-1}$[$\mathbb{R^m}$\S]$\neq$$\mathbb{R^n}$\ $\mathbf{f}^{-1}[S]$. So I thought I could do this. Since $M$\ $\mathbf{f}^{-1}[S]$ is open, the complement $M^c\cup$$\mathbf{f}^{-1}[S]$ is closed. We know $M^c$ is open. Thats why $\mathbf{f}^{-1}[S]$ can't be open because the union would be open then. I thought I got it know and I could say that the inverse image is closed. But no... the inverse image could be neither open nor closed...right?
Thats why I am stuck now. Is there even a possibility to prove it like that. Or does the fact that we are working with a subset of $\mathbb{R^n}$ destroy the possibility of concluding the lemma from my previous proof with open sets.
Is there anyone who could help me out? I would be very grateful.
 A: This is not really an answer, but it's far too long for a comment. I thought I'd just flesh out what I was talking about in the comments.
Your observation that these concepts should be connected is astute, but the two problems are unfortunately too limited to be actually equivalent. As I said in the comments, there is a more general form which makes this equivalence plain (and the proof is what you outlined above, with some trivial adjustments). Given $f : M \subseteq \Bbb{R}^n \to \Bbb{R}^m$, then the following are true:


*

*$f$ is continuous if and only if, given any open $S \subseteq \Bbb{R}^m$, the set $f^{-1}[S]$ is open in $M$, meaning that there exists some open set $U \subseteq \Bbb{R}^n$ such that $f^{-1}[S] = U \cap M$, and

*$f$ is continuous if and only if, given any closed $S \subseteq \Bbb{R}^m$, the set $f^{-1}[S]$ is closed in $M$, meaning that there exists some closed set $C \subseteq \Bbb{R}^n$ such that $f^{-1}[S] = C \cap M$.


Note: these generalise the problems at hand. If $M$ is open, then $U \cap M$ is also open. If $M$ is closed, then $C \cap M$ is also closed. But, these statements also hold without additional assumptions on $M$.
Also, we can easily show 1 and 2 are equivalent with a proof similar to what you've written. Indeed, the closed and open properties are easily seen to be equivalent.

If $f$ has the open property and $S \subseteq \Bbb{R}^m$ is closed, then $T = \Bbb{R}^m \setminus S$ is open. Therefore, $f^{-1}[T]$ is open in $M$, i.e. some $U \subseteq \Bbb{R}^n$ exists such that $f^{-1}[T] = U \cap M$. Thus,
\begin{align*}
f^{-1}[S] &= f^{-1}[\Bbb{R}^m \setminus T] = M \setminus f^{-1}[T] \\
&= M \setminus (U \cap M) = M \setminus U = M \cap (\Bbb{R}^n \setminus U).
\end{align*}
Note that $\Bbb{R}^n \setminus U$ is closed, as $U$ is open, proving $f^{-1}[S]$ is closed in $M$.

The converse follows similarly: just swap the words "closed" and "open" in the above proof. To prove 1, the proof will be (I imagine) very similar to whatever the solution was to your previous exercise:

Suppose $f$ is continuous, $U \subseteq \Bbb{R}^m$ is open, and $x \in f^{-1}[U]$. Then $y := f(x) \in U$, which is open, so a ball of some radius $\varepsilon_x > 0$, centred at $y$, exists inside $U$ (which we'll denote $B(y; \varepsilon_x)$). Using continuity, there is some $\delta_x > 0$ such that
$$\|z - x\| < \delta_x \text{ and } z \in M \implies \|f(z) - f(x)\| < \varepsilon_x.$$
Put another way,
$$B(x; \delta_x) \cap M \subseteq f^{-1}[B(y; \varepsilon_x)] \subseteq f^{-1}[U].$$
So, performing this for each $x \in f^{-1}[U]$,
$$\left(\bigcup_{x \in f^{-1}[U]} B(x; \delta_x)\right) \cap M = \bigcup_{x \in f^{-1}[U]} (B(x; \delta_x) \cap M) \subseteq f^{-1}[U].$$
But, each $x \in f^{-1}[U]$ clearly lies in the left hand side (note: $f^{-1}[U] \subseteq M$), so the $\subseteq$ is, in fact, $=$. The union of the balls is open, so we have shown $f^{-1}[U]$ is open in $M$.
Conversely, suppose $f$ has the open set property. Fix $\varepsilon > 0$ and $x_0 \in M$. Let $S = B(f(x_0); \varepsilon)$, which is an open set in $\Bbb{R}^m$. Then $f(x) \in S \implies x \in f^{-1}[S]$. The latter is open in $M$, so there exists some open $U \subseteq \Bbb{R}^n$ such that $x \in f^{-1}[S] = M \cap U$. As $U$ is open, some $\delta > 0$ exists such that $B(x; \delta) \subseteq U$. Thus,
$$B(x; \delta) \cap M \subseteq M \cap U = f^{-1}[S]$$
Thus,
$$\|z - x\| < \delta \text{ and } z \in M \implies f(z) \in S = B(f(x); \varepsilon) \implies \|f(z) - f(x)\| < \varepsilon,$$
proving continuity.

A note: these characterisations of continuity are the definitions of continuity in terms of topology. The terms "open/closed in $M$" are the meaning of open/closed in the subspace topology of $M$ in $\Bbb{R}^n$.
A: Now for an actual answer! As I said in the comments, I would abandon the other exercise, for it's not quite powerful enough to help you, and instead try to prove this with sequential continuity. That is, we will assume that:

$f : M \subseteq \Bbb{R}^n \to \Bbb{R}^m$ is continuous if and only if, given any $(x_n)_{n=1}^\infty \in M$ that converges to $x \in M$, we have $f(x_n) \to f(x)$ in $\Bbb{R}^m$.

Now, let's suppose that $f$ is (sequentially) continuous, and $S \subseteq \Bbb{R}^m$ is closed. Further, take $(x_n) \in f^{-1}[S]$, converging to some $x \in \Bbb{R}^n$. We wish to show $x \in f^{-1}[S]$.
Since $f^{-1}[S] \subseteq M$, which is closed, we conclude that $x \in M$, so at least $f(x)$ makes sense. By sequential continuity, we know that $f(x_n) \to f(x)$. As $(x_n) \in f^{-1}[S]$, we have $f(x_n) \in S$. Since $S$ is closed, the limit $f(x)$ must also lie in $S$, which means that $x \in f^{-1}[S]$. This proves $f^{-1}[S]$ is closed, as required.
Inversely, suppose $f$ is not continuous. Then, some $(x_n) \in M$ exists, converging to $x \in M$, so that $f(x_n) \not\to f(x)$. We know that a subsequence of $(f(x_n))$ lies some positive distance $\varepsilon$ from $f(x)$. So, by replacing $x_n$ with this subsequence, assume without loss of generality that $\|f(x_n) - f(x)\| > \varepsilon$ for all $n$.
Let $S$ be the closure of the set $\{f(x_n) : n \in \Bbb{N}\}$. As $f(x)$ lies $\varepsilon > 0$ distance from all points in this set, we have $f(x) \notin S$, hence $x \notin f^{-1}[S]$. However, each $x_n$ lies in $f^{-1}[S]$, and the sequence converges to $x$, proving that $f^{-1}[S]$ is not closed. Thus, $f$ does not have the closed set property, completing the proof.
