# Universal variable formulation

In orbital mechanics, the universal variable formulation is a method used to solve the two-body Kepler problem. It is a generalized form of Kepler's Equation, extending it to apply not only to elliptic orbits, but also parabolic and hyperbolic orbits common for spacecraft departing from a planetary orbit. It is also applicable to ejection of small bodies in Solar System from the vicinity of massive planets, during which processes the approximating two-body orbits can have widely varying eccentricities, almost always   e ≥ 1 .

## Introduction

A common problem in orbital mechanics is the following: Given a body in an orbit and a fixed original time $\ t_{\mathsf {o}}\ ,$ find the position of the body at some later time $\ t~.$ For elliptical orbits with a reasonably small eccentricity, solving Kepler's Equation by methods like Newton's method gives excellent results. However, as the orbit approaches an escape trajectory, it becomes more and more eccentric, convergence of numerical iteration may become unusably sluggish, or fail to converge at all for   e ≥ 1 .
Note that the conventional form of Kepler's equation cannot be applied to parabolic and hyperbolic orbits without special adaptions, to accommodate imaginary numbers, since its ordinary form is specifically tailored to sines and cosines; escape trajectories instead use  sinh  and  cosh  (hyperbolic functions).

## Derivation

Although equations similar to Kepler's equation can be derived for parabolic and hyperbolic orbits, it is more convenient to introduce a new independent variable to take the place of the eccentric anomaly $\ E\ ,$ and having a single equation that can be solved regardless of the eccentricity of the orbit. The new variable $\ s\$ is defined by the following differential equation:
    ${\frac {\operatorname {d} s}{\ \operatorname {d} t\ }}={\frac {\ 1\ }{r}}$
    where $\ r\equiv r(t)\$ is the time-dependent scalar distance to the center of attraction.
(In all of the following formulas, carefully note the distinction between scalars $\ r\ ,$ in italics, and vectors $\ \mathbf {r} \ ,$ in upright bold.)
We can regularize the fundamental equation
    $\ {\frac {\ \operatorname {d} ^{2}\mathbf {r} \ }{\ \operatorname {d} t^{2}\ }}+\mu {\frac {\ \mathbf {r} \ }{~r^{3}\ }}=\mathbf {0} \ ,\quad$
    where $~~\mu \equiv G\left(m_{1}+m_{2}\right)~~$ is the system gravitational scaling constant,
by applying the change of variable from time $\ t\$ to $\ s\$ which yields
    ${\frac {\ \operatorname {d} ^{2}\mathbf {r} \ }{~\operatorname {d} s^{2}\ }}+\alpha \ \mathbf {r} =-\mathbf {P} \$
where $\ \mathbf {P} \$ is some t.b.d. constant vector and : $\ \alpha \$ is the orbital energy, defined by
       $\alpha \equiv {\frac {\ \mu \ }{a}}~.$
The equation is the same as the equation for the harmonic oscillator, a well-known equation in both physics and mathematics, however, the unknown constant vector is somewhat inconvenient. Taking the derivative again, we eliminate the constant vector $\ \mathbf {P} \ ,$ at the price of getting a third-degree differential equation:
    $\ {\frac {\ \operatorname {d} ^{3}\mathbf {r} \ }{~\operatorname {d} s^{3}\ }}+\alpha {\frac {\ \operatorname {d} \mathbf {r} \ }{\ \operatorname {d} s\ }}=\mathbf {0} \$
The family of solutions to this differential equation are for convenience written symbolically in terms of the three functions $\ s\ c_{1}\!\!\left(\ \alpha s^{2}\ \right)\ ,\$ $\ s^{2}c_{2}\!\!\left(\ \alpha s^{2}\ \right)\ ,$ and $\ s^{3}c_{3}\!\!\left(\ \alpha s^{2}\ \right)\ ;\$ where the functions $\ c_{k}\!(x)\ ,$ called Stumpff functions, which are truncated generalizations of sine and cosine series. The change-of-variable equation $\ {\tfrac {\operatorname {d} t}{\ \operatorname {d} s\ }}=r\$ gives the scalar integral equation
       $\ \int _{{\tilde {t}}=t_{\mathsf {o}}}^{t}\operatorname {d} {\tilde {t}}=\int _{{\tilde {r}}=r_{\mathsf {o}},\ {\tilde {s}}=0}^{r,\ s}~{\tilde {r}}(\ {\tilde {s}}\ )~\operatorname {d} {\tilde {s}}~.$
After extensive algebra and back-substitutions, its solution results in$^{:Eq.6.9.26}$
    $\ t-t_{\mathsf {o}}=r_{\mathsf {o}}\ s\ c_{1}\!\!\left(\ \alpha s^{2}\ \right)+r_{\mathsf {o}}{\frac {~\operatorname {d} r_{\mathsf {o}}\ }{\ \operatorname {d} t\ }}\ s^{2}c_{2}\!\!\left(\ \alpha s^{2}\ \right)+\mu \ s^{3}c_{3}\!\!\left(\ \alpha s^{2}\ \right)\$
which is the universal variable formulation of Kepler's equation.
There is no closed analytic solution, but this universal variable form of Kepler's equation can be solved numerically for $\ s\ ,$ using a root-finding algorithm such as Newton's method or Laguerre's method for a given time $\ t\ ~.$ The value of $\ s\$ so-obtained is then used in turn to compute the $\ f\$ and $\ g\$ functions and the $\ {\dot {f}}\$ and $\ {\dot {g}}\$ functions needed to find the current position and velocity:
    ${\begin{aligned}\ f(s)&=1-\left({\frac {\ \mu \ }{~r_{\mathsf {o}}\ }}\right)s^{2}c_{2}\!\!\left(\ \alpha s^{2}\ \right)\ ,\\[1.5ex]\ g(s)&=t-t_{\mathsf {o}}-\mu \ s^{3}c_{3}\!\!\left(\ \alpha s^{2}\ \right)\ ,\\[1.5ex]\ {\dot {f}}(s)\equiv {\frac {\ \operatorname {d} f\ }{\ \operatorname {d} t\ }}&=-\left({\frac {\ \mu \ }{\ r_{\mathsf {o}}r\ }}\right)s\ c_{1}\!\!\left(\ \alpha s^{2}\ \right)\ ,\\[1.5ex]\ {\dot {g}}(s)\equiv {\frac {\ \operatorname {d} g\ }{\ \operatorname {d} t\ }}&=1-\left({\frac {\ \mu \ }{r}}\right)\ s^{2}c_{2}\!\!\left(\ \alpha s^{2}\ \right)~.\\[-1ex]\end{aligned}}$
The values of the $\ f\$ and $\ g\$ functions determine the position of the body at the time $\ t\$:
    $\ \mathbf {r} (t)=\mathbf {r} _{\mathsf {o}}\ f(s)+\mathbf {v} _{\mathsf {o}}\ g(s)\$
In addition the velocity of the body at time $\ t\$ can be found using $\ {\dot {f}}(s)\$ and $\ {\dot {g}}(s)\$ as follows:
    $\ \mathbf {v} (t)=\mathbf {r} _{\mathsf {o}}\ {\dot {f}}(s)+\mathbf {v} _{\mathsf {o}}\ {\dot {g}}(s)\$
    where $\ \mathbf {r} (t)\$ and $\ \mathbf {v} (t)\$ are respectively the position and velocity vectors at time $\ t\ ,$ and $\ \mathbf {r} _{\mathsf {o}}\$ and
       $\ \mathbf {v} _{\mathsf {o}}\$ are the position and velocity at arbitrary initial time $\ t_{\mathsf {o}}~.$