You are on page 1of 6

Orbital Mechanics with MATLAB

Keplers Equation
This document describes several MATLAB functions that can be used to solve Keplers equation for
circular, elliptical, parabolic and hyperbolic orbits.
kepler1.m Danbys method
This MATLAB function is based on a numerical solution of Keplers equation devised by Professor J.
M. A. Danby at North Carolina State University. Additional information about this algorithm can be
found in The Solution of Keplers Equation, Celestial Mechanics, 31 (1983) 95-107, 317-328 and 40
(1987) 303-312.
The initial guess for Danby's method is

E0 M 0.85sign sin M e
The fundamental equation we want to solve is

f E E e sin E M 0
which has the first three derivatives given by
f E 1 e cos E
f E e sin E
f E e cos E

The iteration for an updated eccentric anomaly based on a current value En is given by the next four
equations:
f
En
f
f
1
f f
2
f
n En
1
1
f f 2 f
2
6
En 1 En n
En

This algorithm provides quartic convergence of Kepler's equation. This process is repeated until the
following convergence test involving the fundamental equation is satisfied:
f E
page 1

Orbital Mechanics with MATLAB


where is the convergence tolerance. This tolerance is hardwired in the software to = 1.0e-10.
Finally, the true anomaly can be calculated with the following two equations
sin 1 e2 sin E
cos cos E e

and the four quadrant inverse tangent given by

tan 1 sin ,cos


If the orbit is hyperbolic the initial guess is
2M

H 0 log
1.8
e

where H 0 is the hyperbolic anomaly. The fundamental equation and first three derivatives for this case
are as follows:
f H e sinh H H M

f H e cosh H 1
f H e sinh H
f H e cosh H
Otherwise, the iteration loop which calculates , , and so forth is the same. The true anomaly for
hyperbolic orbits is determined with this next set of equations:
sin e2 1sinh H

cos e cosh H

The true anomaly is then determined from a four quadrant inverse tangent evaluation of these two
equations.
The syntax of this MATLAB function is
function [eanom, tanom] = kepler1 (manom, ecc)
% solve Kepler's equation for circular,
% elliptic and hyperbolic orbits
% Danby's method
% input
%
%

manom = mean anomaly (radians)


ecc
= orbital eccentricity (non-dimensional)

page 2

Orbital Mechanics with MATLAB


% output
%
%

eanom = eccentric anomaly (radians)


tanom = true anomaly (radians)

kepler2.m Danbys method with Mikkolas initial guess


This function solves the elliptic and hyperbolic form of Keplers equation using Danbys method and
Mikkolas initial guess. This method uses a cubic approximation of Kepler's equation for the initial
guess. Additional information about this initial guess can be found in A Cubic Approximation For
Keplers Equation, Celestial Mechanics, 40 (1987) 329-334.
The elliptic orbit initial guess for this method is given by the expression
E0 M e 3s 4s3

where
s s1 ds

s1 z

ds

0.078s15
1 e

and

z sign 2 2

1/3

1 e

1
4e
2

1
M
2
1
4e
2

Updates to the eccentric anomaly are calculated using the same set of equations as those in Danby's
method. For hyperbolic orbits this method uses the following for the correction to s
ds

0.071s5
e 1 0.45s 2 1 4 s 2

and the following initial guess for the hyperbolic anomaly:

H 0 3log s 1 s 2

The syntax of this MATLAB function is


function [eanom, tanom] = kepler2 (manom, ecc)
% solve Kepler's equation for circular,
% elliptic and hyperbolic orbits
% Danby's method with Mikkola's initial guess
% input
%

manom = mean anomaly (radians)


page 3

Orbital Mechanics with MATLAB


%

ecc

= orbital eccentricity (non-dimensional)

% output
%
%

eanom = eccentric anomaly (radians)


tanom = true anomaly (radians)

kepler3.m Goodings two iteration method


This MATLAB function solves the elliptic form of Keplers equation using Goodings two iteration
method. This algorithm performs two, and only two iterations when solving Keplers equation.
Additional information about this technique can be found in Procedures For Solving Keplers
Equation, Celestial Mechanics, 38 (1986) 307-334.
The syntax of this MATLAB function is
function [eanom, tanom] = kepler3 (manom, ecc)
% solve Kepler's equation for elliptic orbits
% Gooding's two iteration method
% input
%
%

manom = mean anomaly (radians)


ecc
= orbital eccentricity (non-dimensional)

% output
%
%

eanom = eccentric anomaly (radians)


tanom = true anomaly (radians)

kepler4.m parabolic and near-parabolic orbits


This MATLAB function solves Keplers equation for heliocentric parabolic and near-parabolic orbits. It
is based on the numerical method described in Chapter 4 of Astronomy on the Personal Computer by
Oliver Montenbruck and Thomas Pfleger. This algorithm uses a modified form of Barkers equation
and Stumpff functions to solve this problem.
The form of Keplers equation solved by this function is

E t e sin E t
where

a3

t t0

E eccentric anomaly
e orbital eccentricity

gravitational constant of the Sun


a semimajor axis
t time
t0 time of perihelion passage
page 4

Orbital Mechanics with MATLAB


The relationship between semimajor axis a and perihelion radius q is as follows:
a

q
1 e

By introducing the variable


3ec3 E
E
1 e

Keplers equation is now given by


1

U U 3 6ec3 E
t t0
3
2q3

where c3 E E e sin E E 3 . The kepler4 function iteratively solves for U.


The heliocentric distance is determined from the expression
2c
r q 1 2 U 2
6c3

The true anomaly is determined from the x and y components of the heliocentric position vector as
follows:
tan-1 y, x
where
2c
x q 1 2 U 2
6ec3
y 2q

1 e 1
c1U
2e 6c3

The true anomaly can also be determined from


1 e c2
tan
U
2 3ec3 c1

The c functions used in these equations are called Stumpff functions. They are named after the German
astronomer Karl Stumpff and defined by the series
1 x k

cn x
k 0 2k n !

page 5

k 0,1,2,

Orbital Mechanics with MATLAB


For x real and x 0 , the first few terms are given by the following expressions:
c0 x 2 cos x

c0 x 2 cosh x

c1 x 2

c1 x 2

sin x
x
1 cos x
c2 x 2
x

sinh x
x
cosh x 1
c2 x 2
x

The Stumpff functions also satisfy the recursion relationship defined by


xck 2 x

1
ck x
k!

k 0,1,2,

For x 0 ,

cn x

1
n!

It is most efficient to compute c2 and c3 by series and then compute c0 and c1 by recursion according to
the following:
c0 x 1 xc2
c1 x 1 xc3

The syntax of this MATLAB function is


function [r, tanom] = kepler4(t, q, ecc)
% Kepler's equation for heliocentric
% parabolic and near-parabolic orbits
% input
%
%
%

t
= time relative to perihelion passage (days)
q
= perihelion radius (AU)
ecc = orbital eccentricity (non-dimensional)

% output
%
%

r
= heliocentric distance (AU)
tanom = true anomaly (radians)

page 6

You might also like