I know this question is related to partitions of unity, but we never actually discussed these in class.
Suppose $M$ is an abstract smooth manifold, $K \subset U \subset M$ an inclusion of a compact subset into an open subset. Suppose we have a smooth function $f: U \to \mathbb{R}^k$. Show that there exists a smooth function $g: M \to \mathbb{R}^k$ such that $f \big|_K = g \big|_K$ and $g \big|_{M \setminus U} =0$.
My proof is incredibly confusing ( and definitely not correct). I am asking for the basic outline as to how to think about this problem.
$\textbf{My Attempt:}$
For each $p \in U$, let $\left ( \phi_p, V_p \right)$ be a coordinate chart, $$\phi_p: V_p \to V_p' \subset \mathbb{R}^m$$ where $V_p'$ open. Consider, $$ \bigcup_{p \in U} \phi_p(V_p) = \bigcup_{p \in U} V_p'$$ an open subset of $\mathbb{R}^m$. Given $K$ compact we have that there exists a finite subcover such that, $$ \bigcup_{i=1}^N \phi_{p_i}^{-1} \left ( V_{p_i}' \right) = \bigcup_{i=1}^{N} V_{p_i} \supset K$$
Let $$A:= \{ V_{p_i}' : \phi_{p_i}^{-1} \left ( V_{p_i}' \right) \subset K \}$$ set elements of $A$ aside for the time being. $$B := \{ V_{p_i}' : \phi_{p_i}^{-1} \left (V_{p_i}' \right ) \cap K = \emptyset \}$$ immediately throw all elements of $B$ back in to $\bigcup_{p \in U} V_p '$, we don't really care about these superfluous elements of the subcover.
$$ C:= \{ V_{p_i}' : \phi_{p_i}^{-1} \left ( V_{p_i}' \right) \cap K \neq \emptyset, \hspace{2mm} \phi_{p_i}^{-1} \left (V_{p_i}' \right) \not \subset K \}$$
For each $V_{p_i}' \in C$, let $$W_{p_i} = \phi_{p_i}^{-1} \left ( V_{p_i}' \right ) \cap K$$ Recall the smooth function $$\psi(x) = \begin{cases} e^{-\frac{1}{x^2}}, & \text{if} |x| > 0 \\ 0, & \text{otherwise} \end{cases}$$ and $$ g(x) = \begin{cases} \psi(x-1) \psi(x+1), & \text{if} \hspace{2mm} |x| <1 \\ 0, & \text{otherwise} \end{cases} $$We now define a family of smooth function, $h_i(x) : M \to \mathbb{R}$, as follows,
$$h_i(x) = \begin{cases} 0, & \text{if} \hspace{2mm} x \in \phi_{p_i}^{-1} \left ((A \cup C )^c \right) \\ 1, & \text{if} \hspace{2mm} x \in W_{p_i} \cup A \\ \frac{ \int_{- \infty}^{x} g(t) dt}{\int_{- \infty}^{\infty} g(t) dt}, & \text{if} \hspace{2mm} x \in \hspace{2mm} W_{p_i}^c \cap V_{p_i} \end{cases}$$ \n
Let $\Psi(x) = \sum_{i=1}^{N} h_i(x)$. That $\Phi(x): M \to \mathbb{R}^k$ is smooth follows immediately from it being the finite sum of the smooth functions, $h_i(x)$.
To account for the points which may lie in intersections let, $$ g_i(x) = \frac{ h_i(x)} { \Psi(x)}$$ and then let $\Phi(x) = \sum_{i=1}^N g_i(x)$. Now let, $$k(x) = \begin{cases} 0, & \text{if} \hspace{2mm} x = 0 \\ 1, & \text{if} \hspace{2mm} x \ge 1 \\ 0 < k(x) < 1, & \text{if} \hspace{2mm} x \in (0,1) \end{cases}$$
We know such a smooth function exists. Then, $ ( k \circ \Phi) (x)$ is a smooth function. We conclude that $g(x)= f(x) \cdot (k \circ \Phi)(x)$ is our desired smooth function.
Your argument somehow tries to put together in the same proof a bunch of different facts that are better treated separatedly. And maybe they could do the job, but looks a bit messy. I would suggest this, which also shows that compactness is not necessary.
1) Bump functions. For any two disjoint closed set $F,E\subset M$ there is a smooth function $\varphi:M\to\mathbb R$ that is $\equiv1$ on $F$ and $\equiv0$ on $E$. For instance use a partition of unity $\{\varphi,\psi\}$ subordinated to the cover $\{M\setminus E, M\setminus F\}$. Here one can mention the opposite approach: using charts in the spirit of your proposal, one produces bump functions, and with them gets partitions of unity.
2) Extension by $0$. Let $C$ be a closed subset of $M$ and $f:U\to\mathbb R$ a smooth function defined on an open nbhd $U$ of $C$. To start with pick a smaller open nbhd $V$ of $C$ with closure $\overline V\subset U$ ($M$ is a normal space). Then $C\cap(M\setminus V)=\varnothing$ and we pick a bump function $\varphi:M\to\mathbb R$ which vanishes on the closed set $M\setminus V$ and is $\equiv1$ on $C$. In this situation $$ \widetilde f=\begin{cases}\varphi\cdot f&\text{on $U$,}\\ 0&\text{on $M\setminus\overline V$.}\end{cases} $$ is a well defined smooth function on $M$, since (i) the open sets $U$ and $M\setminus\overline V$ cover $M$ and (ii) $\varphi$ vanishes on their intersection $U\cap(M\setminus\overline V)\subset M\setminus V$. Finally, as $\varphi\equiv1$ on $C$, $\widetilde f=f$ on $C$. $\square$
This can be improved: take another smaller open nbhd $W$ of $C$ with $\overline W\subset V$, and choose the bump function $\equiv1$ on $\overline W$ instead of $C$. Then the extension $\widetilde f$ coincides with $f$ not just on $C$, but on a nbhd of $C$.