# Variable change

If I have the following Hamiltonian:

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]


and I have for p:

p = y q[t] + m Derivative[1][q][t]


How can I substitute p in order to eliminate q'[t]?

• H /. q'[t] -> (p - y q[t])/m? But I'm not sure what is the final goal. – Kuba Feb 19 '15 at 12:12
• See a closely related problem encountered when one deals with systems of differential equations Working with a system of differential equations that cannot be solved explicitly – Artes Feb 19 '15 at 12:56
• I tried but it gaves me: 1/2 (k q[t]^2 + m Derivative[1][q][t]^2) – ame_math Feb 19 '15 at 14:09
• 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 - y q[t])/m – Kuba Feb 19 '15 at 14:18
• Thank you, I solved. It didn't work because I previously defined p as: p := D[L, {Derivative[1][q][t]}] – ame_math Feb 19 '15 at 14:22

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!

• @Kuba It should – Alexei Boulbitch Feb 19 '15 at 13:53