If you aim to exclude the derivative, try this:
1/2 k q[t]^2 + Derivative[1][q][t] (m Derivative[1][q][t] + y q[t]) -
1/2 m Derivative[1][q][t]^2 - y q[t] Derivative[1][q][t] /.
q'[t] -> p/m - y/m*q[t] // Simplify
(* (p^2 - 2 p y q[t] + (k m + y^2) q[t]^2)/(2 m) *)
If, on the other hand, you aim to exclude the q[t], try this:
1/2 k q[t]^2 + Derivative[1][q][t] (m Derivative[1][q][t] + y q[t]) -
1/2 m Derivative[1][q][t]^2 - y q[t] Derivative[1][q][t] /.
q -> (p - y/m*q'[#] &) // Simplify
(* (k m^2 p^2 - 2 k m p y Derivative[1][q][t] +
k y^2 Derivative[1][q][t]^2 + m y^2 (q^\[Prime]\[Prime])[t]^2)/(2 m^2) *)
Have fun!
H /. q'[t] -> (p - y q[t])/m? But I'm not sure what is the final goal. – Kuba Feb 19 '15 at 12:121/2 (k q[t]^2 + m Derivative[1][q][t]^2)– ame_math Feb 19 '15 at 14:091/2 k q[t]^2 + Derivative[1][q][t] (m Derivative[1][q][t] + y q[t]) - 1/2 m Derivative[1][q][t]^2 - y q[t] Derivative[1][q][t] /. q'[t] -> (p - y q[t])/m– Kuba Feb 19 '15 at 14:18p := D[L, {Derivative[1][q][t]}]– ame_math Feb 19 '15 at 14:22