How to calculate the period of a nonlinear Diff Eq? I have this Diff Eq:
$$2g''+g'^{2}+ag+a-b=0
 $$
We can manipulate this into an equivalent relation:
$$g'^{2}=ce^{-g}-ag+b $$
...which makes c a conserved quantity:
$$c=\left(g'^{2}+ag-b\right)e^{g}$$
If $sign(a)=-sign(c)
 $ and $|c|<|b-a|e^{\frac{b-a}{a}}
 $ then g will be periodic. This can be verified by plotting $y=ce^{-g}
 $ and $y=ag-b
 $ and noting exactly two points of intersection at which $g'=0
 $ in Eq(2) 
So my question is, what's the best way to calculate the period of g?
Obviously I could iteratively calculate g(x) from initial conditions, but I doubt that's the best approach because of the accumulating numerical errors. Also, it's calculating a lot of intermediate information that I don't need. 
Is there any clever way to numerically calculate the period directly?
 A: As already noted, this equation preserves the quantity $e^g(g'^2+ag-b)$. So it is worth trying to formulate the problem as Hamilton's equations for this Hamiltonian in some system of coordinates. The coordinates cannot be $(p,q)=(g',g)$ as they would often be, so we have to try something else. If we try to keep $p=g'$, we have $\frac{\partial H}{\partial p}=2e^g g'$ which must be the same as $q'$ for Hamilton's equations. Thus we can take $q=2e^g$. We can now reformulate the equation as the Hamilton's equations for the Hamiltonian
$$H(p,q)=\frac{q}{2} \left ( p^2+a\ln(q/2)-b \right ).$$
These equations are
$$q'=\frac{\partial H}{\partial p}=pq \\
p'=-\frac{\partial H}{\partial q}=-\frac{1}{2} \left ( p^2+a \ln(q/2)-b \right ) - \frac{a}{2}.$$
This will be periodic provided $q$ never reaches zero or $+\infty$ (These would correspond to $g$ blowing up in finite time.)  One can estimate the period by using a symplectic integrator on these equations. The numerical solution from this integrator will preserve a perturbed Hamiltonian, and therefore should give a good estimate of the period when the original system is periodic.
