$C^r$ map between a manifold and $\mathbb{R}$ Let $M$ be a $C^r$ sub-manifold of $\mathbb{R}^n$ and let $f:M \to \mathbb{R}$ be a $C^r$ function.
Prove there exists an open neighborhood $U$ of $M$ in $\mathbb{R}^n$ and a $C^r$ function $g:U \to \mathbb{R}$ such that $g|M = f$.
Does any one know how to prove this?
Also, why is it that we can take $U = \mathbb{R}^n$ when $M$ is a closed subset of $\mathbb{R}^n$? Why can't we take $U = \mathbb{R}^n$ in general?
I'm new to the study of manifolds. Hoping to bone up before attempting a real analysis course.
Here is my attempt at a reasonably understandable solution/proof. I'd be surprised if it was correct but can someone at least tell me if I have the intuition right?
For a $C^r$ manifold $M \subset \mathbb{R}^n$, $f: M \to \mathbb{R}$ is $C^r$ (smooth) if it is smooth at all $x \in M$.
$\Rightarrow$ The derivatives $D^rf(x)$ exist for all $r \in \mathbb{N}$ (this is the definition of a $C^r$ function).
$\Rightarrow$ There is an open neighborhood, $U$, around each $x \in M$.
$\Rightarrow$ And since $f$ is $C^r$, $f$ is smooth for some open $x \in U$
$\Rightarrow$ The existence of $D^rf(x)$ is determined by the restriction of $f$ to any open neighborhood of $x$.
$\Rightarrow$ Their exists a $C^r$ function, $g: U \to \mathbb{R}$, such that $g|U = f$
$\Rightarrow$ When $M$ is open, it suffices to take $M=U$.
 A: Although the tubular nbhd argument of course works, I believe this is more a partitions of unity matter. An important remark: a differentiable function $f:M\to\mathbb R$ with $M\subset\mathbb R^n$ has locally differentiable extensions: every point $x\in M$ has an open nbhd $U^x$ in $\mathbb R^n$ where a differentiable extension $F^x:U^x\to\mathbb R$ of $f$ is defined (the nbhd and the extension depend on $x$). This is in fact one of the equivalent definitions of differentiable function on $M\subset\mathbb R^n$. To connect to tubular nbhds, this local assertion translates into the fact that any function on a linear subspace $L$ of $\mathbb R^n$ extends to $\mathbb R^n$ by composition with a linear projection $\mathbb R^n\to L$ (which is the linear version of the $\nu$ in the tubular ndhd).
Thus the point is to pass from the family of local extensions $F^x$ (which surely do not coincide on the overlappings of their domains $U^x$) to a single global extension $F$ defined on an open nbhd $U$ of $M$.
Now we use a smooth (which covers any differentiability class) partition of unity of the open set $U=\bigcup_xU^x$ subordinated to the covering $\{U^x: x\in M\}$. That partition of unity is a locally finite family of smooth functions $\theta_x:U^x\to [0,1]\subset\mathbb R$ such that $\sum_x\theta_x(y)=1$ for all $y\in U$. Finally the extension $F:U\to\mathbb R$ of $f$ we look for is 
$$
F=\sum_x \theta_xF^x.
$$
This is well defined and smooth because locally it is a finite sum. Furthermore for $y\in M$ we have:
$$
F(y)=\sum_x \theta_x(y)F^x(y)=\sum_x \theta_x(y)f(y)=\big(\sum_x\theta_x(y)\big)f(y)=f(y),
$$
hence $F$ extends $f$.
Sometimes we cannot extend to the whole $\mathbb R^n$. Trivial example: $M=\{t>0\}$ is an open submanifold of $\mathbb R$, and $f(t)=1/t$ does not extend to $0$.
Partitions of unity are the first tool one teaches in any manifolds course, and are needed for most constructions of differentiable objects.
A: For $r \geq 2$, let $\nu$ be a tubular neighborhood of $M$, with $g$ a $C^r$ bundle metric on $\nu$ so that the unit disk bundle with respect to the metric is in contained in $\nu$. Now just define $h: \nu \to \Bbb R$ as $h(x,v)=\phi(g(v,v))f(x)$ where $\phi:\Bbb R^{\geq 0} \to \Bbb R$ is a smooth cutoff function with $\phi(0)=1$ and $\phi(t)=0$ for $t\geq 1$. Extend $h$ to $\Bbb R^n$ by letting it be zero outside of $\nu$.
