Please see attached notebook detailing confusion taking the partial derivative of y' with respect to y. In my way of thinking (which may be wrong) y' and y are totally different and therefore y' should be considered a constant when taking the partial derivative with respect to y.
Granted this could be a case of simply me not understanding how to properly use Mathematica, but though I would run it past you experts for your advice.
D[1/2 m (y'[t])^2 - m g y[t], y[t]]
(* -g m *)
D[1/2*m *(y'[t])^2 - m *g *y[t], y'[t]]
D[1/2*m *(v)^2 - m *g *x, v] /. v -> y'[t] /. x -> y[t]
It is subtle. If you write y' for the velocity, then
In:= D[y', y]
Out= 0 &
because the internal form of y' is Derivative[y], which does contain y. My advice is either to introduce the time variable throughout
D[1/2 m (y'[t])^2 - m g y[t], y'[t]]
or to make a single symbol for the time derivative:
D[1/2 m (yPrime)^2 - m g y, yPrime]
As for the Lagrange equation, here is a way to get it:
L = 1/2 m (y'[t])^2 - m g y[t];
D[L, y[t]] - D[D[L, y'[t]], t]