I have a Hamiltonian system: r’=f(r,p), p’=g(r,p}. I ask for r(t), p(t).
From energy conservation I know the limits for r.
The solution for r(t) I get is correct for the beginning t’s, but then runs off slowly to very large values.
I have a solution from Matlab a colleague sent, which shows the correct oscillating behaviour in the correct limits for r(t).
I checked my input, seems all fine.
Any ideas?
Thanks
I attach the program and the solution from Matlab.
Nice elegant answer, but when I plotted your solution, the plot was coming out in reverse to Matlab. I needed to reverse the signs of the r and p equations. Do you think the signs should be reversed?
There appears to be a discrepancy between your momentum equation and Gianluca’s. We can check the equivalence by comparing the Right Hand Sides (RHS) of the position and momentum equations your and Gianluca’s approach. If they are equivalent, FullSimplify should evaluate to “True”. As the following code demonstrates, this does not apply to the momentum equation.