I have a system of four coordinates and four momenta (conjugates of coordinates).
I have a metric tensor $g_{ik}$ and I know the Hamiltonian:
$H(p,q,t)=\frac{1}{2}g^{ik}(q)p_ip_k$
For my current case, I have the Schwartzschild metric:
$ds^2=(1-r_s/r)dt^2-\frac{1}{1-r_s/r}dr^2-r^2d\theta^2-r^2sin^2(\theta)d\phi^2$
Meaning, the Hamiltonian is:
$H=\frac{1}{2}[\frac{1}{1-r_s/r}p_t^2-(1-r_s/r)p_r^2-\frac{1}{r^2}p_\theta^2-\frac{1}{r^2sin^2(\theta)}p_\phi^2]$
As Mathematica code with $r_s = 1$,
h = 1/2 (1/(1 - 1/r) pt^2 - (1 - 1/r) pr^2 - 1/r^2 pθ^2 - 1/(r^2 Sin[θ]^2) pϕ)
The equations of motion by Hamilton's equations are:
$dt/d\tau=\frac{\partial H}{\partial p_t};$
$dr/d\tau=\frac{\partial H}{\partial p_r};$
$d\theta/d\tau=\frac{\partial H}{\partial p_\theta};$
$d\phi/d\tau=\frac{\partial H}{\partial p_\phi};$
$dp_t/d\tau=-\frac{\partial H}{\partial t};$
$dp_r/d\tau=-\frac{\partial H}{\partial r};$
$dp_\theta/d\tau=-\frac{\partial H}{\partial \theta};$
$dp_\phi/d\tau=-\frac{\partial H}{\partial \phi};$
And I want to solve these equations of motion. I've tried deriving the expressions for each partial derivatives of $H$ and then substituting them in these equations manually. However, is there any way to do this dynamically?
What I mean is: suppose, we've only got the expression of Hamiltonian:
$H=H(p_t,p_r,p_\theta,p_\phi,t,r,\theta,\phi)$
And I want to dynamically derive all the partial derivatives and construct system of 8 (in this case) first-order differential equations and then solve them with NDSolve[]
. So, that next time, when I want to try something else, all I have to change is the Hamiltonian.
P.s.: I've tried lots of things, like using Function[]
for Hamiltonian and throwing variables back and forth, but with no effective result.
NDSolve
? (Or maybeDSolve
?) If it's a separable Hamiltonian system (I didn't check), there are special integration methods available. See reference.wolfram.com/language/tutorial/NDSolveSplitting.html. $\endgroup$NDSolve[]
this whole time. My problem is, I can't differentiate $H$ partially so that it's analytic.Mathematica
can't seem to understand that the variables of result functions (partial derivatives) are by themselves functions of $\tau$ and I don't know how to make it understand. $\endgroup$