Celestial Computing With MATLAB
Celestial Computing With MATLAB
with MATLAB
INTRODUCTION ....................................................................................................... 7
zvcurve1.m – graphics display of zero velocity curves through equilibrium points ..................................... 49
Page 1
Celestial Computing with MATLAB
Page 2
Celestial Computing with MATLAB
jd2str.m – julian date to calendar date and universal time strings .............................................................. 101
utc2tdt.m – convert UTC Julian date to TDT Julian date ............................................................................ 102
tdt2tdb.m – convert TDT Julian date to TDB Julian date ............................................................................ 102
Page 3
Celestial Computing with MATLAB
oepreces.m – transform angular orbital elements from one equinox to another ........................................ 124
Page 4
Celestial Computing with MATLAB
geodet1.m – convert geocentric coordinates to geodetic coordinates - series solution ................................ 127
geodet2.m – convert geocentric coordinates to geodetic coordinates – exact solution ................................ 128
orb2eci.m – convert classical orbital elements to inertial state vector ......................................................... 132
eci2orb.m – convert inertial state vector to six classical orbital elements ................................................... 133
mee2coe.m – convert modified equinoctial orbital elements to classical orbital elements ......................... 136
mee2eci.m – convert modified equinoctial orbital elements to ECI state vector......................................... 138
eci2mee.m – convert ECI state vector to modified equinoctial elements ..................................................... 139
Page 5
Celestial Computing with MATLAB
Page 6
Celestial Computing with MATLAB
Introduction
Celestial Computing with MATLAB is a comprehensive collection of MATLAB functions,
scripts and data files that can be used to solve a variety of problems in fundamental and
advanced celestial mechanics. This suite of applications and functions can be used to solve
practical problems in the following areas of computational celestial mechanics:
This MATLAB toolbox also contains many numerical methods, basic celestial mechanics
functions and data files that can be used to create your own applications. The following is a
summary of these routines:
The Celestial Computing with MATLAB software suite also includes binary data files for the
SLP96 and DE403 ephemeris. Please note that the binary ephemeris and map files provided
with this software package are only compatible with the Windows version of MATLAB.
Requirements
Page 7
Celestial Computing with MATLAB
Page 8
Celestial Computing with MATLAB
This MATLAB script (riseset.m) determines rise and set conditions of the Sun, Moon and
planets. This software uses a combination of one-dimensional minimization and root-finding
to predict visibility. The source ephemeris for this routine is the JPL DE405.
The basic procedure for predicting rise and set of a celestial body involves the following
computational steps and MATLAB functions:
The main MATLAB function that solves this problem has the following syntax and
arguments:
% input
The name of the user-defined objective function (objfunc) and a function that prints the
important results (prtfunc) is passed to this routine in the argument list.
The proper selection of the search parameters dt and dtsml for this algorithm depends on the
type of celestial event you are trying to predict. For example, the value of dt is used to bound
one or more extremas and depends on how long the event lasts. For shorter events dt should
be smaller and for longer events dt can be larger. Be careful not to make dt too large or the
algorithm may “step over” one or more solutions. For lunar events dt can be between 0.1 and
0.25 days and for planetary events dt can be between 0.1 and 0.5 days.
The value of dtsml must be selected such that it produces a “big” enough change in the
objective function to tell the algorithm if it is moving “downhill” or “uphill”. This is similar
to choosing the value of x when numerically estimating the derivative of a function of the
Page 9
Celestial Computing with MATLAB
form y f x . For planetary events a value of dtsml = 0.1 days should be adequate. For
lunar events this number should be a number between 0.01 and 0.05 days. An examination
of a plot of the objective function over a period of time can also provide insight into the
proper selection of the dtsml parameter.
During the search process the oevent1 function calls a MATLAB function called minima
that calculates the extremum of a one-dimensional user-defined objective function. The
syntax of this optimization function is as follows:
% one-dimensional minimization
% Brent's method
% input
% output
The source code of the objective function for this example is as follows:
function fx = rsfunc(x)
% input
% output
% fx = objective function at x
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Page 10
Celestial Computing with MATLAB
dtr = pi / 180;
jdutc = jdatei + x;
jdtdt = utc2tdt(jdutc);
[ra, dec, dis] = applan1(jdtdt, jdutc, itarg, icent, 1, glon, glat, ht);
tmp1 = sin(hangle);
if (rootflg == 1)
% correct for horizontal refraction
if (itarg == 11)
% correct for semidiameter of the moon
tsdia = 0;
end
Notice the use of a root flag rootflg to “toggle” the function when finding a minimum
(rootflg = 0) or a root (rootflg = 1) of the objective function.
This function calculates the topocentric elevation angle of the celestial object for any input
argument x. For this script the input argument is the elapsed time in days since the simulation
Page 11
Celestial Computing with MATLAB
began. Notice the corrections for the semidiameter of the Moon and the horizontal refraction
during the root-finding calculations.
The syntax of the MATLAB function that calculates and displays the actual roots of the user-
defined objective function is as follows:
function events1 (objfunc, prtfunc, ti, tf, topt)
% input
This function is a “driver” routine that uses the time of the extrema topt to first bracket the
backward and forward roots and then actually find the value of each root. After each root is
calculated this routine then calls a MATLAB function called rsfunc that actually displays
the event conditions.
The following is a brief description of the function that brackets each root.
function broot
This MATLAB function is used to bracket a single root of a single nonlinear equation of the
form y f x It uses a combination of geometric acceleration and time rectification to
bracket single roots. The basic idea is to find the endpoints of a time interval x1 and x2 such
that f x1 f x2 0 . This condition guarantees that there is at least one root in the interval
because the objective function changes sign.
The user must supply this function with an initial guess for x1 and x2 . Typically x1 is the
time of an objective function minimum or maximum and x2 is a time 0.05 days after
(forward root) or 0.05 days before (backward root) the value of x1 . The sign of this delta
tells the algorithm in which direction to move.
The name of the user-defined objective function f is passed to this routine in the argument
list. For the riseset script the user-defined (and coded) objective function is called rsfunc.
% input
Page 12
Celestial Computing with MATLAB
% output
The acceleration factor used in this script is 0.25 and the rectification interval is 0.1 days.
The acceleration factor increases the size of each step geometrically and the rectification
interval monitors the length of the current bracketing interval. When necessary the
rectification logic reinitializes the search and prevents the interval from becoming too large
and skipping one or both ends of the bracketing interval completely. The size of each step
increases geometrically until the length of the current step reaches the value of the
rectification interval. At that point the step size is reset and the process begins again.
Eventually, the process will bracket the root and the function will return the endpoints of this
bracketing interval.
The following is a brief description of the MATLAB function that solves for each root.
function brent
This function uses Brent’s method to find a single root of a single nonlinear equation of the
form y f x . Derivatives are not required for this algorithm. However, the user should
ensure that a root is bracketed, f x1 f x2 0 , before calling this routine. Additional
information about this numerical method can be found in Algorithms for Minimization
Without Derivatives, R. P. Brent, Prentice-Hall, 1972. As the title of this book indicates, this
algorithm does not require derivatives of the objective function. This feature is important
because the analytic first derivative of many objective functions is difficult to derive and
code.
% Brent's method
% input
% output
Page 13
Celestial Computing with MATLAB
The riseset MATLAB script will prompt you for an initial calendar date, on the UTC time
scale, and the search interval in days. It will also ask you for the geographic coordinates of
the observer. Please note that north latitudes are positive and south latitudes are negative.
Also note that east longitudes are positive and west longitudes are negative. Furthermore,
observer sites above sea level have positive altitudes and sites below sea level are negative.
The following is a typical user interaction with this script. It illustrates two rise and sets of
the Moon. The initial calendar date was January 1, 1998, and the observer was located at 40
north latitude and 105 west longitude. The altitude of the site is 0 meters. The calendar date
and time displayed is on the UTC time scale.
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Sun
<11> Moon
Page 14
Celestial Computing with MATLAB
'Moon'
rise conditions
set conditions
rise conditions
Page 15
Celestial Computing with MATLAB
set conditions
This same technique can be used to predict rise and set of stars and other stellar objects. For
this case simply call the apstar1 or apstar2 MATLAB functions from within the rsfunc
objective function.
Page 16
Celestial Computing with MATLAB
2. Lunar Eclipses
This MATLAB script (eclipse.m) can be used to predict lunar eclipses. The source
ephemeris for this script is SLP96. However, the code can be easily modified to use DE405
as the source ephemeris. This software provides the eclipse type, the universal times and
topocentric coordinates of the Moon at the beginning and end of the penumbra contacts, and
the time and coordinates at maximum eclipse.
f t cos1 U
ˆ U
m
ˆ f s
s 1 m
where
Uˆ geocentric unit position vector of the Sun
s
ˆ
U m geocentric unit position vector of the Moon
f1 1.02 1 s ss size of penumbra shadow
1 0.99834 m corrected parallax
m horizontal parallax of the Moon
s horizontal parallax of the Sun
sm semidiameter of the Moon
ss semidiameter of the Sun
If we let represent the minimum geocentric separation angle of the Moon relative to the
shadow axis, a penumbral lunar eclipse occurs whenever the following geometric condition
is satisfied:
1.02 1 s ss sm
1.02 1 s ss sm
1.02 1 s ss sm
In these expressions
Page 17
Celestial Computing with MATLAB
req req
m sin 1 s sin 1
dm ds
r r
sm sin 1 m ss sin 1 s
dm ds
where req is the equatorial radius of the Earth (6378.14 kilometers), rm is the radius of the
Moon (1738 kilometers), rs is the radius of the Sun (696,000 kilometers), d m is the
geocentric distance of the Moon and d s is the geocentric distance of the Sun.
The following is a typical user interaction with this script. It illustrates the circumstances of
the total lunar eclipse of November 28, 1993. The topocentric coordinates are for an observer
located in Denver, Colorado.
lunar eclipses
working ...
Page 18
Celestial Computing with MATLAB
working ...
Page 19
Celestial Computing with MATLAB
3. Lunar Occultations
This MATLAB script (occult.m) can be used to predict the local circumstances of lunar
occultations of a planet or star. The source ephemeris for this script is SLP96. However, the
code can be easily modified to use DE405 as the source ephemeris.
f t cos1 U
ˆ U
m b m
ˆ s s
b
where
ˆ topocentric unit position vector of the Moon
U m
r
sm sin 1 m
dm
where rm is the radius of the Moon (1738 kilometers) and d m is the topocentric distance of
the Moon. The semidiameter of a star is zero and the semidiameter of a planet is
s p0
sp
rp
where s p0 is the semidiameter of the planet at a distance of 1 astronomical unit and rp is the
topocentric distance of the planet.
The following is a typical user interaction with this script. It illustrates a lunar occultation of
the star Spica relative to an observer located in Denver, Colorado.
lunar occultations
Page 20
Celestial Computing with MATLAB
? 30
<1> Mercury
<2> Venus
<3> Mars
<4> Jupiter
<5> Saturn
<6> Uranus
<7> Neptune
<8> Pluto
<9> Star
working ...
working ...
Page 21
Celestial Computing with MATLAB
star name
SPICA
parallax (arcseconds)
0.0210
Page 22
Celestial Computing with MATLAB
4. Solar Eclipses
This MATLAB script (seclipse.m) can be used to predict local circumstances of solar
eclipses. The source ephemeris for this script is SLP96. However, the code can be easily
modified to use DE405 as the source ephemeris. This software provides the universal times
and topocentric coordinates of the Moon at the beginning and end of the penumbra contacts,
and the time and coordinates at maximum eclipse.
f t cos1 U
ˆ U
axis
ˆ
mo p
where
ˆ
U axis selenocentric unit vector of the Moon's shadow
ˆ
U m o selenocentric unit position vector of the observer
The penumbra shadow angle at the distance of the Earth observer is determined from
rm 1 rs rm
p sin 1 sin
dm d m s
In this expression rm is the radius of the Moon, rs is the radius of the Sun, d m is the
topocentric distance of the Moon and d m s is the distance from the Moon to the Sun.
The selenocentric position vector of the Sun is computed from the expression
R m s R s R m
where R s is the geocentric position vector of the Sun and R m is the geocentric position
vector of the Moon.
The following is a typical user interaction with this script. This example is taken from page
209 of Astronomy with the Personal Computer.
solar eclipses
Page 23
Celestial Computing with MATLAB
? 30
working ...
working ...
working ...
Page 24
Celestial Computing with MATLAB
This MATLAB script (transit.m) can be used to predict the local circumstances of
transits of Mercury and Venus. The source ephemeris for this script is SLP96. However, the
code can be easily modified to use DE405 as the source ephemeris.
f t cos1 U
ˆ U
s p s
ˆ s s
p
where
ˆ topocentric unit position vector of the Sun
U s
During the search for minimum separation angles, the software also checks to see if the
planet is between the observer and the Sun.
r
ss sin 1 s
ds
where rs is the radius of the Sun (696,000 kilometers) and d s is the topocentric distance of
the Sun. The semidiameter of Mercury and Venus is determined from the expression
s p0
sp
rp
where s p0 is the semidiameter of the planet at a distance of 1 astronomical unit and rp is the
topocentric distance of the planet. This script uses a value of 3.36 arc seconds for Mercury
and 8.41 arc seconds for Venus.
The following is a typical user interaction with this script. This example is Example 6 from
the book Transits by Jean Meeus. The software will also display the topocentric coordinates
of the Sun at the time of ingress, least separation distance and egress. The ingress and egress
conditions correspond to exterior contact.
Page 25
Celestial Computing with MATLAB
<1> Mercury
<2> Venus
working ...
working ...
Page 26
Celestial Computing with MATLAB
working ...
Page 27
Celestial Computing with MATLAB
This MATLAB script (cae2ho.m) uses a combination of Cowell’s method and one-
dimensional minimization to predict closest approach conditions between the Earth and
objects such as asteroids, comets and other bodies in heliocentric elliptic orbits. It includes
the point mass gravity perturbations due to the planets Mercury, Venus, Earth, Mars, Jupiter,
Saturn and the Sun. It also includes the point-mass effect of the Moon via a combined
Earth/Moon gravitational constant.
The user can elect to use either the JPL DE405 ephemeris or the SLP96 ephemeris developed
by the Bureau of Longitudes in Paris for the planetary and solar ephemeris calculations. The
software expects to find one or both of these binary files in the same directory as cae2ho.
Additional information about the SLP96 ephemeris can be found on the Internet at
ftp://ftp.bdl.fr/pub/ephem/sun/slp96. Information about the DE405 ephemeris is available
at ftp://navigator.jpl.nasa.gov.
d 2r rs b 9
r p bi rpi
r 2 r, t s 3
pi 3
3
dt rs b i 1 r p b rpi
i
where
s gravitational constant of the Sun
p gravitational constant of planet i
i
rsb rp rpb
This program uses the Runge-Kutta-Fehlberg 7(8) method to numerically integrate the first-
order form of the orbital equations of motion. This is a variable step size method of order 7
with an 8th order error estimate that is used to dynamically change the integration step size
during the simulation.
This software also uses a one-dimensional optimization algorithm due to Richard Brent to
solve the close approach problem. Additional information about this numerical method can
be found in Algorithms for Minimization Without Derivatives, R.P. Brent, Prentice-Hall,
1972. As the title of this book indicates, this algorithm does not require derivatives of the
Page 28
Celestial Computing with MATLAB
objective function. This feature is important because the analytic first derivative of many
objective functions is difficult to derive and code. The objective function for this program is
the scalar geocentric distance of the heliocentric object.
The software will ask you for the name of a simple ASCII input file that defines the
simulation. When responding to this request be sure to include the file name extension. The
following is a typical input data file for this program. It contains the J2000 equator and
equinox heliocentric orbital elements of the asteroid 1997 XF 11. This file was created using
data available on the Horizons ephemeris system which is located on the Internet at
http://ssd.jpl.nasa.gov/horizons.html. Do not change the total number of lines or the order
of annotation and data in this file. The software expects to find exactly 31 lines of
information in the input data file.
initial TDB
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
0,0,0
initial right ascension of the ascending node (J2000 equator and equinox)
(degrees; 0 <= raan <= 360)
0.3533298230482567D+03
Please note the proper units and coordinate system (J2000 equinox and equator) of the input
orbital elements. Be sure to include all the digits of the calendar year. Notice also that time
on the TDB scale is used.
The following is a typical user interaction with this MATLAB script. The user can specify
the search duration in days and a minimum close approach distance in Astronomical Units.
program cae2ho
< closest approach between the Earth and a heliocentric object >
Page 29
Celestial Computing with MATLAB
DE405 ephemeris
For this example the output is with respect to the J2000/ICRF equinox and equator. When
using SLP96 as the source ephemeris, the output will be with respect to the J2000 dynamical
equinox and equator.
Page 30
Celestial Computing with MATLAB
This MATLAB script (equsol.m) determines the time of the equinoxes and solstices of the
Earth. These events are the times when the apparent geocentric longitude of the Sun is an
exact multiple of 90 degrees. This script uses Brent’s root-finder and the sun1.m solar
ephemeris to calculate these events.
Brent’s method requires an objective function that defines the nonlinear equation to be
solved. The objective function for the spring and fall equinoxes is the geocentric declination
of the Sun. For the summer and winter solstices the objective function is s , where
90 for the summer solstice, 270 for the winter solstice and s is the geocentric
apparent longitude of the Sun. Brent’s method also requires an initial and final time which
bounds the root of the objective function. The initial time for the spring equinox is March 15,
for the summer solstice June 15, for the fall equinox September 15 and for the winter solstice
December 15. For each event, the final time is equal to these initial dates plus 15 days.
The equsol script will prompt you for the calendar date of interest. The following is a typical
user interaction with this script. Please note that the event is displayed in dynamical or
ephemeris time.
spring equinox
summer solstice
fall equinox
winter solstice
Page 31
Celestial Computing with MATLAB
This MATLAB script (cowell1.m) uses Cowell’s method to propagate the motion of
spacecraft, comets and other celestial bodies in heliocentric elliptic orbits. It includes the
point mass gravity perturbations due to the planets Venus, Earth, Mars, Jupiter, Saturn and
the Sun. The low precision ephemerides used in this application can be replaced with the
DE405 or SLP96 algorithms.
d 2r rs b 9
r p bi rpi
r 2 r, t s 3
pi 3
3
dt rs b i 1 r p b rpi
i
where
s gravitational constant of the Sun
p gravitational constant of planet i
i
rsb rp rpb
Page 32
Celestial Computing with MATLAB
162.2486
The syntax of the MATLAB function that reads this file is as follows:
% input
% output
% fid = file id
% jdpp = julian date of perihelion passage
% oev(1) = semimajor axis
% oev(2) = orbital eccentricity
% oev(3) = orbital inclination
% oev(4) = argument of perigee
% oev(5) = right ascension of the ascending node
% oev(6) = true anomaly
program cowell1
? 2
Page 33
Celestial Computing with MATLAB
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 0,0,0
program cowell1
final conditions
This MATLAB script (cowell2.m) determines the long-term orbit evolution of objects in
heliocentric orbits using Cowell’s solution of the modified equinoctial orbital elements form
of the differential equations of motion. The user can provide the initial orbital elements for
this program interactively or by specifying the name of a data file as described in the
cowell1.m script above.
program cowell2
? 2
Page 34
Celestial Computing with MATLAB
? halley.dat
program cowell2
final conditions
Technical Discussion
The relationship between modified equinoctial orbital elements and classical orbital elements
is given by
p a 1 e 2
f e cos
g e sin
h tan i 2 cos
k tan i 2 sin
L
where
Page 35
Celestial Computing with MATLAB
p semiparameter
a semimajor axis
e orbital eccentricity
i orbital inclination
argument of perigee
right ascension of the ascending node
true anomaly
L true longitude
The equations of orbital motion expressed in terms of modified equinoctial orbital elements
are as follows:
dp 2 p p
p t
dt w
df p g
f r sin L w 1 cos L f t h sin L k cos L n
dt w w
dg p g
g r cos L w 1 sin L g t h sin L k cos L n
dt w w
dh p s 2n
h cos L
dt 2w
dk p s 2n
k sin L
dt 2w
2
dL w 1 p
L p h sin L k cos L n
dt p w
where r , t , n are external perturbations in the radial, tangential and orbit normal
directions, respectively.
dy
y A yP b
dt
Page 36
Celestial Computing with MATLAB
where
2p p
0 0
q
q 1 cos L f
p p1 p g
sin L h sin L k cos L
q q
q 1 sin L g
p p p f
cos L h sin L k cos L
q
A y
2
0 0
p s cos L
2q
p s 2 sin L
0 0
2q
p
0 0 h sin L k cos L
and
0
0
0
b 0
0
q
2
p
p
In this MATLAB script these perturbations consist of the point-mass gravity effects of the
planets. Other perturbations such as solar radiation pressure can also be included.
Furthermore, ˆir , ˆit and ˆin are unit vectors in the radial, tangential and normal directions given
by
Page 37
Celestial Computing with MATLAB
ˆi r
r
r
ˆi r v
rv
n
ˆi ˆi ˆi
t n r
Page 38
Celestial Computing with MATLAB
The classic form of Encke’s special perturbation method solves the initial value problem
(IVP) of celestial mechanics by analytically propagating a two-body “reference” orbit and
numerically integrating the deviations from two-body motion. These two procedures are
performed for the same time interval or step size. Since the two-body solution is “exact”, the
time interval used is usually a function of the numerical integration technique and the
magnitude of the perturbations. After each propagation interval, the errors between the
reference orbit and the perturbed orbit are evaluated. When these errors become “large”, a
process known as rectification of the orbit is performed. This involves adding the integrated
deviations to the two-body orbit to produce a new reference orbit called the osculating orbit.
After rectification, the algorithm is reinitialized with the elements of the new osculating orbit
and the process is repeated until either the errors become large once more or the final time is
reached.
The numerical algorithm used in this script simplifies this technique by using a variable step-
size integration method to automatically select the propagation step size. Since this type of
integrator “senses” the magnitude of the perturbations, it will choose the “best” and largest
step size for each propagation interval. The user can control how well this procedure is
performed with the algorithm truncation error tolerance. Furthermore, the software eliminates
the logic required to determine when rectification should occur by simply rectifying the orbit
after each and every propagation step.
d 2rk r t
2
k 3 0
dt rk
where rk is the unperturbed position vector of the spacecraft at any time t and is the
gravitational constant of the primary body.
The equations of motion of motion of a spacecraft subject to a point mass central body and
other external perturbations are
d 2rp r t
2
p 3 a rp , t
dt rp
where rp is the perturbed position vector at any time t and a rp , t is the vector of
perturbations or other accelerations.
Page 39
Celestial Computing with MATLAB
2r d 2rp d 2rk
dt 2 dt 2 dt 2
2r
f q rp t rp t a rp , t
dt 2
3
where
3 3q q2
f q q
1 1 q 3/ 2
and
q
r 2r r
r2
At any time the position and velocity vectors of the true orbit are given by the vector sum of
the two body and perturbed components as follows:
r t rk t rp t
v t vk t v p t
The gravitational acceleration on the spacecraft due to each planet is determined from the
following expression:
r rp
a r, t p b
rp b 3 rp 3
where
rp b position vector of spacecraft relative to planet
rp position vector of spacecraft relative to Sun
gravitational constant of planet
The software uses a slightly modified version of Shepperd's two body algorithm to provide
the unperturbed solution for any simulation time. This MATLAB file is called twobody4 and
has for its input and output the entire state vector in a single array instead of individual
position and velocity arrays. The “deviation” equations of motion are integrated using a
slightly modified version of the Runge-Kutta-Fehlberg 7(8) method called rkencke.
Page 40
Celestial Computing with MATLAB
Although simple and straightforward, this approach does require special attention to the
initialization at the start of each propagation step. Since there are no perturbations at the
initial epoch of the osculating reference orbit, the integrator would use the initial step size
defined by the user. This will cause very large errors before rectification can be performed.
To avoid this problem, the software forces the algorithm to perform the first phase of the
orbit propagation with a fixed step size. This is accomplished by setting the initial step size
guess to a small value and the truncation error tolerance to a very large value. For the second
phase of the propagation, the step size estimate is increased and the RKF algorithm is
allowed to change the actual step size to the largest value based on the perturbations and
user-defined error tolerance. The truncation error tolerance for this phase is set to a very
small number. The “best” initial step size depends on the type of orbit propagation and the
initial conditions.
Additional information about this algorithm can be found in AAS 92-196, “A Simple and
Efficient Computer Implementation of Encke’s Method”, AAS/AIAA Spaceflight Mechanics
Meeting, Colorado Springs, Colorado, February 24-26, 1992.
The information required for this script can either be manually input by the user or the
software can read a simple data file of orbital elements. For both options the program will
always ask the user for the initial calendar date and Universal Time of the simulation, the
simulation duration in days, and the algorithm error tolerance. A tolerance of 1.0e-8 is
recommended.
program encke
? 2
Page 41
Celestial Computing with MATLAB
This program also uses the readoe2 function to process the input data file. The following is
the screen display created by this software for this example.
final conditions
The low precision ephemeris used in this application can be replaced with the DE405 or
SLP96 algorithms very easily.
Page 42
Celestial Computing with MATLAB
The applications described here are for orbital problems in the Earth-Moon-satellite system.
However, the equations and algorithms are valid for any circular-restricted three-body system
for which the mass ratio of the primary and secondary is between 0 and 1/2.
The classic textbook for this problem is Theory of Orbits by Victor Szebehely, Academic
Press, New York, 1967. An excellent discussion about this problem can also be found in
Chapter 8 of An Introduction to Celestial Mechanics by Forest Ray Moulton, Dover
Publications, 1970.
Technical Discussion
The motion of the spacecraft or celestial body is modeled in a coordinate system which is
rotating about the center-of-mass or barycenter of the Earth-Moon system. The motion of all
three bodies is confined to the x-y plane. In the discussion that follows, subscript 1 is the
Earth and subscript 2 is the Moon.
For convenience, the problem is formulated in canonical or non-dimensional units. The unit
of length is taken to be the constant distance between the Earth and Moon, and the unit of
time is chosen such that the Earth and Moon have an angular velocity about the barycenter
equal to 1.
2 m1 m2 g m1 m2 1
3
The x and y coordinates of the Earth and Moon in this coordinate system are given by
x1 y1 0
x2 1 y2 0
The position and velocity vectors of the small body in this system are sometimes called
“synodical” coordinates to distinguish them from “sidereal” coordinates defined in an
inertial, non-rotating coordinate system.
Page 43
Celestial Computing with MATLAB
d 2x dy xx xx
2
2 x 1 3 1 3 2
dt dt r1 r2
d2y dx y y
2
2 y 1 3 3
dt dt r1 r2
d 2z z z
2
1 3 3
dt r1 r2
where
x x component of position
y y component of position
z z component of position
x1
x2 1
Earth-Moon mass ratio m1 / m2 1/ 81.27
r12 x x1 y 2 z 2
2
r22 x x2 y 2 z 2
2
2 1 2
V 2 x2 y2 C
r1 r2
In this equation V is the scalar speed of the small body and C is a constant of integration
called the Jacobi constant.
In his prize memoir of 1772, Joseph-Louis Lagrange proved that there are five equilibrium
points in the circular-restricted three-body problem. If a satellite or celestial body is located
at one of these points with zero initial velocity relative to the rotating coordinate system, it
will stay there permanently provided there are no perturbations. These special positions are
also called libration points or stationary Lagrange points. Three of these libration points are
on the x-axis (collinear points) and the other two form equilateral triangles with the positions
of the Earth and Moon.
Page 44
Celestial Computing with MATLAB
This MATLAB script can be used to calculate the coordinates and energy of the five libration
or equilibrium points of the CRTBP. For the collinear libration points this script solves three
nonlinear equations.
1
x 0
x x 1
2 2
1
x 0
x x 1
2 2
1
x 0
x x 1
2 2
The lower and upper bounds used during the root-finding search for all three equations are
x 2 and x 2 respectively.
program crtbp1
program crtbp1
Page 45
Celestial Computing with MATLAB
This MATLAB script graphically displays motion of a spacecraft or small celestial body in
the circular-restricted three-body problem. This algorithm and program examples are based
on the methods described in “Periodic Orbits in the Restricted Three-Body Problem with
Earth-Moon Masses”, by R. A. Broucke, JPL TR 32-1168, 1968.
program g3body
main menu
selection (1, 2, 3 or 4)
The first three menu options will display typical periodic orbits about the respective libration
point. The initial conditions for each of these example orbits are as follows:
x0 0.300000161
y0 2.536145497
0.012155092
t f 5.349501906
Page 46
Celestial Computing with MATLAB
x0 2.840829343
y0 2.747640074
0.012155085
t f 11.933318588
x0 1/ 600000312
y0 2.066174572
0.012155092
t f 6.303856312
If you would like to experiment with your own initial conditions, select option <4> from the
main menu. The program will then prompt you for the initial x and y components of the
orbit's position and velocity vector, and the values of to use in the simulation. The
software will also ask for an initial and final time to run the simulation, and an integration
step size. The value 0.01 is a good number for step size.
Here is a short list of initial conditions for several other periodic orbits that you may want to
display with this script.
x0 2.499999883
y0 2.100046263
0.012155092
t f 11.99941766
x0 0.952281734
y0 0.957747254
0.012155092
t f 6.450768946
Page 47
Celestial Computing with MATLAB
x0 3.147603117
y0 3.07676285
0.012155092
t f 12.567475674
x0 1.399999991
y0 0.9298385561
0.012155092
t f 13.775148738
The following is the graphic screen display for main menu option <3> and an integration
step size of 0.01. The locations of the Earth and Moon are labeled with an asterisk and the
L3 libration point is the small dot.
Page 48
Celestial Computing with MATLAB
The following is a summary of these test problems. Column 1 is the test problem number,
column 2 is the initial x coordinate x0 , column 3 is the initial y speed y0 and column 4 is the
orbital period t f . For problems 1 to 15 0.012277471 and for problems 16 to 20
0.000953875 .
This MATLAB script can be used to display zero relative velocity curves that pass through
the five equilibrium or libration points of the Earth-Moon circular-restricted three-body
Page 49
Celestial Computing with MATLAB
problem (CRTBP). These two-dimensional drawings are also called equipotential curves.
The zero velocity curves define regions of the x-y plane that a satellite or celestial body with
a given energy level can or cannot attain.
If we set the velocity components to zero in the equation for the Jacobi integral, we find that
the Jacobi constant can be determined from the following expression:
2 2
C 2 E0 1 r12 r22 1
r1 r2
where E0 is the zero relative velocity specific orbital energy which is given by.
1
E0
2
1 2
x y2
r1
r2
From the Jacobi integral we can see that imaginary velocities occur whenever the following
expression is smaller than the Jacobi constant C.
2 1 2
x2 y2
r1 r2
This MATLAB script computes and displays zero relative velocity contour plots that actually
pass through the five libration points.
program zvcurve1
<1> L1 contour
<2> L2 contour
<3> L3 contour
selection (1, 2, 3, 4 or 5)
?5
The following is a graphics display of the equipotential curves through each libration point.
The libration points are labeled with asterisks and the Earth and Moon are shown as small
dots.
Page 50
Celestial Computing with MATLAB
This MATLAB script can be used to display zero relative velocity contour curves of the
circular-restricted three-body problem (CRTBP) for user-defined values of the Jacobi
constant C and mass ratio as defined by the following expression:
2 2
C 1 r12 r22 1
r1 r2
This application will prompt the user for the mass ratio and the contour levels to plot either
as discrete values or as a range of values with a user-defined increment. The software will
also ask you for the minimum and maximum values of the x and y coordinates and an
increment for creating the mesh grid used by MATLAB to plot the contours. Please note that
if the mesh grid increment is too large the script may not plot “complete” contour levels.
program zvcurve2
Page 51
Celestial Computing with MATLAB
selection (1 or 2)
? 1
The following is the graphics display for this example. The libration points for this three-
body system are labeled with asterisks and the primary and secondary bodies are shown as
small dots.
Page 52
Celestial Computing with MATLAB
The software also allows the user to control what part of the contour plot is displayed and
label the zero relative velocity contours. The following is a typical user interaction
illustrating these script options.
program zvcurve2
selection (1 or 2)
? 1
Page 53
Celestial Computing with MATLAB
The following is the graphics display for this example. The libration points for this three-
body system are labeled with asterisks and the primary and secondary bodies are shown as
small dots.
Page 54
Celestial Computing with MATLAB
(1) precession
(2) nutation
(3) aberration
(4) gravitational deflection of light
Please note that these functions do not include a correction for atmospheric refraction.
An excellent discussion about these corrections can be found in “Mean and Apparent Place
Computations in the New IAU System. III. Apparent, Topocentric, and Astrometric Places of
Planets and Stars”, G.H. Kaplan, J.A. Hughes, P.K. Seidelmann, C.A. Smith and B.D.
Yallop, The Astronomical Journal, Vol. 97, No. 4, pages 1197-1210, 1989.
The processing steps used in these two MATLAB scripts are as follows:
The topocentric azimuth A and elevation (altitude) h are calculated using the topocentric right
ascension and declination and the observer's coordinates as follow:
sin H
tan A
cos H sin tan cos
Page 55
Celestial Computing with MATLAB
where H is the apparent hour angle of the celestial object and is the geodetic latitude of
the observer. The apparent hour angle is given by the difference between the observer's local
sidereal time and the right ascension of the object as follows:
H
In these MATLAB functions azimuth is measured positive clockwise from north. For
example, east is an azimuth of 90, south is 180 and so forth.
function applan1.m
The source ephemeris for this routine is the DE405 binary file jpleph.
function [ra, dec, dis] = applan1 (tjd, ujd, l, n, topo, glon, glat, ht)
% input
% output
A MATLAB script called aplanet1 demonstrates how to interact with this function. This
script will prompt you for the calendar date, universal time, observer coordinates, the “target”
body and the type of ephemeris (topocentric or geocentric). The program defaults to the
Earth as the central or “primary” body.
Page 56
Celestial Computing with MATLAB
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1998
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Sun
<11> Moon
<1> geocentric
<2> topocentric
'Moon'
Page 57
Celestial Computing with MATLAB
function applan2.m
The source ephemeris for this routine is the SLP96 binary file slp96.
function [ra, dec, dis] = applan2(tjd, ujd, l, n, topo, glon, glat, ht)
% input
% output
The MATLAB script called aplanet2 demonstrates how to use this function. The user
interaction with this script is identical to the interaction with the aplanet1 script described
above.
Page 58
Celestial Computing with MATLAB
(1) precession
(2) nutation
(3) aberration
(4) gravitational deflection of light
(5) proper motion
(6) parallax
(7) radial velocity
Please note that this program does not include a correction for atmospheric refraction. For
extragalatic objects the proper motions, parallax and radial velocity should all be set to 0.
An excellent discussion about these corrections can be found in “Mean and Apparent Place
Computations in the New IAU System. III. Apparent, Topocentric, and Astrometric Places of
Planets and Stars”, G.H. Kaplan, J.A. Hughes, P.K. Seidelmann, C.A. Smith and B.D.
Yallop, The Astronomical Journal, Vol. 97, No. 4, pages 1197-1210, 1989.
The syntax and arguments for the MATLAB function that actually performs most of the
calculations are as follows:
Page 59
Celestial Computing with MATLAB
function [ra, dec] = apstar1 (tjd, ujd, n, topo, glon, glat, ht, ...
ram, decm, pmra, pmdec, parlax, radvel)
% input
% output
The astar software will prompt you for the calendar date, universal time, observer
coordinates, the name of the star data file and the type of ephemeris (topocentric or
geocentric). The following is a typical star data file named altair.dat. Do not delete any
lines of text or data as the software expects to find exactly 20 lines of information.
star name
ALTAIR
parallax (arcseconds)
0.1981
The following is a typical user interaction with the star1 (and star2) scripts. It illustrates
the topocentric coordinates of the star Altair relative to a sea level observer at 40 north
latitude and 105 west longitude, at 0 hours UT.
Page 60
Celestial Computing with MATLAB
<1> geocentric
<2> topocentric
ALTAIR
Page 61
Celestial Computing with MATLAB
The jplephem function requires initialization the first time it is called. The following
statement in the main MATLAB script will accomplish this:
iephem = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function.
Demojpl is a simple MATLAB script that demonstrates how to call the jplephem routine. A
sample binary file for IBM-PC compatible computers is included on the Celestial Computing
with MATLAB CD ROM. The name of this binary file is jpleph and it is valid between
Julian date 2429616.5 (calendar date 12/19/1939) and Julian date 2473488.5 (calendar date
1/30/2060). The coordinates calculated by this function are with respect to the International
Celestial Reference System (ICRS) which is described in “The International Celestial
Reference Frame as Realized by Very Long Baseline Interferometry”, C. Ma, E. Arias, T.
Eubanks, A. Fey, A. Gontier, C. Jacobs, O. Sovers, B. Archinal and P. Charlot, The
Astronomical Journal, 116:516-546, 1998, July.
% input
% 1 = mercury 8 = neptune
% 2 = venus 9 = pluto
% 3 = earth 10 = moon
% 4 = mars 11 = sun
% 5 = jupiter 12 = solar-system barycenter
% 6 = saturn 13 = earth-moon barycenter
% 7 = uranus 14 = nutations (longitude and obliq)
Page 62
Celestial Computing with MATLAB
% output
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Moon
<11> Sun
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Moon
<11> Sun
<12> solar-system barycenter
<13> Earth-Moon barycenter
Page 63
Celestial Computing with MATLAB
? 3
state vector
Page 64
Celestial Computing with MATLAB
The slp96 function requires initialization the first time it is called. The following statement
in the main MATLAB script will accomplish this:
islp96 = 1;
The user must also specify the name of the binary data file with the following statement:
fname = ‘slp96’
These variables should also be placed in a global statement at the beginning of the main
script that calls this function.
Demoslp is a simple MATLAB driver script that demonstrates how to call the slp96 routine.
A sample binary file for IBM-PC compatible computers is included on the Celestial
Computing with MATLAB CD ROM. This binary file is valid between Julian date 2433264.5
(calendar date 12/14/1949) and Julian date 2469808.5 (calendar date 1/02/2050).
The following is a summary of the inputs and outputs for this MATLAB function:
function [result, ierr] = slp96 (tjd, ibody, icent, ipv, iframe, icoord)
% input
Page 65
Celestial Computing with MATLAB
% ipv=1 : position.
% ipv=2 : position and velocity.
% output
% position
% velocity
% position
% velocity
% ierr=0 : no error
% ierr=10 : file error
% ierr=11 : date error (tjd)
% ierr=12 : body error (ibody)
% ierr=13 : frame center error (icent)
% ierr=14 : position-velocity error (ipv)
% ierr=15 : frame error (iframe)
% ierr=16 : coordinates error (icoord)
Page 66
Celestial Computing with MATLAB
<1> Mercury
<2> Venus
<3> Earth-Moon barycenter
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> void
<10> Moon
<11> Sun
<12> Earth
Page 67
Celestial Computing with MATLAB
<7> Uranus
<8> Neptune
<9> void
<10> Moon
<11> Sun
<12> Earth
program demoslp
state vector
Page 68
Celestial Computing with MATLAB
t JD 2451545
T t / 36525 1
Each MATLAB function uses fundamental trigonometric arguments (in revolutions) of the
following form:
Gs 0.993126 0.00273777850t
G2 0.140023 0.00445036173t
G4 0.053856 0.00145561327t
G5 0.056531 0.00023080893t
F4 0.849694 0.00145569465t
L4 0.987353 0.00145575328t
The heliocentric, ecliptic longitude , latitude and distance r are computed from series
involving these arguments. These series are of the form
cos cos
r r cos sin
sin
This function calculates the true-of-date geocentric right ascension, declination and position
vector of the Sun.
Page 69
Celestial Computing with MATLAB
% solar ephemeris
% input
% output
This function calculates the true-of-date geocentric right ascension, declination and position
vector of the Moon.
% lunar ephemeris
% input
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Mercury.
% input
Page 70
Celestial Computing with MATLAB
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Venus.
% input
% output
This function calculates the true-of-date heliocentric ecliptic position vector of the Earth.
% input
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Mars.
% input
Page 71
Celestial Computing with MATLAB
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Jupiter.
% input
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Saturn.
% input
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Uranus.
% input
Page 72
Celestial Computing with MATLAB
% output
This function calculates the true-of-date heliocentric ecliptic position vector of Neptune.
% input
% output
This function calculates the heliocentric position vector of Pluto relative to the ecliptic and
equinox of J2000. This algorithm is based on the method described in Chapter 36 of
Astronomical Algorithms by Jean Meeus.
The fundamental time argument for this method is a function of the Julian Ephemeris Date
JED as follows:
JED 2451545
T
36525
The heliocentric ecliptic coordinates of Pluto are computed from series of the form
43
m A sin B cos
i 1
where
m coordinate mean value
iJ jS kP
J , S , P mean longitudes of Jupiter, Saturn and Pluto
i, j, k integer constants
A, B coefficients of periodic term
Page 73
Celestial Computing with MATLAB
% input
% output
This MATLAB function computes a true-of-date geocentric ephemeris of the Sun based on
the data and numerical methods described in the book, Planetary Programs and Tables by
Pierre Bretagnon and Jean-Louis Simon.
The fundamental time argument of this method is the number of days relative to the Julian
epoch January 1, 2000 normalized with respect to 3652500 Julian days. This value can be
calculated for any Julian Ephemeris Date JED with the following expression
JED 2451545
U
3652500
The geocentric, ecliptic mean longitude of the Sun is calculated with a trigonometric series of
the form
50
sm 0 1 U li sin i i U
i 1
The geocentric distance of the Sun is calculated with another series of the form
50
rs r0 r1 U ri cos i i U
i 1
The longitude of the Sun is corrected for the effect of aberration (in radians) with the
following equation:
sa 107 993 17cos 3.10 62830.14U
where
Page 74
Celestial Computing with MATLAB
The apparent, geocentric ecliptic longitude of the Sun is determined as the combination of
these three components with the next equation
s sm sa
The three components of the geocentric, ecliptic position vector of the Sun are given by
xs rs cos s
ys rs sin s
zs 0
The apparent geocentric, equatorial right ascension s and declination s of the Sun can be
found from
where is the true obliquity of the ecliptic. This number is calculated from the mean
obliquity of the ecliptic m and the nutation in obliquity in this function with the
following expressions:
m
m 107 4090928 446cos A1 28cos A2
107U 226938 U 75 U 96926 U 2491 12104U
Finally, we can compute the three components of the apparent, geocentric equatorial position
vector of the Sun with the following three expressions:
rx r cos s cos s
ry r sin s cos s
rz r sin s
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
Page 75
Celestial Computing with MATLAB
suncoef = 1;
This variable should also be placed in a global statement at the beginning of the main
script that calls this function.
% input
% output
This function calculates the osculating classical orbital elements of the Moon in the mean
ecliptic and mean equinox of date coordinate system. It is based on the book Lunar Tables
and Programs From 4000 B.C. TO A.D. 8000 by Michelle Chapront-Touze and Jean
Chapront. This book and its optional companion software are available from Willmann-Bell
(www.willbell.com).
JED 2451545
t
36525
The osculating orbital elements are calculated from series of the form
a 383397.6 Sa tSa
where
30
Sa an cos n n t n 104 t 2 n 106 t 3 n 108 t 4
0 1 2 3 4
n 1
3
Sa an cos n n t
0 1
n 1
The first few multipliers and trigonometric arguments for this orbital element are
Page 76
Celestial Computing with MATLAB
n an n 0 n1 n 2 n 3 n 4
1 3400.4 235.7004 890534.223 -32.601 3.664 -1.769
0
2 -635.6 100.7370 413335.355 -122.571 -10.684 5.028
4
% input
% output
A MATLAB script called demoelp.m which demonstrates how to interact with this
ephemeris function is included with this software. The following is a typical user interaction
with this script.
demoelp
Page 77
Celestial Computing with MATLAB
? 2
This MATLAB calculates the position and velocity vectors of the planets with respect to the
mean ecliptic and equinox of date. These calculations are based on the algorithm described in
Chapter 30 of Astronomical Algorithms by Jean Meeus. Each orbital element is represented
by a cubic polynomial of the form
Page 78
Celestial Computing with MATLAB
JED 2451545
T
36525
% planetary ephemeris
% input
% output
This MATLAB calculates the position and velocity vectors of the planets with respect to the
mean ecliptic and equinox of J2000. These calculations are based on the algorithm described
in Chapter 30 of Astronomical Algorithms by Jean Meeus. Each orbital element is
represented by a cubic polynomial of the form
JED 2451545
T
36525
% planetary ephemeris
% input
Page 79
Celestial Computing with MATLAB
% output
This MATLB function computes a transformation matrix that can be used to convert vectors
in the ECI mean of date coordinates to selenographic mean of date or true of date coordinate
system. The transformation is based on the algorithms given in Section 4.8 of the classic text
Methods of Orbit Determination.
% input
% jd = julian date
% it = transformation flag
% = 0 transform to mean selenographic
% <> 0 transform to true selenographic
% (include physical librations)
% output
A MATLAB script that demonstrates how to use this function is included in the Celestial
Computing with MATLAB software suite. The script is called demosen.m and it graphically
displays the topocentric coordinates of the Sun relative to a selenographic location on the
Moon.
Page 80
Celestial Computing with MATLAB
This function calculates the apparent Greenwich sidereal time using the first few terms of the
IAU 1980 nutation algorithm.
m cos m
where m is the Greenwich mean sidereal time, is the nutation in longitude, m is the
mean obliquity of the ecliptic and is the nutation in obliquity.
where T ( JD 2451545) / 36525 and JD is the Julian date on the UT1 time scale. The
mean obliquity of the ecliptic is determined from
The nutations in obliquity and longitude involve the following three trigonometric arguments
(in degrees):
L 280.4665 36000.7698T
L 218.3165 481267.8813T
125.04452 1934.136261T
Page 81
Celestial Computing with MATLAB
The following diagram illustrates the geometry of sidereal time. In this picture is the
observer’s west longitude and is the observer’s local sidereal time.
% input
% output
This function calculates the mean or apparent Greenwich sidereal time. For the apparent
sidereal time calculation, the obliquity in longitude and obliquity are determined using the
nutation function which implements the full IAU 1980 nutation algorithm. Please note
that the Julian date can be passed to this routine in a high-order and low-order part. In the
input argument list k determines the type of Greenwich sidereal time calculation. This
function was ported to MATLAB using the Fortran version of the NOVAS source code that
was developed at the USNO.
Page 82
Celestial Computing with MATLAB
n
Si sin Ai
i 1
n
Ci cos Ai
i 1
where
Ai ail bil ci F di D ei
% input
% output
This function calculates the mean or apparent Greenwich sidereal time. For the apparent
sidereal time calculation, the obliquity in longitude and obliquity are determined by reading
the nutation values contained on a JPL DE405 binary ephemeris file named jpleph. Please
note that the Julian date can be passed to this routine in a high-order and low-order part. In
the input argument list k determines the type of Greenwich sidereal time calculation. This
function was ported to MATLAB using the Fortran version of the NOVAS (Naval
Observatory Vector Astrometry Subroutines) source code that was developed at the United
States Naval Observatory.
Page 83
Celestial Computing with MATLAB
% reference
% aoki, et al. (1982) astronomy and astropysics 105, 359-361
% input
% output
Page 84
Celestial Computing with MATLAB
This MATLAB function (nutation.m) calculates the nutation in longitude and obliquity
using the coefficients defined by the IAU 1980 nutation theory.
n
Si sin Ai
i 1
n
Ci cos Ai
i 1
where
Ai ail bil ci F di D ei
and l , l , F , D and are fundamental arguments. The number of terms in this nutation theory
is 106.
can be used to transform a mean equinox of date position vector r0 to a true equinox of date
position vector r as follows:
r N r0
In this matrix 0 is the mean obliquity of the ecliptic and 0 is the true obliquity.
The nutation matrix can also be expressed as a combination of individual rotations according
to
N R1 R3 R1 0
where T JD 2451545.0 / 36525 and JD is the Julian Date on the UT1 time scale.
Page 85
Celestial Computing with MATLAB
If second-order terms are neglected, a linearized nutation matrix can be calculated from
Finally, mean equinox equatorial rectangular position coordinates can be converted to true
equinox coordinates by adding the following corrections to the respective components:
% input
% output
Page 86
Celestial Computing with MATLAB
This MATLAB function (precess.m) precesses equatorial rectangular coordinates from one
epoch to another. The coordinates are referred to the mean equator and equinox of the two
respective epochs. This function was ported to MATLAB using the Fortran version of the
NOVAS (Naval Observatory Vector Astrometry Subroutines) source code written by George
Kaplan at the U.S. Naval Observatory.
cos za cos a cos a sin za sin a cos za cos a sin a sin za cos a cos za sin a
P sin za cos a cos a cos za sin a sin za cos a sin a cos za cos a sin za sin a
sin a cos a sin a sin a cos a
where the unit of these angular arguments is arc seconds and the time arguments are
In these two equations JED1 is the TDB Julian Date of the first epoch and JED2 is the TDB
Julian Date of the second epoch.
Page 87
Celestial Computing with MATLAB
% input
% output
Page 88
Celestial Computing with MATLAB
where M is the mean anomaly, E is the eccentric anomaly and e is the orbital eccentricity.
The two algorithms based on Professor Danby’s work can also solve the hyperbolic form of
Kepler’s equation.
This section describes a numerical solution devised by Professor J.M.A. Danby at North
Carolina State University. Additional information about this algorithm can be found in “The
Solution of Kepler’s Equation”, Celestial Mechanics, 31 (1983) 95-107, 317-328 and 40
(1987) 303-312.
E0 M 0.85sign sin M e
f E E e sin E M 0
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
En
1
f f
2
f
n En
1 1
f f 2 f
2 6
En 1 En n
Page 89
Celestial Computing with MATLAB
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
sin 1 e2 sin E
cos cos E e
2M
H 0 log 1.8
e
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.
Page 90
Celestial Computing with MATLAB
% Danby's method
% input
% output
This function solves the elliptic and hyperbolic form of Kepler’s equation using Danby’s
method and Mikkola’s 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 Kepler’s 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
2
0.078s15
ds
1 e
1/ 3
z sign 2 2
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
Page 91
Celestial Computing with MATLAB
0.071s5
ds
e 1 0.45s 2 1 4 s 2
H 0 3log s 1 s 2
The syntax for this MATLAB function is
% input
% output
This MATLAB function solves the elliptic form of Kepler’s equation using Gooding’s two
iteration method. This algorithm always performs two, and only two iterations when solving
Kepler’s equation. Additional information about this technique can be found in “Procedures
For Solving Kepler’s Equation”, Celestial Mechanics, 38 (1986) 307-334.
% input
% output
Page 92
Celestial Computing with MATLAB
This MATLAB function solves Kepler’s 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 Barker’s equation and Stumpff functions to solve this problem.
E t e sin E t t t0
a3
where
E eccentric anomaly
e orbital eccentricity
gravitational constant of the Sun
a semimajor axis
t time
t0 time of perihelion passage
q
a
1 e
3ec3 E
U E
1 e
1
U U 3 6ec3 E t t0
3 2q3
2c
r q 1 2 U 2
6c3
Page 93
Celestial Computing with MATLAB
The true anomaly is determined from the x and y components of the heliocentric position
vector as follows:
atan y, x
where
2c
x q 1 2 U 2
6ec3
1 e 1
y 2q
2e 6c3
c1U
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
k
cn x k 0,1,2,
k 0 2k n !
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 sinh x
x x
1 cos x cosh x 1
c2 x 2 c2 x 2
x x
1
xck 2 x ck x k 0,1,2,
k!
For x 0 ,
1
cn x
n!
It is most efficient to compute c2 and c3 by series and then compute c0 and c1 by recursion
according to the following:
Page 94
Celestial Computing with MATLAB
c0 x 1 xc2
c1 x 1 xc3
% input
% output
Please note that the time relative to perihelion passage is in days and the perihelion radius is
in astronomical units.
Page 95
Celestial Computing with MATLAB
Goodyear’s method uses a change of variables that allows one to use a single set of equations
to predict elliptic, hyperbolic and parabolic motion. This change of variables is defined by
1/ r
The relationship between this generalized anomaly and the classical eccentric anomaly E
and hyperbolic anomaly F is given by
E E0 F F0
/a / a
The equations used to calculate the final position vector r and the final velocity vector r
from the initial position and velocity vectors r0 and r0 are as follows:
r0 r0 r0
0 r0 r0
r0 r0 2
r0
The generalized eccentric anomaly and the four transcendental functions given by
2 2 4 3 6
s0 1
2! 4! 6!
3 2 5 3 7
s1
3! 5! 7!
2 4 2 6 3 8
s2
2! 4! 6! 8!
3 5 2 7 3 9
s3
3! 5! 7! 9!
Page 96
Celestial Computing with MATLAB
t t0 r0 s1 0 s2 s3
r r0 s0 0 s2 s3
The f and g functions and their derivatives are calculated with the four equations given by
s2
f 1
r0
s1
f
rr0
g t t0 s3
s2
g 1
r
Finally, the position and velocity vectors at the final time t are computed from the f and g
functions with the next two equations:
r t f r0 g r0
r t f r0 g r0
r
r t 3
r
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
tbcoef = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function.
Page 97
Celestial Computing with MATLAB
% Goodyear's method
% input
% output
% Shepperd's method
% input
% output
x s2
where
Page 98
Celestial Computing with MATLAB
The first three derivatives of this form of Kepler’s equation are given by
The c functions used in these equations are called Stumpff functions. They are named after
the German astronomer Karl Stumpff and are defined by the series
1 x k
k
cn x k 0,1,2,
k 0 2k n !
c0 x 2 cos x c0 x 2 cosh x
c1 x 2 c1 x 2
sin x sinh x
x x
1 cos x cosh x 1
c2 x 2 c2 x 2
x x
1
xck 2 x ck x k 0,1,2,
k!
For x 0,
Page 99
Celestial Computing with MATLAB
1
cn x
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 equations for the f and g functions and derivatives are as follows:
f 1 s 2c2 s 2
r0
g t t0 s 3c3 s 2
f sc1 s 2
rr0
g 1 s 2c2 s 2
r
Finally, the position and velocity vectors at the final time t are given by
r t f r0 g r0
r t f r0 g r0
% Danby/Stumpff method
% input
% output
Page 100
Celestial Computing with MATLAB
This MATLAB function converts a calendar date to its corresponding Julian date. Be sure to
pass this routine all digits of the calendar year.
% Input
% Output
This MATLAB function converts a Julian date to its corresponding calendar date.
% input
% output
This function converts a Julian date to its equivalent calendar date and universal time strings.
Page 101
Celestial Computing with MATLAB
% input
% output
This function converts a Julian date on the coordinated universal time (UTC) time scale to a
Julian date on the terrestrial dynamic time (TDT) scale. It is valid between January 1, 1940
and the near future.
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
itime = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function.
% input
% output
This function converts a Julian date on the terrestrial dynamic time (TDT) also called
terrestrial time TT) time scale to a Julian date on the barycentric dynamic time (TDB) scale.
TDB is the fundamental time argument for the Jet Propulsion Laboratory (JPL) and Bureau
of Longitudes (BDL) ephemerides. The difference between these two time scales can be as
much as 1.6 milliseconds. This difference is periodic with an average of zero.
Page 102
Celestial Computing with MATLAB
% input
% output
This function can be used to convert a floating point argument in hours into its equivalent
degrees, minutes, seconds, and string representation.
% input
% dd = angle in hours
% output
% h = integer hours
% m = integer minutes
% s = seconds
% hmsstr = string equivalent of input
Page 103
Celestial Computing with MATLAB
% input
% a = sine of angle
% b = cosine of angle
% output
modulo.m – modulo 2 pi
% modulo 2 pi function
% input
% x = argument (radians)
% output
% y = x modulo 2 pi
This function calculates a unit vector from a user provided three component vector.
% unit vector
Page 104
Celestial Computing with MATLAB
% input
% output
DIFFERENTIAL EQUATIONS
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
rkcoef = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function. After the first call, the function will set this value to 0.
% Runge-Kutta-Fehlberg 4(5)
% input
% output
Page 105
Celestial Computing with MATLAB
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
rkcoef = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function. After the first call, the function will set this value to 0.
if (xerr > 1)
% reject current step
ti = twrk;
x = xwrk;
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% accept current step %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% perform graphics, additional %
% calculations, etc. at this point %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
When the processing reaches the else statement, a successful integration step has been
completed and additional processing such as graphics or other calculations can be performed
here. For example, the following code performs the rectification required for Encke’s
method.
if (xerr > 1)
% reject current step
ti = twrk;
x = xwrk;
for i = 1:1:6
ytrue(i) = ytbf(i) + x(i);
ytbi(i) = ytrue(i);
x(i) = 0;
end
tsaved = ti;
end
Page 106
Celestial Computing with MATLAB
% input
% output
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
nycoef = 1;
This variable should also be placed in a global statement at the beginning of the main script
that calls this function.
% input
% output
Page 107
Celestial Computing with MATLAB
This MATLAB function evaluates the first-order form of the heliocentric equations of orbital
motion. It includes the point-mass gravity perturbations due to Venus, Earth, Mars, Jupiter
and Saturn. The fundamental coordinate system used in this algorithm is the true-of-date
ecliptic and equinox.
% input
% output
d 2r r p bi rpi
9
rs b
r 2 r, t s 3
pi 3
3
dt rs b i 1 r p b rpi
i
where
s gravitational constant of the Sun
p gravitational constant of planet i
i
rsb rp rpb
Page 108
Celestial Computing with MATLAB
This MATLAB function evaluates the modified equinoctial orbital elements form of the
equations of heliocentric orbital motion.
% input
% output
The perturbation vector used in these calculations is computed in a MATLAB function called
ceqm2.m. The syntax of this function is as follows:
% input
% output
The equations of orbital motion expressed in terms of modified equinoctial orbital elements
are as follows:
Page 109
Celestial Computing with MATLAB
dp 2 p p
p t
dt w
df p g
f r sin L w 1 cos L f t h sin L k cos L n
dt w w
dg p g
g r cos L w 1 sin L g t h sin L k cos L n
dt w w
dh p s 2n
h cos L
dt 2w
dk p s 2n
k sin L
dt 2w
2
dL w 1 p
L p h sin L k cos L n
dt p w
where r , t , n are external perturbations in the radial, tangential and orbit normal
directions, respectively.
This function can be used to bracket a single root of a single nonlinear equation of the form
y f x . It uses a combination of geometric acceleration and rectification to bracket roots.
The basic idea is to find the endpoints of an interval x1 and x2 such that f x1 f x2 0 .
The user must supply this function with an initial guess for x1 and x2 . Typically x1 is the
time of an objective function minimum or maximum and x2 is a time 10 seconds after
(forward root) or 10 seconds before (backward root) the value of x1
The following diagram illustrates this process. The acceleration factor for this example is
0.25 and the rectification interval is 300 seconds. The acceleration factor increases the size of
each step geometrically and the rectification interval monitors the length of the current
bracketing interval. When necessary the rectification logic reinitializes the search and
prevents the interval from becoming too large and skipping one or both ends of the
bracketing interval completely. The process starts at the bottom left, labeled minimum, which
Page 110
Celestial Computing with MATLAB
is the time of the function minimum for this example. The x-axis is the number of steps taken
in the search for the bracketing interval and the y-axis is the elapsed simulation time. The
size of each step increases geometrically until the length of the current step reaches the value
of the rectification interval. At that point, labeled rectification on the plot, the step size is
reset and the process begins again. Eventually, the process will bracket the root, labeled root
on this plot, and the function will return the endpoints x1 and x2 of this bracketing interval.
% input
% output
This function uses Brent’s method to find a single root of a single nonlinear equation of the
form y f x . Derivatives are not required for this algorithm. However, the user should
ensure that a root is bracketed f x1 f x2 0 before calling this routine.
Page 111
Celestial Computing with MATLAB
% Brent's method
% input
% output
This function uses Brent’s method to find a single minimum or maximum of a single user-
defined nonlinear “objective” function.
% Brent's method
% input
% output
Page 112
Celestial Computing with MATLAB
ATMOSPHERIC REFRACTION
This MATLAB function corrects a topocentric elevation angle for atmospheric refraction.
The correction to be added to the “true” or calculated topocentric elevation angle is as
follows:
1.02
E
10.3
tan E
E 5.11
% refraction correction
% input
% output
This MATLAB function determines the effect of atmospheric refraction using the algorithm
included in the NOVAS software suite from the Naval Observatory.
Page 113
Celestial Computing with MATLAB
This MATLAB function determines the effect of atmospheric refraction using an algorithm
that includes the effects of ambient pressure and temperature. The code is based on the
numerical method described in “A New Angular Tropospheric Refraction Model”, by A. L.
Berman and S. T. Rockwell, JPL Deep Space Network Progress Report 42-24.
% input
% output
UTILITY ROUTINES
This function prints a formatted display of the six classical orbital elements with the orbital
period displayed in days. There is also a version of this function called oeprint2.m that
prints the semimajor axis in astronomical units.
function oeprint1(oev)
% input
Page 114
Celestial Computing with MATLAB
This function prints a formatted display of the components and scalar magnitudes of a state
vector (position and velocity vectors and magnitudes).
function svprint(r, v)
% input
This function can be used to convert a floating point argument in degrees into its equivalent
degrees, minutes, seconds, and string representation. For example, the command
[d,m,s,degstr]=deg2dms(22.12345)
% input
% output
% d = integer degrees
% m = integer minutes
% s = seconds
% dmsstr = string equivalent of input
This function interactively requests the calendar date. Please note that all digits of the
calendar year are required.
Page 115
Celestial Computing with MATLAB
% output
% m = calendar month
% d = calendar day
% y = calendar year
The following is the screen display for this function. Please note the valid range of inputs.
The calendar date should be input with individual elements separated by commas.
This function interactively requests the geodetic coordinates of a ground site. Please note that
geodetic latitude and longitude are returned in the units of radians.
% output
The following is a typical user interaction with this function. Please note the sign
conventions and range of valid inputs. North latitudes are positive and south latitudes are
negative. East longitude is positive and west longitude is negative.
Page 116
Celestial Computing with MATLAB
This function interactively requests six classical orbital elements. Please note that all angular
elements are returned from this function in the units of radians. The user can control which
orbital elements are requested by setting the corresponding value of the ioev vector. For
example, the following statement will request all six orbital elements:
oev = getoe([1;1;1;1;1;1])
If the orbital eccentricity input by the user is 0, this function will bypass the prompt for
argument of periapsis (if requested via ioev) and set its value to 0.
% input
% output
% oev(1) = semimajor
% oev(2) = orbital eccentricity
% oev(3) = orbital inclination
% oev(4) = argument of perigee
% oev(5) = right ascension of the ascending node
% oev(6) = true anomaly
This function interactively requests the universal time in hours, minutes and seconds.
% output
The following is the screen prompt displayed by this function. Please note the range of valid
inputs. If invalid data is input the function will redisplay this request.
please input the universal time
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
?
Page 117
Celestial Computing with MATLAB
This MATLAB application demonstrates how to read and plot the MicroWorld Database
binary map files. The Celestial Computing with MATLAB software package includes versions
of these maps for IBM-PC compatible computers. The map features that are plotted by this
utility are defined in the code as follows:
allfeatures = 0;
coastlines = 1;
countries = 0;
states = 0;
islands = 1;
lakes = 0;
rivers = 0;
This MATLAB function will plot an orthographic view of the Earth. The map coordinates
are contained in a file called xyzmap.dat. The Celestial Computing with MATLAB CD ROM
contains a script called demoplot.m that demonstrates how to interact with both the
pltortho and pltrect mapping functions.
Page 118
Celestial Computing with MATLAB
% input
% note
The following is a typical plot created with this function. The viewpoint is 40 degrees north
latitude and 105 degrees west longitude. The latitude and longitude grid spacing for this
example was 30 degrees.
Page 119
Celestial Computing with MATLAB
This function will plot the major features of the Earth on a rectangular map. The map
coordinates are contained in a file called gmapll.dat. The syntax of this function is simply
function pltrect.
Page 120
Celestial Computing with MATLAB
right ascension
declination
ecliptic longitude
ecliptic latitude
A topocentric azimuth
h topocentric altitude
H hour angle
observer's local sidereal time
observer's geodetic latitude
obliquity of the ecliptic
Also, equations involving a two argument inverse tangent denote calculations that are
performed with the four quadrant inverse tangent function atan3.m.
The scalar distance can be determined from the three components of the rectangular position
vector as follows:
rx2 ry2 rz2
The longitudinal polar coordinate is computed using a four quadrant inverse tangent function
as follows:
tan 1 ry , rx
rz
tan 1
rx2 ry2
Page 121
Celestial Computing with MATLAB
% input
% output
The three components of the rectangular position vector are determined from the scalar
distance , the longitudinal polar coordinate and the latitudinal polar coordinate
as follows:
cos cos
r sin cos
sin
% input
% output
The conversion from ecliptic to equatorial coordinates is given by the following two
equations:
tan 1 sin cos tan sin ,cos
Page 122
Celestial Computing with MATLAB
% input
% output
% input
% output
The conversion from equatorial to local horizontal coordinates is given by the following two
expressions:
A tan 1 sin H ,cos H sin tan cos
% input
Page 123
Celestial Computing with MATLAB
% output
% notes
% input
% output
% notes
This MATLAB function can be used to transform angular orbital elements from one equinox
to another. The orbital inclination i , argument of periapsis , and longitude of ascending
node are the only orbital elements that depend on the position of the equinox.
In the equations which follow, i0 , 0 , and 0 are the orbital inclination, longitude of
ascending node and argument of periapsis with respect to the initial equinox. Orbital
Page 124
Celestial Computing with MATLAB
elements without a subscript are with respect to the final equinox. It is important to
remember that these transformed orbital elements are still valid for the same epoch as the
original orbital elements. In other words, this MATLAB function performs a coordinate
transformation, not an epoch transformation.
The spherical trigonometry relationships among these elements are summarized below:
The correction to the argument of perapsis can be calculated from the following two
expressions:
sin sin i sin i0 cos A cos i0 sin A cos A 0
0
This function will accept initial and final equinoxes in the form of Besselian (B1950 for
example) and Julian years (J2000 for example) as well as Julian ephemeris dates (2451545
for example). These equinoxes should be passed to this function as strings.
% input
% output
Page 125
Celestial Computing with MATLAB
rx G1 cos cos
ry G2 cos sin
rz G2 sin
For ECI site coordinates is equal to the local sidereal time, and for ECF coordinates is
equal to the east longitude of the ground site. In these equations is the geodetic latitude of
the ground site. It is positive in the northern hemisphere and negative in the southern
hemisphere.
req
G1 h
1 2 f f 2 sin 2
req 1 f
2
G2 h
1 2 f f 2 sin 2
where
f Earth flattening factor
req Earth equatorial radius
geodetic latitude
h geodetic altitude
% input
Page 126
Celestial Computing with MATLAB
% output
This MATLAB function uses a series solution to convert geocentric distance and declination
to geodetic altitude and latitude. The following diagram illustrates the geometric relationship
between geocentric and geodetic coordinates.
In this diagram, is the geocentric declination, is the geodetic latitude, r is the geocentric
distance, and h is the geodetic altitude. The exact mathematical relationship between
geocentric and geodetic coordinates is given by the following system of two nonlinear
equations
c h cos r cos 0
s h sin r sin 0
req
c
1 2 f f 2 sin 2
s c 1 f
2
and req is the Earth equatorial radius (6378.14 kilometers) and f is the flattening factor for
the Earth (1/298.257).
Page 127
Celestial Computing with MATLAB
sin 2 1 1
f 2 sin 4 f 2
4
1 cos 2
1 1
hˆ rˆ 1 f 1 cos 4 f 2
2 4 16
In these equations, is the geocentric distance of the object, hˆ h / req and rˆ / req .
% series solution
% input
% output
This MATLAB function uses the exact solution of K. M. Borkowski (“Accurate Algorithms
to Transform Geocentric to Geodetic Coordinates”, Bullentin Geodesique, 63 No. 1, 50-56)
to convert geocentric distance and declination to geodetic altitude and latitude. The
calculation steps for this numerical method are as follows:
brz a 2 b2
E
ar
brz a 2 b2
F
ar
r rx2 ry2
Page 128
Celestial Computing with MATLAB
a
b sign rz a
f
The calculations continue with
4
P EF 1
3
Q 2E2 F 2
D P3 Q 2
v D1/ 2 Q
1/ 3
1 2
G E vE
2
F vG
t G 2
2G E
The geodetic latitude is determined from the expression
1 t2
arctan a
2bt
h r at cos rz b sin
% input
% output
Page 129
Celestial Computing with MATLAB
N h cos cos
e
where
req
N
1 e 2 sin 2
e2 2 f f 2
f Earth flattening factor
req Earth equatorial radius
geodetic latitude
e east longitude
h geodetic altitude
The geocentric distance is determined from the components of the geocentric position vector
as follows:
r rx2 ry2 rz2
The geocentric declination can be computed from the z component of the geocentric position
vector with
r
sin 1 z
r
% input
% output
This MATLAB function converts geodetic latitude and altitude to geocentric position
magnitude and geocentric declination.
Page 130
Celestial Computing with MATLAB
sin 2 sin 2 1 1
f sin 4 f 2
ˆ
h 1 2 hˆ 1
2
ˆ
4 h 1
2
ˆ
4 h 1
and
cos 2 1 1
ˆ
ˆ h 1
1
f
1 cos 4 f 2
2
4 hˆ 1 16
where the geocentric distance r and geodetic altitude h have been normalized by ˆ r / req
and hˆ h / r , respectively, and r is the equatorial radius of the Earth.
eq eq
% input
% output
This MATLAB function calculates the geodetic altitude relative to a triaxial ellipsoidal
planet. The algorithm is based on the numerical method described in “Geodetic Altitude to a
Triaxial Ellipsoidal Planet”, by Charles C. H. Tang, The Journal of the Astronautical
Sciences, Vol. 36, No. 3, July-September 1988, pp. 279-283.
This function solves for the real root of the following nonlinear equation:
2
f z p 1
cy cx
z c2 0
2 p
cz b c z p cz a c z p
2
2 2 2 2
where
Page 131
Celestial Computing with MATLAB
cx acxs
2
c y bcy s
2
cz c 2 z s
a, b, c semi-axes a b c
xs , ys , zs geocentric coordinates of satellite
z p z coordinate of subpoint
% input
% output
The semi-axes in this function are “hardwired” to the values a 6378.138 and b 6367
(kilometers), and the flattening factor is f 1/ 298.257 . These are representative values for
the Earth and can be easily changed for other planets or the Moon.
This MATLAB function converts the six classical orbital elements to an inertial state vector
(position and velocity vectors). The rectangular components of the object’s inertial position
vector are determined from
The components of the inertial velocity vector are computed using the following equations:
Page 132
Celestial Computing with MATLAB
vx cos sin e sin sin cos i cos e cos
p
vy sin sin e sin cos cos i cos e cos
p
vz sin i cos e cos
p
where
a semimajor axis
e orbital eccentricity
i orbital inclination
argument of periapsis
right ascension of the ascending node
true anomaly
p a 1 e 2
% input
% output
This MATLAB function converts an inertial state vector (position and velocity vectors) to six
classical orbital elements. The following diagram illustrates the geometry of these orbital
elements.
Page 133
Celestial Computing with MATLAB
where
a semimajor axis
e orbital eccentricity
i orbital inclination
argument of periapsis
right ascension of the ascending node
true anomaly
The semimajor axis defines the size of the orbit and the orbital eccentricity defines the shape
of the orbit. The angular orbital elements are defined with respect to a fundamental x-axis,
the vernal equinox, and a fundamental plane, the ecliptic or the equator. The z-axis of this
system is collinear with either the spin axis of the Earth or the north ecliptic pole, and the y-
axis completes a right-handed coordinate system.
The orbital inclination is the angle between the fundamental plane and the orbit plane. Orbits
with inclinations between 0 and 90 degrees are called direct orbits and objects with
inclinations greater than 90 and less than 180 degrees are called retrograde orbits. The right
ascension of the ascending node (RAAN) is the angle measured from the x-axis (vernal
equinox) eastward along the fundamental plane to the ascending node. The argument of
periapsis is the angle from the ascending node, measured along the orbit plane in the
direction of increasing true anomaly, to the argument of perigee. The true anomaly is the
angle from the argument of perigee, measured along the orbit plane in the direction of
Page 134
Celestial Computing with MATLAB
motion, to the object’s location. Also shown is the argument of latitude, u, which is the angle
from the ascending node, measured in the orbit plane, to the object’s location in the orbit. It
is equal to u .
The orbital eccentricity is an indication of the type of orbit. For values of 0 e 1 , the orbit
is circular or elliptic. The orbit is parabolic when e 1 and the orbit is hyperbolic if e 1
1
a
2 v2
r
where r r rx2 ry2 rz2 and v v vx2 v 2y vz2 . The angular orbital elements are
calculated from the equinoctial orbital elements that are calculated from the ECI position and
velocity vectors.
e h2 k 2
The orbital inclination is determined from p and q using the following expression
i 2 tan 1 p 2 q2
For values of inclination greater than a small value , the right ascension of the ascending
node (RAAN) is given by
tan 1 p, q
Otherwise, the orbit is equatorial and there is no RAAN. If the value of orbital eccentricity is
greater than , the argument of perigapsis is determined from
tan 1 h, k
Otherwise, the orbit is circular and there is no argument of periapsis. In the MATLAB code
for these calculations, 108 .
Page 135
Celestial Computing with MATLAB
In these equations, all two argument inverse tangent functions use the four quadrant function
atan3.m and angular orbital elements which can range from 0 to 360 degrees are also
processed with the modulo 2 function, modulo.m.
% input
% output
This MATLAB function can be used to convert modified equinoctial orbital elements to
classical orbital elements.
% input
% output
Page 136
Celestial Computing with MATLAB
The relationship between modified equinoctial and classical orbital elements is given by
p a 1 e 2
f e cos
g e sin
h tan i 2 cos
k tan i 2 sin
L
where
p semiparameter
a semimajor axis
e orbital eccentricity
i orbital inclination
argument of perigee
right ascension of the ascending node
true anomaly
L true longitude
The relationship between classical and modified equinoctial orbital elements is as follows:
semimajor axis
p
a
1 f 2 g2
orbital eccentricity
e f 2 g2
orbital inclination
i 2 tan 1 h2 k 2
argument of periapsis
tan 1 g f tan 1 k h
Page 137
Celestial Computing with MATLAB
tan 1 k h
true anomaly
L L tan 1 g f
This MATLAB function can be used to convert modified equinoctial orbital elements to ECI
position and velocity vectors.
% input
% output
The relationship between ECI position and velocity vectors and modified equinoctial
elements is defined by the following series of equations:
position vector
r
s 2 cos L cos L 2hk sin L
2
r 2 sin L sin L 2hk cos L
r 2
s
r
h sin L k cos L
s2
velocity vector
Page 138
Celestial Computing with MATLAB
1
2
s p
sin L 2 sin L 2hk cos L g 2 f h k 2 g
1
v 2 cos L 2 cos L 2hk sin L g f 2 gh k 2 f
s p
2
h cos L k sin L f h gk
s2 p
where
2 h2 k 2
s2 1 h2 k 2
p
r
w
w 1 f cos L g sin L
This MATLAB function can be used to convert an ECI state vector (position and velocity
vectors) to modified equinoctial orbital elements.
% input
% output
Page 139
Celestial Computing with MATLAB
This MATLAB function computes the elementary rotation matrix for a user-defined rotation
angle about a user-defined rotation axis. All calculations follow the right-handed rule and
counterclockwise rotation angles are positive.
The three rotation matrices for the x, y and z axes are defined by
1 0 0
Rx 0 cos sin
0 sin cos
cos 0 sin
Ry 0 1 0
sin 0 cos
cos sin 0
Rz sin cos 0
0 0 1
x x
y R y
x
z z
, ,
x x
y R y
x
z z
, ,
The matrix-vector form of the transformation between the equatorial and local horizontal
coordinate systems are as follows:
Page 140
Celestial Computing with MATLAB
x x
y R 180 R 90 y
z y
z z
A, a h ,
x x
y R 90 R 180
y z y
z z
h , A,a
% rotation matrix
% input
% output
Page 141
Celestial Computing with MATLAB
An excellent discussion about the algorithms used in the NOVAS software can be found in
“Mean and Apparent Place Computations in the New IAU System. III. Apparent,
Topocentric, and Astrometric Places of Planets and Stars”, G.H. Kaplan, J.A. Hughes, P.K.
Seidelmann, C.A. Smith and B.D. Yallop, The Astronomical Journal, Vol. 97, No. 4, pages
1197-1210, 1989.
% input
% output
% input
% output
Page 142
Celestial Computing with MATLAB
% input
% output
% input
% output
% input
Page 143
Celestial Computing with MATLAB
% output
% note:
% if tjd is negative, inverse nutation (true to mean) is applied
% input
% output
% note:
% if tjd is negative, inverse nutation (true to mean) is applied
% input
Page 144
Celestial Computing with MATLAB
% output
% note
% tjd = 0 means no precession/nutation transformation
% gast = 0 means no spin transformation
% x = y = 0 means no wobble transformation
% input
% output
% purpose
% references
% input
% tjd = julian date of the desired time, on the tdb time scale
% body = body identification number for the
% solar system object of interest;
% mercury = 1,...,pluto = 9, sun = 10, moon = 11
% origin = origin code; solar system barycenter = 0,
% center of mass of the sun = 1
% output
Page 145
Celestial Computing with MATLAB
% input
% output
% input
% output
Page 146
Celestial Computing with MATLAB
% input
% output
% input
% output
function [pos, vel] = vectrs (ra, dec, pmra, pmdec, parllx, rv)
% input
% output
Page 147
Celestial Computing with MATLAB
% input
% output
Page 148
Celestial Computing with MATLAB
Bretagnon, P., and Simon, J., Planetary Programs and Tables from –4000 to +2800,
Willmann-Bell, 1986.
Brouwer, D., and Clemence, G., Methods of Celestial Mechanics, Academic Press, 1961.
Chapront, J., and Chapront-Touze, M., Lunar Tables and Programs from 4000 B.C. to A.D.
8000, Willmann-Bell, 1991.
Dormand, J. R., Numerical Methods for Differential Equations, CRC Press, 1996.
Forsythe, G. E., Malcolm, M. A., and Moler, C. B., Computer Methods for Mathematical
Computations, Prentice-Hall, 1977.
Meeus, J., Tables of the Sun, Moon and Planets, Willmann-Bell, 1995.
Montenbruck, O., and Pfleger, T., Astronomy on the Personal Computer, Springer-Verlag,
1994.
Page 149
Celestial Computing with MATLAB
Page 150