From e77e0ba0beeaadcb14000bf93a0fcdc948711db2 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Sun, 16 Nov 2025 19:51:14 -0500 Subject: [PATCH] Fix Hamiltonian form in Kepler problem example The Hamiltonian at any point should not depend on the generalized velocity, but instead the momentum. For this problem it doesn't make as much difference, but users can get confused about the equations of motion if the Hamiltonian already includes the generalized velocities. --- docs/src/examples/kepler_problem.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/src/examples/kepler_problem.md b/docs/src/examples/kepler_problem.md index e24992832..edefaf7b9 100644 --- a/docs/src/examples/kepler_problem.md +++ b/docs/src/examples/kepler_problem.md @@ -1,13 +1,22 @@ # The Kepler Problem -The Hamiltonian $\mathcal {H}$ and the angular momentum $L$ for the Kepler problem are +The (non-dimensional) Hamiltonian $\mathcal {H}$ and the angular momentum $L$ for the Kepler problem are -$$\mathcal {H} = \frac{1}{2}(\dot{q}^2_1+\dot{q}^2_2)-\frac{1}{\sqrt{q^2_1+q^2_2}},\quad -L = q_1\dot{q_2} - \dot{q_1}q_2$$ +```math +\begin{align*} +\mathcal{H}(q_1, p_1, q_2, p_2) &= \frac{1}{2}(p^2_1+p^2_2)-\frac{1}{\sqrt{q^2_1+q^2_2}}, \\ +L &= q_1 p_2 - p_1 q_2 +\end{align*} +``` Also, we know that -$${\displaystyle {\frac {\mathrm {d} {\boldsymbol {p}}}{\mathrm {d} t}}=-{\frac {\partial {\mathcal {H}}}{\partial {\boldsymbol {q}}}}\quad ,\quad {\frac {\mathrm {d} {\boldsymbol {q}}}{\mathrm {d} t}}=+{\frac {\partial {\mathcal {H}}}{\partial {\boldsymbol {p}}}}}$$ +```math +\begin{align*} +\frac{\mathrm{d} \boldsymbol{p}}{\mathrm{d} t} &= - \frac {\partial \mathcal{H}}{\partial \boldsymbol{q}} , \\ +\frac{\mathrm{d} \boldsymbol{q}}{\mathrm{d} t} &= + \frac {\partial \mathcal{H}}{\partial \boldsymbol{p}} +\end{align*} +``` ```@example kepler import OrdinaryDiffEq as ODE, LinearAlgebra, ForwardDiff, NonlinearSolve as NLS, Plots