It is subtle. If you write y'
for the velocity, then
In[35]:= D[y', y]
Out[35]= 0 &
because the internal form of y'
is Derivative[1][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]