TITLE: Rigorous proof of the "Lagrange-multiplier theorem"
QUESTION [6 upvotes]: From Marsden's Elementary Classical Analysis:

Theorem 8
Let $f\colon U \subset \Bbb R^n \to \Bbb R$ and $g\colon U\subset \Bbb R^n \to R$ be given $C^1$ functions. Let $x_0\in U$, $g(x_0)=c_0$ and let $S = g^{-1}(c_0)$ the level set for $g$ with value $c_0$. Assume $\nabla g(x_0)\ne 0$. If $f\restriction S$ has a maximum or minimum at $x$ then there is a real number $\lambda$ such that $$\nabla f(x_0)=\lambda \nabla g(x_0)$$
Proof
The only thing not complete about the sketch of the proof given in Section 7.7 is that we need to know that if $v\perp \nabla g(x_0)$ then $v=c'(0)$ for a $C^1$ curve $c(t)$ in $S$, with $c(0) = x_0$.
This can be established as follows. By Theorem 3 there is a change of coordinates $h$ such that $g(h(x_1,\dots,x_n)) = x_n$. Thus $h^{-1} (S)$ is the coordinate plane $x_n = c_0$. Let $w=Dh^{-1}(x_0)\cdot v$. We claim that the last coordinate of $w$ is zero, that is, $w$ lies in the plane $x_n = c_0$. Indeed let $e_n = (0,0,\dots,1)$. We shall show that $\langle w, e_n \rangle = 0$. But from the chain rule, $g(h(x_1,\dots,x_n))=x_n$ implies $$\langle\nabla g(x_0),Dh(y_0) \cdot w\rangle=\langle w,e_n\rangle$$ where $h(y_0)=x_0$. But the left side is $\langle\nabla g(x_0),v\rangle=0$. Now let $c(t)=h(y_0+tw)$. This lies in $S$, $c(0)=x_0$, and from the chain rule, $c'(0)=v$.
The proof may now be completed as in the text. $\blacksquare$

Two points that I'm having trouble with:
(1) In the seventh line from the last, why does $w$'s last coordinate being zero imply that $w$ lies in the plane $x_n=c_0$? I only naively (erroneously) see that the former implies that $w$ lies in the plane $x_n=0$.
(2) How is the chain rule being used to obtain the equation in the fourth line from the last?

REPLY [6 votes]: Concerning the first point, your mistake is

I only naively (erroneously)

the word in parentheses. You are right, $w$ lies in the plane $x_n = 0$. What the author probably thought of was the straight line through $y_0 = h^{-1}(x_0)$ with direction $w$, which lies in the plane $x_n = c_0$, and thus its image under $h$ is a curve in $S$ whose tangent vector at $x_0$ is $v$.
Regarding the second point, we have $g\circ h = \pi_n$, the projection on the last coordinate, so $\nabla (g\circ h) \equiv e_n$, whence $\langle\nabla (g\circ h)\lvert_{y_0}, w\rangle = \langle e_n,w\rangle$. On the other hand, the chain rule gives
$$D(g\circ h)\lvert_{y_0} = D g\lvert_{x_0} \circ Dh\lvert_{y_0},$$
from which we obtain
$$D(g\circ h)\lvert_{y_0}(w) = Dg\lvert_{x_0} \left(Dh\lvert_{y_0}(w)\right) = \langle \nabla g\lvert_{x_0}, Dh\lvert_{y_0}(w)\rangle,$$
since $\nabla g$ is defined/characterised by
$$\langle \nabla g\lvert_x, u\rangle = Dg\lvert_x (u).$$