This action might not be possible to undo. Are you sure you want to continue?
Celestial Computing
with MATLAB
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
Zero Relative Velocity Curves for Mass Ratio = 0.2
x coordinate
y
c
o
o
r
d
i
n
a
t
e
Copyright © 19982009 by Science Software. All rights reserved.
Celestial Computing with MATLAB
INTRODUCTION ....................................................................................................... 7
1. RISE AND SET OF THE SUN, MOON AND PLANETS........................................ 9
2. LUNAR ECLIPSES.............................................................................................. 17
3. LUNAR OCCULTATIONS................................................................................... 20
4. SOLAR ECLIPSES.............................................................................................. 23
5. TRANSITS OF MERCURY AND VENUS............................................................ 25
6. CLOSEST APPROACH BETWEEN THE EARTH AND HELIOCENTRIC
OBJECTS................................................................................................................ 28
7. EQUINOXES AND SOLSTICES.......................................................................... 31
8. COWELL’S METHOD FOR HELIOCENTRIC ORBITS....................................... 32
cowell1.m – rectangular position and velocity vector formulation ................................................................32
cowell2.m – modified equinoctial orbital elements formulation.....................................................................34
9. ENCKE’S METHOD FOR HELIOCENTRIC ORBITS.......................................... 39
10. THE CIRCULARRESTRICTED THREEBODY PROBLEM............................. 43
crtbp1.m – coordinates and energy of the libration points .............................................................................44
g3body.m – graphics display of threebody motion.........................................................................................46
zvcurve1.m – graphics display of zero velocity curves through equilibrium points.....................................49
zvcurve2.m – graphics display of userdefined zero relative velocity curves ................................................51
11. APPARENT COORDINATES OF A PLANET OR THE MOON ........................ 55
12. APPARENT COORDINATES OF A STAR........................................................ 59
13. JPL DE405 LUNAR, SOLAR AND PLANETARY EPHEMERIS....................... 62
14. SLP96 LUNAR, SOLAR AND PLANETARY EPHEMERIS .............................. 65
Page 1
Celestial Computing with MATLAB
15. OTHER LUNAR, SOLAR AND PLANETARY EPHEMERIS ALGORITHMS.... 69
sun.m – solar ephemeris.....................................................................................................................................69
moon.m – lunar ephemeris ................................................................................................................................70
mercury.m – Mercury ephemeris......................................................................................................................70
venus.m – Venus ephemeris...............................................................................................................................71
earth.m – Earth ephemeris ................................................................................................................................71
mars.m – Mars ephemeris .................................................................................................................................71
jupiter.m – Jupiter ephemeris ...........................................................................................................................72
saturn.m – Saturn ephemeris ............................................................................................................................72
uranus.m – Uranus ephemeris...........................................................................................................................72
neptune.m – Neptune ephemeris .......................................................................................................................73
pluto.m – Pluto ephemeris .................................................................................................................................73
sun1.m – precision Sun ephemeris ....................................................................................................................74
elp2000.m – osculating orbital elements of the moon......................................................................................76
planet1.m – mean ecliptic and equinox of data planetary ephemeredes........................................................78
planet2.m – mean ecliptic and equinox of J2000 planetary ephemerides......................................................79
seleno.m – selenographic coordinate transformation......................................................................................80
16. APPARENT GREENWICH SIDEREAL TIME ................................................... 81
gast.m – low precision ........................................................................................................................................81
gast1.m – full precision.......................................................................................................................................82
gast2.m – DE405 nutations ................................................................................................................................83
17. IAU 1980 NUTATION IN LONGITUDE AND OBLIQUITY ................................ 85
18. PRECESSION TRANSFORMATION ................................................................ 87
19. KEPLER’S EQUATION..................................................................................... 89
kepler1.m – Danby’s method.............................................................................................................................89
kepler2.m – Danby’s method with Mikkola’s initial guess .............................................................................91
Page 2
Celestial Computing with MATLAB
kepler3.m – Gooding’s two iteration method...................................................................................................92
kepler4.m – parabolic and nearparabolic orbits ............................................................................................93
20. TWOBODY ORBITAL MOTION....................................................................... 96
twobody1.m – Goodyear’s method....................................................................................................................96
twobody2.m – Sheppard’s method....................................................................................................................98
twobody3.m – Stumpff/Danby method.............................................................................................................98
21. TIME AND DATE FUNCTIONS....................................................................... 101
julian.m – calendar date to Julian date ..........................................................................................................101
gdate.m – julian date to calendar date............................................................................................................101
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
hrs2hms.m – convert hours function ..............................................................................................................103
22. NUMERICAL METHODS AND UTILITY ROUTINES...................................... 104
TRIGONOMETRY AND VECTOR ROUTINES.........................................................................................104
atan3.m – four quadrant inverse tangent .......................................................................................................104
modulo.m – modulo 2 pi...................................................................................................................................104
uvector.m – unit vector ....................................................................................................................................104
DIFFERENTIAL EQUATIONS.....................................................................................................................105
rkf45.m – RungeKuttaFehlberg 4(5) method for firstorder systems .......................................................105
rkf78.m – RungeKuttaFehlberg 7(8) method for firstorder systems .......................................................105
nym4.m – Nystrom fourthorder method for secondorder systems............................................................107
ceqm1.m – firstorder heliocentric equations of orbital motion...................................................................108
meeeqm.m – modified equinoctial equations of motion ................................................................................109
ROOTFINDING AND OPTIMIZATION....................................................................................................110
broot.m – bracket a single root of a nonlinear function................................................................................110
brent.m – solve for a single root of a nonlinear function ..............................................................................111
Page 3
Celestial Computing with MATLAB
minima.m – onedimensional minimization ...................................................................................................112
oevent1.m – find minimization/root finding orbital event ............................................................................112
ATMOSPHERIC REFRACTION..................................................................................................................113
refract.m – refraction correction function .....................................................................................................113
refract1.m – NOVAS refraction correction function.....................................................................................113
refract2.m – refraction correction function including temperature/pressure effects.................................114
UTILITY ROUTINES .....................................................................................................................................114
oeprint1.m – formatted classical orbital elements screen display ................................................................114
svprint.m – formatted state vector screen display.........................................................................................115
deg2dms.m – convert degrees function...........................................................................................................115
INTERACTIVE REQUEST OF PROGRAM INPUTS................................................................................115
getdate.m – request calendar date...................................................................................................................115
getobs.m – request observer coordinates........................................................................................................116
getoe.m – request classical orbital elements ...................................................................................................117
gettime.m – request universal time .................................................................................................................117
RECTANGULAR AND ORTHOGRAPHIC GRAPHICS...........................................................................118
demomwdb.m – MicroWorld Database map files .........................................................................................118
pltortho.m – plot orthographic view of the Earth..........................................................................................118
pltrect.m – plot rectangular map of the Earth...............................................................................................120
23. ASTRONOMICAL COORDINATES................................................................ 121
rec2pol.m – rectangular to polar coordinate conversion ..............................................................................121
pol2rec.m – polar to rectangular coordinate conversion ..............................................................................122
ecl2equ.m – ecliptic to equatorial coordinate conversion..............................................................................122
equ2ecl.m – equatorial to ecliptic coordinate conversion..............................................................................123
equ2hor.m – equatorial to local horizontal coordinate conversion..............................................................123
hor2equ.m – local horizontal to equatorial coordinate conversion..............................................................124
oepreces.m – transform angular orbital elements from one equinox to another ........................................124
Page 4
Celestial Computing with MATLAB
gsite.m – ground site position vector...............................................................................................................126
geodet1.m – convert geocentric coordinates to geodetic coordinates  series solution................................127
geodet2.m – convert geocentric coordinates to geodetic coordinates – exact solution................................128
geodet3.m – convert geodetic coordinates to ECF position vector...............................................................129
geodet4.m – convert geodetic coordinates to geocentric coordinates...........................................................130
triaxial.m – geodetic altitude to a triaxial ellipsoid........................................................................................131
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
rotmat.m – fundamental rotation matrix .......................................................................................................140
24. NOVAS ROUTINES......................................................................................... 142
aberat.m – correction for the aberration of light...........................................................................................142
etilt1.m – orientation quantities based on DE405..........................................................................................142
etilt2.m – orientation quantities based on IAU 1980 nutation......................................................................143
geocen.m – move coordinates origin to the Earth centerofmass................................................................143
nutate1.m – nutation transformation..............................................................................................................143
nutate2.m – nutation transformation..............................................................................................................144
pnsw.m – Earthfixed to spacefixed transformation....................................................................................144
propmo.m – apply proper motion correction.................................................................................................145
solsys.m – interface to JPL ephemerides ........................................................................................................145
spin.m – rotating to nonrotating transformation .........................................................................................146
sunfld.m – correct for the deflection of light ..................................................................................................146
tdtimes.m – compute TDT julian date ............................................................................................................146
terra.m – position and velocity vectors of a terrestrial observer..................................................................147
vectrs.m – convert angular quantities to vectors ...........................................................................................147
Page 5
Celestial Computing with MATLAB
wobble.m – polar motion correction...............................................................................................................148
25. BIBLIOGRAPHY AND REFERENCES ........................................................... 149
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:
 Rise and Set of the Sun, Moon and Planets
 Lunar and Solar Eclipses
 Lunar Occultations
 Transits of Mercury and Venus
 Equinoxes and Solstices
 The CircularRestricted ThreeBody Problem
 Cowell’s and Encke’s Method for Heliocentric Objects
 Apparent Coordinates of the Sun, Moon, Planets and Stars
 Kepler’s Equation
 Twobody Orbital Motion
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:
 Date and time routines
 Lunar, solar and planetary ephemerides
 Astronomical Coordinates and Transformations
 Rootfinding and optimization
 Differential equations of heliocentric orbital motion
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
Celestial Computing with MATLAB requires MATLAB version 5.3 or higher.
MATLAB is a registered trademark of The Mathworks, Inc.
Windows is a registered trademark of Microsoft Corporation
Page 7
Celestial Computing with MATLAB
Page 8
Celestial Computing with MATLAB
1. Rise and Set of the Sun, Moon and Planets
This MATLAB script (riseset.m) determines rise and set conditions of the Sun, Moon and
planets. This software uses a combination of onedimensional minimization and rootfinding
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:
(1) locate an extrema using the functions oevent1 and minima
(2) bracket a “forward” and “backward” root using the function broot
(3) find each root using the function brent
(4) calculate the event circumstances using the function events1
(5) display the event circumstances using the function rsfunc
The main MATLAB function that solves this problem has the following syntax and
arguments:
function oevent1 (objfunc, prtfunc, ti, tf, dt, dtsml)
% predict minimization/rootfinding events
% input
% objfunc = objective function
% prtfunc = display results function
% ti = initial simulation time
% tf = final simulation time
% dt = step size used for bounding minima
% dtsml = small step size used to determine whether
% the function is increasing or decreasing
The name of the userdefined objective function (objfunc) and a function that prints the
important results (prtfunc) is passed to this routine in the argument list.
Choosing the Search Parameters
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 . 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.
( ) y f x =
During the search process the oevent1 function calls a MATLAB function called minima
that calculates the extremum of a onedimensional userdefined objective function. The
syntax of this optimization function is as follows:
function [xmin, fmin] = minima (f, a, b, tolm)
% onedimensional minimization
% Brent's method
% input
% f = objective function coded as y = f(x)
% a = initial x search value
% b = final x search value
% tolm = convergence criterion
% output
% xmin = minimum x value
% fmin = minimum function value
This function in turn requires an objective function coded as fx = objfunc(x) where
objfunc is the name of the userdefined objective function, x is the current function
argument and fx is the objective function evaluated at x. For this script the objective function
is equal to the topocentric elevation angle of the body. A numerical value of 1e4 for the
convergence criterion should be adequate for most userdefined objective functions.
The source code of the objective function for this example is as follows:
function fx = rsfunc(x)
% topocentric elevation angle
% objective function
% input
% x = elpased simulation time (days)
% output
% fx = objective function at x
% Celestial Computing with MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global jdatei itarg icent rootflg
global obslat glon glat ht stlocl
Page 10
Celestial Computing with MATLAB
global aunit elevation azimuth
rtd = 180 / pi;
dtr = pi / 180;
jdutc = jdatei + x;
jdtdt = utc2tdt(jdutc);
[ra, dec, dis] = applan1(jdtdt, jdutc, itarg, icent, 1, glon, glat, ht);
% apparent hour angle
hangle = stlocl  (2 * pi * ra / 24);
% topocentric elevation (degrees)
elevation = rtd * asin(sin(obslat) * sin(dtr * dec) ...
+ cos(obslat) * cos(dtr * dec) * cos(hangle));
% topocentric azimuth (degrees)
tmp1 = sin(hangle);
tmp2 = cos(hangle) * sin(obslat)  tan(dtr * dec) * cos(obslat);
azimuth = mod(180 + rtd * atan3(tmp1, tmp2), 360);
if (rootflg == 1)
% correct for horizontal refraction
dref = (34 / 60);
if (itarg == 11)
% correct for semidiameter of the moon
tsdia = rtd * asin((1738 / aunit) / dis);
elseif (itarg == 10)
% correct for semidiameter of the sun
tsdia = rtd * asin((0.5 * 696000 / aunit) / dis);
else
% no semidiameter correction for planets
tsdia = 0;
end
else
dref = 0;
tsdia = 0;
end
% evaluate objective function
fx = (elevation + tsdia + dref);
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 rootfinding 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)
% compute and display celestial events
% input
% objfunc = objective function
% prtfunc = display results function
% ti = initial simulation time
% tf = final simulation time
% topt = extrema time
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 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
( ) y f x =
1
x and
2
x such
that . This condition guarantees that there is at least one root in the interval
because the objective function changes sign.
( ) (
1 2
f x f x ) 0 <
The user must supply this function with an initial guess for
1
x and
2
x . Typically
1
x is the
time of an objective function minimum or maximum and
2
x is a time 0.05 days after
(forward root) or 0.05 days before (backward root) the value of
1
x . The sign of this delta
tells the algorithm in which direction to move.
The name of the userdefined objective function f is passed to this routine in the argument
list. For the riseset script the userdefined (and coded) objective function is called rsfunc.
The syntax of this MATLAB function is as follows:
function [x1out, x2out] = broot (f, x1in, x2in, factor, dxmax)
% bracket a single root of a nonlinear equation
% input
% f = objective function coded as y = f(x)
Page 12
Celestial Computing with MATLAB
% x1in = initial guess for first bracketing x value
% x2in = initial guess for second bracketing x value
% factor = acceleration factor (nondimensional)
% dxmax = rectification interval
% output
% x1out = final value for first bracketing x value
% x2out = final value for second bracketing x value
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 . Derivatives are not required for this algorithm. However, the user should
ensure that a root is bracketed,
( ) y f x =
( ) ( )
1 2
0 f x f x < , before calling this routine. Additional
information about this numerical method can be found in Algorithms for Minimization
Without Derivatives, R. P. Brent, PrenticeHall, 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.
The syntax of this MATLAB function is as follows:
function [xroot, froot] = brent (f, x1, x2, rtol)
% solve for a single real root of a nonlinear equation
% Brent's method
% input
% f = objective function coded as y = f(x)
% x1 = lower bound of search interval
% x2 = upper bound of search interval
% rtol = algorithm convergence criterion
% output
% xroot = real root of f(x) = 0
% froot = function value at f(x) = 0
Page 13
Celestial Computing with MATLAB
The rootfinding performance of this algorithm is determined by rtol. A value of 1.0e8
should be adequate for most problems. Smaller values will predict roots more accurately at
the expense of longer program execution times.
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.
rise and set of the sun, moon or planets
please input an initial UTC calendar date
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1998
please input the search duration (days)
? 5
target body menu
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Sun
<11> Moon
please select the target body
? 11
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 40,0,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 105,0,0
please input the altitude of the ground site (meters)
Page 14
Celestial Computing with MATLAB
(positive above sea level, negative below sea level)
? 0
rise and set conditions
'Moon'
observer latitude +40d 00m 00.00s
observer east longitude 105d 00m 00.00s
observer altitude 0.0000 meters
rise conditions
calendar date 01Jan1998
universal time 16:27:02
UTC Julian date 2450815.1854
azimuth angle +107d 16m 34.84s
elevation angle +00d 50m 08.02s
< please press any key to continue >
maximum elevation conditions
calendar date 01Jan1998
universal time 21:55:47
UTC Julian date 2450815.4137
azimuth angle +180d 44m 55.48s
elevation angle +36d 55m 51.41s
< please press any key to continue >
set conditions
calendar date 02Jan1998
universal time 03:25:20
UTC Julian date 2450815.6426
azimuth angle +254d 49m 56.04s
elevation angle +00d 50m 09.37s
event duration +10h 58m 17.6827s
< please press any key to continue >
rise conditions
Page 15
Celestial Computing with MATLAB
calendar date 02Jan1998
universal time 17:07:18
UTC Julian date 2450816.2134
azimuth angle +102d 17m 18.07s
elevation angle +00d 50m 10.40s
< please press any key to continue >
maximum elevation conditions
calendar date 02Jan1998
universal time 22:49:50
UTC Julian date 2450816.4513
azimuth angle +180d 53m 01.40s
elevation angle +40d 55m 36.02s
< please press any key to continue >
set conditions
calendar date 03Jan1998
universal time 04:33:46
UTC Julian date 2450816.6901
azimuth angle +260d 17m 02.22s
elevation angle +00d 50m 10.77s
event duration +11h 26m 27.6213s
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.
This script uses a combination of onedimensional minimization and rootfinding to solve
this classic problem. The objective function used in these calculations involves the geocentric
separation angle between the center of the Moon and the antiSun position vector or shadow
axis, and the semidiameter and horizontal parallax of the Sun and Moon. This function is
given by the following expression:
( )
( )
1
1
ˆ ˆ
cos
m s m
f t f
÷
s = ÷  ÷ + U U
where
( )
1 1
1
ˆ
geocentric unit position vector of the Sun
ˆ
geocentric unit position vector of the Moon
1.02 size of penumbra shadow
0.99834 corrected parallax
horizontal parallax of the Mo
s
m
s s
m
m
f s t t
t t
t
=
=
= + + =
= =
=
U
U
on
horizontal parallax of the Sun
semidiameter of the Moon
semidiameter of the Sun
s
m
s
s
s
t =
=
=
If we let o 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
1.02
s s m
s s o t t < + + +
A partial lunar eclipse will happen whenever the following is true:
( )
1
1.02
s s m
s s o t t < + ÷ +
The geometric condition for a total lunar eclipse is given by
( )
1
1.02
s s m
s s o t t < + ÷ ÷
In these expressions
Page 17
Celestial Computing with MATLAB
1 1
1 1
sin sin
sin sin
eq eq
m s
m s
m s
m s
m s
r r
d d
r r
s s
d d
t t
÷ ÷
÷ ÷
  
= =

\ . \
   
= =
 
\ . \ .


.
where is the equatorial radius of the Earth (6378.14 kilometers), is the radius of the
Moon (1738 kilometers),
eq
r
m
r
s
r is the radius of the Sun (696,000 kilometers), is the
geocentric distance of the Moon and
m
d
s
d 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
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 11,1,1993
please input the search duration (days)
? 30
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 40,0,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 105,0,0
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 0
working ...
total lunar eclipse
begin penumbral phase of lunar eclipse
calendar date 29Nov1993
universal time 03:27:08
UTC Julian date 2449320.6438
lunar azimuth angle +99d 45m 53.83s
lunar elevation angle +43d 53m 09.29s
< please press any key to continue >
working ...
Page 18
Celestial Computing with MATLAB
greatest eclipse conditions
calendar date 29Nov1993
universal time 06:26:13
UTC Julian date 2449320.7682
lunar azimuth angle +164d 18m 16.73s
lunar elevation angle +70d 13m 39.01s
< please press any key to continue >
working ...
end penumbral phase of lunar eclipse
calendar date 29Nov1993
universal time 09:25:00
UTC Julian date 2449320.8924
lunar azimuth angle +250d 53m 05.61s
lunar elevation angle +52d 24m 42.53s
event duration +05h 57m 51.8379s
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.
This script uses a combination of onedimensional minimization and rootfinding to solve
this problem. The objective function used in these calculations is the topocentric separation
angle between the center of the Moon and the object being occulted. This function is given
by the following expression:
( )
( )
( )
1
ˆ ˆ
cos
m b m b
f t s
÷
=  ÷ + U U s
where
ˆ
topocentric unit position vector of the Moon
ˆ
topocentric unit position vector of the object
semidiameter of the Moon
semidiameter of the object
m
b
m
b
s
s
=
=
=
=
U
U
The semidiameter of the Moon is given by
1
sin
m
m
m
r
s
d
÷
 
=

\ .
where is the radius of the Moon (1738 kilometers) and is the topocentric distance of
the Moon. The semidiameter of a star is zero and the semidiameter of a planet is
m
r
m
d
0
p
p
p
s
s
r
=
where is the semidiameter of the planet at a distance of 1 astronomical unit and is the
topocentric distance of the planet.
0
p
s
p
r
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
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 2,1,1987
please input the search duration (days)
? 30
Page 20
Celestial Computing with MATLAB
target body menu
<1> Mercury
<2> Venus
<3> Mars
<4> Jupiter
<5> Saturn
<6> Uranus
<7> Neptune
<8> Pluto
<9> Star
please select the target body
? 9
please input the star data file name
(be sure to include the file name extension)
? spica.dat
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 39,45,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 104,58,48
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 0
working ...
begin lunar occultation
calendar date 18Feb1987
universal time 12:27:04
UTC Julian date 2446845.0188
lunar azimuth angle +214d 02m 41.91s
lunar elevation angle +32d 52m 22.10s
< please press any key to continue >
working ...
end lunar occultation
calendar date 18Feb1987
universal time 13:17:46
UTC Julian date 2446845.0540
lunar azimuth angle +226d 06m 05.32s
Page 21
Celestial Computing with MATLAB
lunar elevation angle +26d 31m 56.13s
event duration +00h 50m 41.6772s
< please press any key to continue >
The following is the star data file used in this example.
star name
SPICA
J2000 right ascension (hours)
13.4198852780
J2000 declination (degrees)
11.1613083330
J2000 proper motion in right ascension (seconds/Julian century)
0.2780
J2000 proper motion in declination (arcseconds/Julian century)
2.8300
parallax (arcseconds)
0.0210
radial velocity (kilometers/second)
1.0
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.
This script uses a combination of onedimensional minimization and rootfinding to solve
this problem. The objective function used in these calculations is the selenocentric separation
angle between the axis of the shadow cast by the Moon and an Earth observer. This function
is given by the following expression:
( )
( )
1
ˆ ˆ
cos
axis m o p
f t ¢
÷
÷
=  ÷ U U
where
ˆ
selenocentric unit vector of the Moon's shadow
ˆ
selenocentric unit position vector of the observer
penumbra shadow angle
axis
m o
p
¢
÷
=
=
=
U
U
The penumbra shadow angle at the distance of the Earth observer is determined from
1 1
sin sin
m s
p
m m
r r
d d
m
s
r
¢
÷ ÷
÷
   +
= +

\ . \


.
In this expression is the radius of the Moon,
m
r
s
r is the radius of the Sun, is the
topocentric distance of the Moon and
m
d
m s
d
÷
is the distance from the Moon to the Sun.
The selenocentric position vector of the Sun is computed from the expression
m s s m ÷
= ÷ R R R
where
s
R is the geocentric position vector of the Sun and is the geocentric position
vector of the Moon.
m
R
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
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 5,1,1994
please input the search duration (days)
Page 23
Celestial Computing with MATLAB
? 30
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 33,57,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 6,50,0
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 0
working ...
begin penumbral phase of solar eclipse
calendar date 10May1994
universal time 17:50:46
UTC Julian date 2449483.2436
lunar azimuth angle +280d 49m 06.97s
lunar elevation angle +15d 58m 45.39s
< please press any key to continue >
working ...
greatest eclipse conditions
calendar date 10May1994
universal time 18:58:15
UTC Julian date 2449483.2904
lunar azimuth angle +289d 25m 24.94s
lunar elevation angle +02d 55m 27.28s
< please press any key to continue >
working ...
end penumbral phase of solar eclipse
calendar date 10May1994
universal time 19:59:20
UTC Julian date 2449483.3329
lunar azimuth angle +297d 56m 19.07s
lunar elevation angle 08d 14m 55.69s
event duration +02h 08m 34.2403s
Page 24
Celestial Computing with MATLAB
5. Transits of Mercury and Venus
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.
This script uses a combination of onedimensional minimization and rootfinding to solve
this problem. The objective function used in these calculations is the topocentric separation
angle between the center of the Sun and the planet in transit. This function is given by the
following expression:
( )
( ) ( )
1
ˆ ˆ
cos
s p s p
f t s
÷
=  ÷ + U U s
where
ˆ
topocentric unit position vector of the Sun
ˆ
topocentric unit position vector of the planet
semidiameter of the Sun
semidiameter of the planet
s
p
s
p
s
s
=
=
=
=
U
U
During the search for minimum separation angles, the software also checks to see if the
planet is between the observer and the Sun.
The semidiameter of the Sun is given by
1
sin
s
s
s
r
s
d
÷
 
=

\ .
where
s
r is the radius of the Sun (696,000 kilometers) and
s
d is the topocentric distance of
the Sun. The semidiameter of Mercury and Venus is determined from the expression
0
p
p
p
s
s
r
=
where is the semidiameter of the planet at a distance of 1 astronomical unit and 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.
0
p
s
p
r
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
transits of Mercury and Venus
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 6,1,2012
please input the search duration (days)
? 30
target body menu
<1> Mercury
<2> Venus
please select the target body
? 2
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 38,55,17
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 77,3,56
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 84
working ...
ingress  exterior contact  Venus
calendar date 05Jun2012
universal time 22:03:45
UTC Julian date 2456084.4193
azimuth angle of the sun +279d 05m 05.27s
elevation angle of the sun +25d 56m 12.81s
< please press any key to continue >
working ...
least distance of the Sun and Venus
calendar date 06Jun2012
universal time 01:26:18
UTC Julian date 2456084.5599
azimuth angle of the sun +309d 48m 31.41s
elevation angle of the sun 09d 40m 16.84s
Page 26
Celestial Computing with MATLAB
< please press any key to continue >
working ...
egress  exterior contact  Venus
calendar date 06Jun2012
universal time 04:51:00
UTC Julian date 2456084.7021
azimuth angle of the sun +355d 50m 23.84s
elevation angle of the sun 28d 16m 44.34s
event duration +06h 47m 15.4074s
Page 27
Celestial Computing with MATLAB
6. Closest Approach Between the Earth and Heliocentric Objects
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 pointmass 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.
The secondorder heliocentric equations of motion of a satellite or celestial body subject to
the point mass gravitational attraction of the Sun and planets are given by
( )
( )
( )
2 9
3 3 2
1
,
i i
i
i
i
p b
p
s b
s p
i
s b
p
p b
d
t
dt
µ µ
÷
÷
=
÷
÷
 

= = ÷ ÷ +


\ .
¿
r
r
r r
r r
r
r
r
3
where
gravitational constant of the Sun
gravitational constant of planet
position vector from the Sun to planet
position vector from the Sun to the body
position vector from the plane
i
s
p
p
s b
p b
i
µ
µ
÷
÷
=
=
=
=
=
r
r
r t to the body
These position vectors are related according to
s b p p b ÷ ÷
= + r r r
This program uses the RungeKuttaFehlberg 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 8
th
order error estimate that is used to dynamically change the integration step size
during the simulation.
This software also uses a onedimensional 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, PrenticeHall,
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 calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
10,20,1998
initial TDB
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
0,0,0
initial semimajor axis (AU)
(semimajor axis > 0)
0.1441779254846407D+01
initial orbital eccentricity (nondimensional)
(0 <= eccentricity < 1)
0.4836740409964595D+00
initial orbital inclination (J2000 equator and equinox)
(degrees; 0 <= inclination <= 180)
0.2017287833484568D+02
initial argument of perihelion (J2000 equator and equinox)
(degrees; 0 <= argument of perihelion <= 360)
0.3228014264370198D+03
initial right ascension of the ascending node (J2000 equator and equinox)
(degrees; 0 <= raan <= 360)
0.3533298230482567D+03
initial mean anomaly (J2000 equator and equinox)
(degrees; 0 <= mean anomaly <= 360)
0.2708752703925974D+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
< please press any key to continue >
please input the name of the data file
(be sure to include the file name extension)
? xf11.dat
please input the search duration (days)
? 2000
would you like to enforce a minimum distance constraint (y = yes, n = no)
? y
please input the minimum distance constraint (AU)
? .1
please select the ephemeris source (1 = DE405, 2 = SLP96)
? 1
The software will display the initial conditions as follows:
initial heliocentric orbital elements
(J2000/ICRF equinox and equator)
sma (au) eccentricity inclination (deg) argper (deg)
1.4417792548e+000 4.8367404100e001 2.0172878335e+001 3.2280142644e+002
raan (deg) true anomaly (deg) arglat (deg) period (days)
3.5332982305e+002 2.2165440865e+002 1.8445583509e+002 7.3186814210e003
< please press any key to continue >
DE405 ephemeris
time and conditions at closest approach
calendar date 31Oct2002
TDB time 00:26:38
TDB Julian date 2452578.5185
geocentric distance 0.06350013 AU
geocentric distance 9499483.83935515 km
heliocentric orbital elements
(J2000/ICRF equinox and equator)
sma (au) eccentricity inclination (deg) argper (deg)
1.4422695673e+000 4.8412378833e001 2.0165272969e+001 3.2279202361e+002
raan (deg) true anomaly (deg) arglat (deg) period (days)
3.5334764382e+002 7.7110770918e+001 3.9902794530e+001 7.3224150847e003
< please press any key to continue >
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
7. Equinoxes and Solstices
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 rootfinder 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
u ì ÷ , where
for the summer solstice, for the winter solstice and 90 u =
270 u =
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.
time of the equinoxes and solstices
please input the calendar year
? 2000
time of the equinoxes and solstices
spring equinox
calendar date 20Mar2000
dynamical time 07:36:11
summer solstice
calendar date 21Jun2000
dynamical time 01:48:48
fall equinox
calendar date 22Sep2000
dynamical time 17:28:45
winter solstice
calendar date 21Dec2000
dynamical time 13:38:30
Page 31
Celestial Computing with MATLAB
8. Cowell’s Method for Heliocentric Orbits
cowell1.m – rectangular position and velocity vector formulation
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.
The secondorder heliocentric equations of motion of a satellite or celestial body subject to
the point mass gravitational attraction of the Sun and planets are given by
( )
( )
( )
2 9
3 3 2
1
,
i i
i
i
i
p b
p
s b
s p
i
s b
p
p b
d
t
dt
µ µ
÷
÷
=
÷
÷
 

= = ÷ ÷ +


\ .
¿
r
r
r r
r r
r
r
r
3
where
gravitational constant of the Sun
gravitational constant of planet
position vector from the Sun to planet
position vector from the Sun to the body
position vector from the plane
i
s
p
p
s b
p b
i
µ
µ
÷
÷
=
=
=
=
=
r
r
r t to the body
These position vectors are related according to
s b p p b ÷ ÷
= + r r r
The following data file defines a simulation for Halley’s comet.
calendar date of perihelion passage
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
2,9,1986
universal time of perihelion passage
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
15,52,14.592
perihelion radius (Astronomical Units)
(perihelion radius > 0)
0.587478
orbital eccentricity (nondimensional)
(0 <= eccentricity < 1)
0.967329
orbital inclination (degrees)
(0 <= inclination <= 180)
Page 32
Celestial Computing with MATLAB
162.2486
argument of perigee (degrees)
(0 <= argument of perigee <= 360)
111.8114
right ascension of the ascending node (degrees)
(0 <= raan <= 360)
58.1291
The syntax of the MATLAB function that reads this file is as follows:
function [fid, oev1, jdpp] = readoe2(filename)
% read orbital elements data file
% required by encke.m and cowell2.m
% input
% filename = name of orbital element data file
% 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
The following is a typical user interaction with this script.
program cowell1
< heliocentric orbit propagation using Cowell's method >
< please press any key to continue >
simulation data menu
<1> user input
<2> data file
? 2
please input the simulation data file name
(be sure to include the file name extension)
? halley.dat
initial calendar date and universal time
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1986
please input the universal time
Page 33
Celestial Computing with MATLAB
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 0,0,0
please input the simulation period (days)
? 120
please input the algorithm error tolerance
(a value of 1.0e10 is recommended)
? 1e8
The following is the output created for this example:
program cowell1
< heliocentric orbital motion  Cowell's method >
final conditions
calendar date 01May1986
universal time 00:00:00
sma (km) eccentricity inclination (deg) argper (deg)
2.6903161323e+009 9.6733201594e001 1.6224898626e+002 1.1181332479e+002
raan (deg) true anomaly (deg) arglat (deg) period (days)
5.8130641784e+001 1.0750909426e+002 2.1932241905e+002 2.7855777571e+004
perihelion radius 5.8748967570e001 AU
cowell2.m – modified equinoctial orbital elements formulation
This MATLAB script (cowell2.m) determines the longterm 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.
The following is a typical user interaction with this script.
program cowell2
< heliocentric orbit propagation using Cowell's method >
simulation data menu
<1> user input
<2> data file
? 2
please input the simulation data file name
(be sure to include the file name extension)
Page 34
Celestial Computing with MATLAB
? halley.dat
initial calendar date and universal time
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1986
please input the universal time
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 0,0,0
please input the simulation period (days)
? 120
please input the algorithm error tolerance
(a value of 1.0e8 is recommended)
? 1e8
The following is the data display for this example.
program cowell2
< heliocentric orbital motion  Cowell's method >
final conditions
calendar date 01May1986
universal time 00:00:00
sma (km) eccentricity inclination (deg) argper (deg)
2.6903158654e+009 9.6733201271e001 1.6224898624e+002 1.1181332505e+002
raan (deg) true anomaly (deg) arglat (deg) period (days)
5.8130641942e+001 1.0750909422e+002 2.1932241926e+002 2.7855773424e+004
perihelion radius 5.8748967534e001 AU
Technical Discussion
The relationship between modified equinoctial orbital elements and classical orbital elements
is given by
( )
( )
( )
( )
( )
2
1
cos
sin
tan 2 cos
tan 2 sin
p a e
f e
g e
h i
k i
L
e
e
e u
= ÷
= + O
= + O
= O
= O
= O+ +
where
Page 35
Celestial Computing with MATLAB
semiparameter
semimajor axis
orbital eccentricity
orbital inclination
argument of perigee
right ascension of the ascending node
true anomaly
true longitude
p
a
e
i
L
e
u
=
=
=
=
=
O =
=
=
The equations of orbital motion expressed in terms of modified equinoctial orbital elements
are as follows:
( ) ( )
( ) ( )
2
2
2
2
sin 1 cos sin cos
cos 1 sin sin cos
cos
2
sin
2
1
sin cos
t
t n
r
t n
r
n
n
dp p p
p
dt w
df p g
f L w L f h L k
dt w w
dg p g
g L w L g h L k
dt w w
dh p s
h L
dt w
dk p s
k L
dt w
dL w p
L p h L k
dt p w
µ
µ
µ
µ
µ
µ
µ
= = A
A A
(
= = A + + + ÷ ÷ (
¸ ¸
(
¸ ¸
L
L
A A
(
= = ÷A + + + + ÷ (
¸ ¸
(
¸ ¸
A
= =
A
= =
 
= = + ÷

\ .
( )
n
L A
where are external perturbations in the radial, tangential and orbit normal
directions, respectively.
, ,
r t
A A A
n
The equations of motion can also be expressed as follows:
( )
d
dt
= = +
y
y A y P b
Page 36
Celestial Computing with MATLAB
where
( )
( ) { } { }
( ) { } { }
{ }
2
2
2
0 0
1
sin 1 cos sin cos
cos 1 sin sin cos
cos
0 0
2
sin
0 0
2
0 0 sin c
p p
q
p p p g
L q L f h L k
q q
p p p f
L q L g h L k
q
p s L
q
p s L
q
p
h L k L
µ
µ µ µ
µ µ µ
µ
µ
µ
¦ ¹
¦ ¦
¦ ¦
¦ ¦
¦ ¦ + + ÷ ÷
¦ ¦
¦ ¦
¦ ¦
÷ + + ÷
¦ ¦
¦ ¦
=
´ `
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦ ÷
¦ ¦
¹ )
A y
os
L
L
and
2
0
0
0
0
0
q
p
p
µ
¦ ¹
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦ ¦
=
´ `
¦ ¦
¦ ¦
¦ ¦
 
¦ ¦

¦ ¦ \ . ¹ )
b
In this equation P is the total disturbing acceleration vector given by
ˆ ˆ
r r t t n n
ˆ
= A + A + A P i i i
In this MATLAB script these perturbations consist of the pointmass gravity effects of the
planets. Other perturbations such as solar radiation pressure can also be included.
Furthermore,
ˆ ˆ
are unit vectors in the radial, tangential and normal directions given
by
ˆ
, and
r t n
i i i
Page 37
Celestial Computing with MATLAB
ˆ
ˆ
ˆ ˆ ˆ
r
n
t n r
=
×
=
×
= ×
r
i
r
r v
i
r v
i i i
Page 38
Celestial Computing with MATLAB
9. Encke’s Method for Heliocentric Orbits
This MATLAB application (encke.m) demonstrates heliocentric orbit propagation using
Encke’s method. It includes the point mass gravity perturbations due to the planets Venus,
Earth, Mars, Jupiter, Saturn and the Sun.
The classic form of Encke’s special perturbation method solves the initial value problem
(IVP) of celestial mechanics by analytically propagating a twobody “reference” orbit and
numerically integrating the deviations from twobody motion. These two procedures are
performed for the same time interval or step size. Since the twobody 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 twobody 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.
The twobody or unperturbed equations of motion of a spacecraft or celestial body are
( )
2
2 3
0
k k
k
t d
dt r
µ + =
r r
where is the unperturbed position vector of the spacecraft at any time t and
k
r µ 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
( )
( )
2
2 3
,
p p
p
p
d t
t
dt r
µ + =
r r
a r
where is the perturbed position vector at any time t and
p
r
( )
,
p
t a r is the vector of
perturbations or other accelerations.
The difference between these two types of orbital motion is
Page 39
Celestial Computing with MATLAB
2
2 2
2 2
p
k
d
d
dt dt dt
o
= ÷
r
r r
2
In order to avoid numerical difficulties when subtracting small differences of vector
equations, the following form of the equations of motion is used:
( ) ( ) ( ) ( )
2
2 3
,
p p p
f q t t t
dt
o µ
µ
( = ÷ + +
¸ ¸
r
r r a r
where
( )
( )
2
3/ 2
3 3
1 1
q q
f q q
q
 
+ +
= 

+ +
\ .
and
( )
2
2
q
r
o o ÷ 
=
r r r
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:
( ) ( ) ( )
k p
t t = + r r r t
( ) ( ) ( )
k p
t t = + v v v t
The gravitational acceleration on the spacecraft due to each planet is determined from the
following expression:
( )
3 3
,
p b p
p b p
t µ
÷
÷
 

= ÷ +

\ .
r r
a r
r r
where
p
position vector of spacecraft relative to planet
position vector of spacecraft relative to Sun
gravitational constant of planet
p b
µ
÷
=
=
=
r
r
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 RungeKuttaFehlberg 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
userdefined 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 92196, “A Simple and
Efficient Computer Implementation of Encke’s Method”, AAS/AIAA Spaceflight Mechanics
Meeting, Colorado Springs, Colorado, February 2426, 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.0e8 is
recommended.
The following is a typical user interaction with this program.
program encke
< orbit propagation using Encke's method >
< please press any key to continue >
simulation data menu
<1> user input
<2> data file
? 2
please input the simulation data file name
(be sure to include the file name extension)
? halley.dat
initial calendar date and universal time
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1986
please input the universal time
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 0,0,0
Page 41
Celestial Computing with MATLAB
please input the simulation period (days)
? 120
please input the algorithm error tolerance
(a value of 1.0e8 is recommended)
? 1e8
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
calendar date 01May1986
universal time 00:00:00
sma (km) eccentricity inclination (deg) argper (deg)
2.6903155747e+009 9.6733200916e001 1.6224898624e+002 1.1181332495e+002
raan (deg) true anomaly (deg) arglat (deg) period (days)
5.8130641692e+001 1.0750909431e+002 2.1932241926e+002 2.7855768910e+004
perihelion radius 5.8748967589e001 AU
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
10. The CircularRestricted ThreeBody Problem
This section describes several MATLAB scripts that can be used to analyze and display
orbits in the circularrestricted threebody problem (CRTBP). This is a special case of the
general threebody problem where the primary and secondary bodies move in circular orbits
about the common center of mass, and the effect of the gravitational attraction of the smallest
body and any other perturbations such as solar radiation pressure are ignored.
The applications described here are for orbital problems in the EarthMoonsatellite system.
However, the equations and algorithms are valid for any circularrestricted threebody 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 centerofmass or barycenter of the EarthMoon system. The motion of all
three bodies is confined to the xy 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 nondimensional 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 e about the barycenter
equal to 1.
Kepler’s third law for this formulation is given by
( )
3
2
1 2 1 2
1 m m g m m e = + =
The x and y coordinates of the Earth and Moon in this coordinate system are given by
1 1
2 2
0
1 0
x y
x y
µ
µ
= ÷ =
= ÷ =
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, nonrotating coordinate system.
The system of secondorder nondimensional differential equations of motion of a pointmass
satellite or celestial body in this rotating coordinate system are given by
Page 43
Celestial Computing with MATLAB
( )
( )
( )
2
1 2
2 3
1 2
2
2 3
1 2
2
2 3 3
1 2
2 1
2 1
1
d x dy x x x x
x
dt dt r r
d y dx y y
y
dt dt r r
d z z z
dt r r
µ µ
µ µ
µ µ
3
3
÷ ÷
÷ = ÷ ÷ ÷
+ = ÷ ÷ ÷
= ÷ ÷ ÷
where
( )
( )
1
2
1 2
2
2 2 2
1 1
2
2 2 2
2 2
component of position
component of position
component of position
1
EarthMoon mass ratio / 1/ 81.27
x x
y y
z z
x
x
m m
r x x y z
r x x y z
µ
µ
µ
=
=
=
= ÷
= ÷
= =
= ÷ + +
= ÷ + +
~
The Jacobi integral for the threebody problem is given by
( )
2 2 2
1 2
2 1 2
V x y
r r
µ µ ÷
C = + + + ÷
In this equation V is the scalar speed of the small body and C is a constant of integration
called the Jacobi constant.
crtbp1.m – coordinates and energy of the libration points
In his prize memoir of 1772, JosephLouis Lagrange proved that there are five equilibrium
points in the circularrestricted threebody 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 xaxis (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.
The nonlinear equation for the libration point is given by
1
L
( ) ( )
2 2
1
0
1
x
x x
µ µ
µ µ
÷
÷ + =
+ ÷ +
The nonlinear equation for the
2
L libration point is
( ) ( )
2 2
1
0
1
x
x x
µ µ
µ µ
÷
÷ ÷ =
+ ÷ +
and the nonlinear equation for the collinear libration point is
3
L
( ) ( )
2 2
1
0
1
x
x x
µ µ
µ µ
÷
+ + =
+ ÷ +
The lower and upper bounds used during the rootfinding search for all three equations are
and respectively. 2 x = ÷ 2 x = +
The libration point is located at
4
L 1 2 , 3 2 x y µ = ÷ = and the libration point is at
5
L
1 2 , 3 2 x y µ = ÷ = ÷ . For these two libration points
1 2
1 r r = = .
The following is a typical user interaction with this script.
program crtbp1
< equilibrium coordinates and energy >
please input the value for the mass ratio
? .01
The following is the program output for this example.
program crtbp1
< equilibrium coordinates and energy >
mass ratio = 1.0000000000e002
location xcoordinate ycoordinate energy
L1 0.848079 0.000000 1.5838206546e+000
Page 45
Celestial Computing with MATLAB
L2 1.146765 0.000000 1.5771597543e+000
L3 1.004167 0.000000 1.5049988584e+000
L4 0.490000 0.866025 1.4950500000e+000
L5 0.490000 0.866025 1.4950500000e+000
g3body.m – graphics display of threebody motion
This MATLAB script graphically displays motion of a spacecraft or small celestial body in
the circularrestricted threebody problem. This algorithm and program examples are based
on the methods described in “Periodic Orbits in the Restricted ThreeBody Problem with
EarthMoon Masses”, by R. A. Broucke, JPL TR 321168, 1968.
This script begins by displaying the following main menu.
program g3body
< graphics display of threebody motion >
main menu
<1> periodic orbit about L1
<2> periodic orbit about L2
<3> periodic orbit about L3
<4> user input of initial conditions
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:
(1) periodic orbit about the L
1
libration point
0
0
0.300000161
2.536145497
0.012155092
5.349501906
f
x
y
t
µ
=
= ÷
=
=
(2) periodic orbit about the L libration point
2
0
0
2.840829343
2.747640074
0.012155085
11.933318588
f
x
y
t
µ
=
= ÷
=
=
Page 46
Celestial Computing with MATLAB
(3) periodic orbit about the L libration point
3
0
0
1/ 600000312
2.066174572
0.012155092
6.303856312
f
x
y
t
µ
= ÷
=
=
=
Notice that each orbit is defined by an initial xcomponent of position, x
0
, an initial y
component of velocity, y
0
, a value of EarthMoon mass ratio µ , and an orbital period t . The
initial ycomponent of position and xcomponent of velocity for each of these orbits is equal
to zero. The software will draw the location of the Earth, Moon and libration point on the
graphics screen.
f
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.
(1) Retrograde periodic orbit about m
1
0
0
2.499999883
2.100046263
0.012155092
11.99941766
f
x
y
t
µ
= ÷
=
=
=
(2) Direct periodic orbit about m
1
0
0
0.952281734
0.957747254
0.012155092
6.450768946
f
x
y
t
µ
=
= ÷
=
=
(3) Direct periodic orbit about m and m
1 2
Page 47
Celestial Computing with MATLAB
0
0
3.147603117
3.07676285
0.012155092
12.567475674
f
x
y
t
µ
=
= ÷
=
=
(4) Direct periodic orbit about m
2
0
0
1.399999991
0.9298385561
0.012155092
13.775148738
f
x
y
t
µ
=
= ÷
=
=
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
libration point is the small dot.
3
L
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
y
c
o
o
r
d
i
n
a
t
e
x coordinate
Periodic Orbit about the L3 Libration Point
Another excellent source of circularrestricted threebody problems is described in the report,
“A Collection of Restricted Threebody Test Problems” by Philip W. Sharp, Report Series
Page 48
Celestial Computing with MATLAB
460, Department of Mathematics, University of Auckland, March 2001. A copy of this report
in PDF format can be found at the following web site:
http://www.scitec.auckland.ac.nz/~sharp/papers/preprints.html
The following is a summary of these test problems. Column 1 is the test problem number,
column 2 is the initial x coordinate
0
x , column 3 is the initial y speed
0
y and column 4 is the
orbital period
f
t . For problems 1 to 15 0.012277471 µ = and for problems 16 to 20
0.000953875 µ = .
1 0.994000E+00 0.21138987966945026683E+01 0.54367954392601899690E+01
2 0.994000E+00 0.20317326295573368357E+01 0.11124340337266085135E+02
3 0.994000E+00 0.20015851063790825224E+01 0.17065216560157962559E+02
4 0.997000E+00 0.16251217072210773125E+01 0.22929723423442969481E+02
5 0.879962E+00 0.66647197988564140807E+00 0.63006757422352314657E+01
6 0.879962E+00 0.43965281709207999128E+00 0.12729711861022426544E+02
7 0.879962E+00 0.38089067106386964470E+00 0.19138746281183026809E+02
8 0.997000E+00 0.18445010489730401177E+01 0.12353901248612092736E+02
9 0.100000E+01 0.16018768253456252603E+01 0.12294387796695023304E+02
10 0.100300E+01 0.14465123738451062297E+01 0.12267904265603897140E+02
11 0.120000E+01 0.71407169828407848921E+00 0.18337451820715063383E+02
12 0.120000E+01 0.67985320356540547720E+00 0.30753758552146029263E+02
13 0.120000E+01 0.67153130632829144331E+00 0.43214375227857454128E+02
14 0.120000E+01 0.66998291305226832207E+00 0.55672334134347612727E+02
15 0.120000E+01 0.66975741517271092087E+00 0.68127906604713772763E+02
16 0.102745E+01 0.40334488290490413053E01 0.18371316400018903965E+03
17 0.976680E+00 0.61191623926410837000E01 0.17733241131524483004E+03
18 0.766650E+00 0.51230158665978820282E+00 0.17660722897242937108E+03
19 0.109137E+01 0.14301959822238380020E+00 0.82949461922342093092E+02
20 0.110137E+01 0.15354250908611454510E+00 0.60952121909407746612E+02
zvcurve1.m – graphics display of zero velocity curves through equilibrium points
This MATLAB script can be used to display zero relative velocity curves that pass through
the five equilibrium or libration points of the EarthMoon circularrestricted threebody
problem (CRTBP). These twodimensional drawings are also called equipotential curves.
Page 49
Celestial Computing with MATLAB
The zero velocity curves define regions of the xy 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
0 1 2
1 2
2 2
2 1 1 C E r r
r r
µ µ µ
   
= ÷ = ÷ + + + ÷ ÷
 
\ . \ .
µ
where is the zero relative velocity specific orbital energy which is given by.
0
E
( )
2 2
0
1 2
1 1
2
E x y
r r
µ µ ÷
= ÷ + ÷ ÷
From the Jacobi integral we can see that imaginary velocities occur whenever the following
expression is smaller than the Jacobi constant C.
( )
2 2
1 2
2 1 2
x y
r r
µ µ ÷
+ + +
This MATLAB script computes and displays zero relative velocity contour plots that actually
pass through the five libration points.
The following is a typical user interaction with this script.
program zvcurve1
graphics display of zero relative velocity
curves through the crtbp equilibrium points
<1> L1 contour
<2> L2 contour
<3> L3 contour
<4> L4 and L5 contour
<5> all points 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
−1.5 −1 −0.5 0 0.5 1 1.5
−1.5
−1
−0.5
0
0.5
1
1.5
Zero Relative Velocity Curves through L1−L5
x coordinate
y
c
o
o
r
d
i
n
a
t
e
zvcurve2.m – graphics display of userdefined zero relative velocity curves
This MATLAB script can be used to display zero relative velocity contour curves of the
circularrestricted threebody problem (CRTBP) for userdefined values of the Jacobi
constant C and mass ratio µ as defined by the following expression:
( ) ( )
2 2
1 2
1 2
2 2
1 1 C r r
r r
µ µ µ
   
= ÷ + + + ÷ ÷
 
\ . \ .
µ
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 userdefined 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.
The following is a typical user interaction with this MATLAB script.
program zvcurve2
graphics display of userdefined
zero relative velocity curves
Page 51
Celestial Computing with MATLAB
please input the value for the mass ratio
? 0.2
contour level input menu
<1> lower value, increment, upper value
<2> discrete contour values
selection (1 or 2)
? 1
please input the lower contour value
? 3.0
please input the contour increment
? 0.1
please input the upper contour value
? 4.0
would you like to label the contours (y = yes, n = no)
? n
please input the minimum value for the x and y coordinates
? 2
please input the maximum value for the x and y coordinates
? 2
please input the mesh grid value for x and y
(a value between 0.01 and 0.005 is recommended)
? 0.01
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
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
−2
−1.5
−1
−0.5
0
0.5
1
1.5
2
Zero Relative Velocity Curves for Mass Ratio = 0.2
x coordinate
y
c
o
o
r
d
i
n
a
t
e
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
graphics display of userdefined
zero relative velocity curves
please input the value for the mass ratio
? 0.2
contour level input menu
<1> lower value, increment, upper value
<2> discrete contour values
selection (1 or 2)
? 1
please input the lower contour value
? 3.0
Page 53
Celestial Computing with MATLAB
please input the contour increment
? 0.1
please input the upper contour value
? 3.5
would you like to label the contours (y = yes, n = no)
? y
please input the minimum value for the x and y coordinates
? 0
please input the maximum value for the x and y coordinates
? 1.5
please input the mesh grid value for x and y
(a value between 0.01 and 0.005 is recommended)
? 0.01
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.
0 0.5 1 1.5
0
0.5
1
1.5
3
3.1
3.2
3.3
3.4
3.5
Zero Relative Velocity Curves for Mass Ratio = 0.2
x coordinate
y
c
o
o
r
d
i
n
a
t
e
Page 54
Celestial Computing with MATLAB
11. Apparent Coordinates of a Planet or the Moon
These two MATLAB functions can be used to determine the apparent geocentric and
topocentric coordinates of a planet or the Moon. These functions use several functions ported
to MATLAB using the Fortran versions of the NOVAS (Naval Observatory Vector
Astrometry Subroutines) source code that was developed at the United States Naval
Observatory.
These functions includes the following types of coordinate corrections:
(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 11971210, 1989.
The processing steps used in these two MATLAB scripts are as follows:
(1) input a calendar date on the UT1 time scale
(2) compute the UT1 Julian date
(3) compute the TDT Julian date
(4) compute the TDB Julian date
(5) select the target body
(6) define type of coordinates
(7) evaluate the ephemeris
The topocentric azimuth A and elevation (altitude) h are calculated using the topocentric right
ascension o and declination o and the observer's coordinates as follow:
sin
tan
cos sin tan cos
H
A
H  o 
=
÷
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 u and the right ascension of the object as follows:
H u o = ÷
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.
The following is the syntax for this MATLAB function.
function [ra, dec, dis] = applan1 (tjd, ujd, l, n, topo, glon, glat, ht)
% this function computes the apparent geocentric or topocentric place
% of a planet or other solar system body. rectangular coordinates of
% solar system bodies are obtained from function solsys.
% input
% tjd = tdt julian date for apparent geocentric place
% ujd = ut1 julian date for apparent topocentric place
% l = body identification number for desired planet
% n = body identification number for the earth
% topo = type of apparent place calculation
% = 0 ==> geocentric
% = 1 ==> topocentric
% glon = geodetic longitude of observer (east +, degrees)
% glat = geodetic latitude of observer (north +, degrees)
% ht = height of observer (meters)
% output
% ra = apparent geocentric or topocentric right ascension,
% referred to true equator and equinox of date (hours)
% dec = apparent geocentric or topocentric declination,
% referred to true equator and equinox of date (degrees)
% dis = true distance from earth to planet (astronomical units)
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.
The following is a typical user interaction with this demonstration script.
aplanet1  apparent coordinates
please input a UTC calendar date
please input the calendar date
Page 56
Celestial Computing with MATLAB
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1998
please input the universal time
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 10,20,30
target body menu
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Sun
<11> Moon
please select the target body
? 11
coordinate type menu
<1> geocentric
<2> topocentric
please select coordinate type
? 2
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 40,0,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 105,0,0
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 1000
The following is the program output created for this example.
apparent topocentric coordinates
'Moon'
UTC calendar date 01Jan1998
universal time 10:20:30
UTC julian date 2450814.9309
observer latitude 105d 00m 00.00s
observer east longitude +40d 00m 00.00s
Page 57
Celestial Computing with MATLAB
observer altitude 1000.0000 meters
right ascension +21h 12m 2.9587s
declination 14d 17m 47.57s
azimuth +27d 31m 13.82s
elevation 61d 53m 39.08s
topocentric distance 376284.4187 kilometers
function applan2.m
The source ephemeris for this routine is the SLP96 binary file slp96.
The following is the syntax for this function.
function [ra, dec, dis] = applan2(tjd, ujd, l, n, topo, glon, glat, ht)
% this function computes the apparent geocentric or topocentric place
% of a planet or other solar system body. rectangular coordinates of
% solar system bodies are obtained from function slp96.
% input
% tjd = tdt julian date for apparent geocentric place
% ujd = ut1 julian date for apparent topocentric place
% l = body identification number for desired planet
% n = body identification number for the earth
% topo = type of apparent place calculation
% = 0 ==> geocentric
% = 1 ==> topocentric
% glon = geodetic longitude of observer (east +, degrees)
% glat = geodetic latitude of observer (north +, degrees)
% ht = height of observer (meters)
% output
% ra = apparent geocentric or topocentric right ascension,
% referred to true equator and equinox of date (hours)
% dec = apparent geocentric or topocentric declination,
% referred to true equator and equinox of date (degrees)
% dis = true distance from earth to planet (astronomical units)
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
12. Apparent Coordinates of a Star
These two MATLAB scripts demonstrate how to calculate the apparent topocentric and
geocentric coordinates of a star. The first script is called astar1 and it uses DE405 as its
source ephemeris. The second script is called astar2 and it uses SLP96 as its source
ephemeris. These applications use several functions ported to MATLAB from the Fortran
versions of the NOVAS (Naval Observatory Vector Astrometry Subroutines) source code
that was developed at the United States Naval Observatory.
This program includes the following types of coordinate corrections:
(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 11971210, 1989.
The processing steps used in this program are as follows:
(1) input a calendar date on the UT1 time scale
(2) compute the UT1 Julian date
(3) compute the TDT Julian date
(4) compute the TDB Julian date
(5) read the star's coordinates, proper motions, parallax and radial velocity
(6) define type of coordinates
(7) calculate apparent coordinates
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)
% this subroutine computes the geocentric or topocentric apparent place
% of a star, given its mean place, proper motion, parallax, and radial
% velocity for j2000.0.
% input
% tjd = tdt julian date for apparent place
% ujd = ut1 julian date for apparent topocentric place
% n = body identification number for the earth
% topo = type of apparent place calculation
% = 0 ==> geocentric
% = 1 ==> topocentric
% ram = mean right ascension j2000.0 (hours)
% decm = mean declination j2000.0 (degrees)
% pmra = proper motion in ra (seconds of time/julian century)
% pmdec = proper motion in dec (seconds of arc/julian century)
% parlax = parallax (seconds of arc)
% radvel = radial velocity (kilometers per second)
% output
% ra = apparent geocentric or topocentric right ascension,
% referred to true equator and equinox of date (hours)
% dec = apparent geocentric or topocentric declination,
% referred to true equator and equinox of date (degrees)
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
J2000 right ascension (hours)
19.8463894440
J2000 declination (degrees)
8.8683416670
J2000 proper motion in right ascension (seconds/Julian century)
3.6290
J2000 proper motion in declination (arcseconds/Julian century)
38.6300
parallax (arcseconds)
0.1981
radial velocity (kilometers/second)
26.30
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
star1  apparent coordinates  jplephem ephemeris
please input a UTC calendar date
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1998
please input the universal time
(0 <= hours <= 24, 0 <= minutes <= 60, 0 <= seconds <= 60)
? 0,0,0
please input the star data file name
(be sure to include the file name extension)
? altair.dat
coordinate type menu
<1> geocentric
<2> topocentric
please select coordinate type
? 2
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 40,0,0
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 105,0,0
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 0
apparent topocentric coordinates
ALTAIR
UTC calendar date 01Jan1998
universal time 00:00:00
UTC julian date 2450814.5000
observer latitude 105d 00m 00.00s
observer east longitude +40d 00m 00.00s
observer altitude 0.0000 meters
right ascension +19h 50m 39.1674s
declination +08d 51m 46.09s
Page 61
Celestial Computing with MATLAB
13. JPL DE405 Lunar, Solar and Planetary Ephemeris
This MATLAB script demonstrates how to read DE405 binary ephemeris files created using
the Fortran programs and ASCII data files provided by the Jet Propulsion Laboratory, and
calculate the position and velocity vectors of a planet or the Moon. This function was ported
to MATLAB using the Fortran source code subroutine provided by JPL. These ASCII files
can be found on the Internet at ftp://navigator.jpl.nasa.gov. A CD ROM containing these
ASCII data files and Fortran source code is also available from WillmannBell.
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 IBMPC 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:516546, 1998, July.
The following is the syntax for this MATLAB function:
function rrd = jplephem (et, ntarg, ncent)
% reads the jpl planetary ephemeris and gives
% the position and velocity of the point 'ntarg'
% with respect to point 'ncent'
% input
% et = julian ephemeris date at which interpolation is wanted
% ntarg = integer number of 'target' point
% ncent = integer number of center point
% the numbering convention for 'ntarg' and 'ncent' is:
% 1 = mercury 8 = neptune
% 2 = venus 9 = pluto
% 3 = earth 10 = moon
% 4 = mars 11 = sun
% 5 = jupiter 12 = solarsystem barycenter
% 6 = saturn 13 = earthmoon barycenter
% 7 = uranus 14 = nutations (longitude and obliq)
Page 62
Celestial Computing with MATLAB
% 15 = librations, if on ephemeris file
% if nutations are wanted, set ntarg = 14.
% for librations, set ntarg = 15. set ncent = 0.
% output
% rrd = output 6word array containing position and velocity
% of point 'ntarg' relative to 'ncent'. the units are au and
% au/day. for librations the units are radians and radians
% per day. in the case of nutations the first four words of
% rrd will be set to nutations and rates, having units of
% radians and radians/day.
% the option is available to have the units in km and km/sec.
% for this, set km = 1 via global in the calling program.
The following is a typical user interaction with this script.
demojpl  demonstrates how to use the jplephem.m function
please input a UTC calendar date
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 10,21,1998
target body menu
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Moon
<11> Sun
please select the target body
? 10
central body menu
<1> Mercury
<2> Venus
<3> Earth
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> Pluto
<10> Moon
<11> Sun
<12> solarsystem barycenter
<13> EarthMoon barycenter
please select the central body
Page 63
Celestial Computing with MATLAB
? 3
target body 'Moon'
central body 'Earth'
UTC calendar date 21Oct1998
UTC Julian date 2451107.5000
state vector
rx (km) ry (km) rz (km) rmag (km)
3.3736590217e+005 2.1902562142e+005 5.9817990536e+004 +4.0665239060e+005
vx (kps) vy (kps) vz (kps) vmag (kps)
+5.3908644803e001 7.5535385071e001 2.8617936544e001 +9.7111907995e001
Page 64
Celestial Computing with MATLAB
14. SLP96 Lunar, Solar and Planetary Ephemeris
This MATLAB function demonstrates how to read SLP96 binary ephemeris files created
using the Fortran programs and ASCII data files provided by the Bureau of Longitudes
(BDL, Paris), and calculate the position and velocity vectors of a planet or the moon in either
the J2000 FK5 or dynamical coordinate systems. This function was ported to MATLAB
using the Fortran source code subroutine provided by the BDL. These ASCII files can be
found on the Internet at ftp.bdl.fr/pub/ephem/sun/slp96.
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 IBMPC 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)
% solar, lunar and planetary coordinates j2000
% input
% tjd julian date tdb
% ibody body index
% ibody=01 : mercury ibody=07 : uranus
% ibody=02 : venus ibody=08 : neptune
% ibody=03 : em baryc. ibody=09 : void
% ibody=04 : mars ibody=10 : moon
% ibody=05 : jupiter ibody=11 : sun
% ibody=06 : saturn ibody=12 : earth
% icent frame center index
% icent=00 : barycenter of solar system
% icent=01 : mercury icent=07 : uranus
% icent=02 : venus icent=08 : neptune
% icent=03 : em baryc. icent=09 : void
% icent=04 : mars icent=10 : moon
Page 65
Celestial Computing with MATLAB
% icent=05 : jupiter icent=11 : sun
% icent=06 : saturn icent=12 : earth
% ipv positionvelocity index
% ipv=1 : position.
% ipv=2 : position and velocity.
% iframe frame index
% iframe=1 : equinox and equator j2000 (fk5)
% iframe=2 : equinox and ecliptic j2000 (dynamical)
% icoord coordinates index
% icoord=1 : rectangular coordinates
% icoord=2 : spherical coordinates
% fname name of the slp96 data file
% note: passed via global
% output
% result results table
% rectangular coordinates (icoord = 1)
% position
% result(1) : equatorial or ecliptic component x (au)
% result(2) : equatorial or ecliptic component y (au)
% result(3) : equatorial or ecliptic component z (au)
% velocity
% result(4) : equatorial or ecliptic component x (au/day)
% result(5) : equatorial or ecliptic component y (au/day)
% result(6) : equatorial or ecliptic component z (au/day)
% spherical coordinates (icoord = 2)
% position
% result(1) : right ascension or longitude (radians)
% result(2) : declination or latitude (radians)
% result(3) : geometric distance (au)
% velocity
% result(4) : right ascension or longitude (rad/day)
% result(5) : declination or latitude (rad/day)
% result(6) : geometric distance (au/day)
% ierr error index
% 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 : positionvelocity error (ipv)
% ierr=15 : frame error (iframe)
% ierr=16 : coordinates error (icoord)
Page 66
Celestial Computing with MATLAB
The processing steps used in this script are as follows:
(1) input a calendar date on the UTC time scale
(2) compute the UTC Julian date
(3) compute the TDT Julian date
(4) compute the TDB Julian date
(5) select the target body
(6) select the central body
(7) define type of coordinate system
(8) define type of coordinate calculations
(9) specify the name of the SLP96 binary data file
(10) evaluate the ephemeris
The following is a typical user interaction with this script.
demoslp  demonstrates how to use the slp96.m function
please input a UTC calendar date
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 10,21,1998
target body menu
<1> Mercury
<2> Venus
<3> EarthMoon barycenter
<4> Mars
<5> Jupiter
<6> Saturn
<7> Uranus
<8> Neptune
<9> void
<10> Moon
<11> Sun
<12> Earth
please select the target body
? 10
central body menu
<0> solar system barycenter
<1> Mercury
<2> Venus
<3> EarthMoon barycenter
<4> Mars
<5> Jupiter
<6> Saturn
Page 67
Celestial Computing with MATLAB
<7> Uranus
<8> Neptune
<9> void
<10> Moon
<11> Sun
<12> Earth
please select the central body
? 12
coordinate system menu
<1> equinox and equator j2000 (fk5)
<2> equinox and ecliptic j2000 (dynamical)
please select the coordinate system type
? 1
coordinate type menu
<1> rectangular coordinates
<2> spherical coordinates
please select the coordinate type
? 1
The following is the program output created for this example.
program demoslp
equinox and equator j2000 (fk5)
target body 'Moon'
central body 'Earth'
UTC calendar date 21Oct1998
UTC Julian date 2451107.5000
state vector
rx (km) ry (km) rz (km) rmag (km)
3.3736588697e+005 2.1902566702e+005 5.9818049020e+004 +4.0665241115e+005
vx (kps) vy (kps) vz (kps) vmag (kps)
+5.3908659599e001 7.5535382805e001 2.8617931903e001 +9.7111913078e001
Page 68
Celestial Computing with MATLAB
15. Other Lunar, Solar and Planetary Ephemeris Algorithms
The next ten MATLAB functions are based on the algorithms described in “LowPrecision
Formulae for Planetary Positions”, T. C. Van Flandern and K. F. Pulkkinen, The
Astrophysical Journal Supplement Series, 41:391411, November 1979. To the precision of
this algorithm (one arc minute) these coordinates can be considered to be trueofdate.
Each algorithm uses time arguments given by
2451545
/ 36525 1
t JD
T t
= ÷
= +
where JD is the Julian date on the UT1 time scale.
Each MATLAB function uses fundamental trigonometric arguments (in revolutions) of the
following form:
2
4
5
4
4
0.993126 0.00273777850
0.140023 0.00445036173
0.053856 0.00145561327
0.056531 0.00023080893
0.849694 0.00145569465
0.987353 0.00145575328
s
G t
G t
G t
G t
F t
L t
= +
= +
= +
= +
= +
= +
The heliocentric, ecliptic longitude ì , latitude  and distance r are computed from series
involving these arguments. These series are of the form
( ) ( )
( ) ( )
( )
4 4 4 4
4 4 4 4 4
4 4
38451sin 2238sin 2 181sin 3
6603sin 622sin 615sin
1.53031 0.1417cos 0.0066cos 2
L G G G
F G F G F
r G G
ì

= + + + +
= + ÷ + +
= ÷ ÷ +
+
where the unit of r is Astronomical Units.
The heliocentric, ecliptic position vector of the planet is determined from
cos cos
cos sin
sin
r
 ì
 ì

¦ ¹
¦ ¦
=
´ `
¦ ¦
¹ )
r
sun.m – solar ephemeris
This function calculates the trueofdate geocentric right ascension, declination and position
vector of the Sun.
Page 69
Celestial Computing with MATLAB
The syntax of this MATLAB function is
function [rasc, decl, rsun] = sun (jdate)
% solar ephemeris
% input
% jdate = Julian date
% output
% rasc = right ascension of the sun (radians)
% (0 <= rasc <= 2 pi)
% decl = declination of the sun (radians)
% (pi/2 <= decl <= pi/2)
% rsun = eci position vector of the sun (km)
moon.m – lunar ephemeris
This function calculates the trueofdate geocentric right ascension, declination and position
vector of the Moon.
The syntax of this MATLAB function is
function [rasc, decl, rmoon] = moon (jdate)
% lunar ephemeris
% input
% jdate = julian date
% output
% rasc = right ascension of the moon (radians)
% (0 <= rasc <= 2 pi)
% decl = declination of the moon (radians)
% (pi/2 <= decl <= pi/2)
% rmoon = eci position vector of the moon (km)
mercury.m – Mercury ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Mercury.
The syntax of this MATLAB function is
function rmercury = mercury (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Mercury
% input
% jdate = julian date
Page 70
Celestial Computing with MATLAB
% output
% rmercury = position vector of Mercury (km)
venus.m – Venus ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Venus.
The syntax of this MATLAB function is
function rvenus = venus (jdate)
% trueofdate heliocentric, ecliptic
% position vector of venus
% input
% jdate = Julian date
% output
% rvenus = position vector of Venus (km)
earth.m – Earth ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of the Earth.
The syntax of this MATLAB function is
function rearth = earth (jdate)
% trueofdate heliocentric, ecliptic
% position vector of the Earth
% input
% jdate = Julian date
% output
% rearth = position vector of the Earth (km)
mars.m – Mars ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Mars.
The syntax of this MATLAB function is
function rmars = mars (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Mars
% input
% jdate = Julian date
Page 71
Celestial Computing with MATLAB
% output
% rmars = position vector of Mars (km)
jupiter.m – Jupiter ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Jupiter.
The syntax of this MATLAB function is
function rjupiter = jupiter (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Jupiter
% input
% jdate = Julian date
% output
% rjupiter = position vector of Jupiter (km)
saturn.m – Saturn ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Saturn.
The syntax of this MATLAB function is
function rsaturn = saturn (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Saturn
% input
% jdate = Julian date
% output
% rsaturn = position vector of Saturn (km)
uranus.m – Uranus ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Uranus.
The syntax of this MATLAB function is
function ruranus = uranus (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Uranus
% input
Page 72
Celestial Computing with MATLAB
% jdate = Julian date
% output
% ruranus = position vector of Uranus (km)
neptune.m – Neptune ephemeris
This function calculates the trueofdate heliocentric ecliptic position vector of Neptune.
The syntax of this MATLAB function is
function rneptune = neptune (jdate)
% trueofdate heliocentric, ecliptic
% position vector of Neptune
% input
% jdate = Julian date
% output
% rneptune = position vector of Neptune (km)
pluto.m – Pluto ephemeris
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:
2451545
36525
JED
T
÷
=
The heliocentric ecliptic coordinates of Pluto are computed from series of the form
43
1
sin cos
m
i
A B ì ì o
=
= + +
¿
o
where
coordinate mean value
, , mean longitudes of Jupiter, Saturn and Pluto
, , integer constants
, coefficients of periodic term
m
iJ jS kP
J S P
i j k
A B
ì
o
=
= + +
=
=
=
The syntax of this MATLAB function is
Page 73
Celestial Computing with MATLAB
function rpluto = pluto(jdate)
% heliocentric coordinates of pluto
% heliocentric position vector of Pluto
% ecliptic and equinox of J2000
% input
% jdate = Julian date
% output
% rpluto = position vector of Pluto (km)
sun1.m – precision Sun ephemeris
This MATLAB function computes a trueofdate geocentric ephemeris of the Sun based on
the data and numerical methods described in the book, Planetary Programs and Tables by
Pierre Bretagnon and JeanLouis 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
2451545
3652500
JED
U
÷
=
The geocentric, ecliptic mean longitude of the Sun is calculated with a trigonometric series of
the form
( )
50
0 1
1
sin
m
s i
i
U l U ì ì ì o v
=
= + + +
¿ i i
i
The geocentric distance of the Sun is calculated with another series of the form
( )
50
0 1
1
cos
s i i
i
r r r U r U o v
=
= + + +
¿
The longitude of the Sun is corrected for the effect of aberration (in radians) with the
following equation:
( ) { }
7
10 993 17cos 3.10 62830.14
a
s
U ì
÷
A = ÷ + +
The nutation in longitude (in radians) is calculated from
( )
7
1 2
10 834sin 64sin A A ¢
÷
A = ÷ ÷
where
Page 74
Celestial Computing with MATLAB
2
1
2
2
2.18 3375.70 0.36
3.51 125666.39 0.10
A U
A U
= ÷ +
= + +
U
U
The apparent, geocentric ecliptic longitude of the Sun is determined as the combination of
these three components with the next equation
m a
s s s
ì ì ì ¢ = + A + A
The three components of the geocentric, ecliptic position vector of the Sun are given by
cos
sin
0
s s s
s s s
s
x r
y r
z
ì
ì
=
=
=
The apparent geocentric, equatorial right ascension
s
o and declination
s
o of the Sun can be
found from
( )
( )
arctan cos , sin sin
arcsin sin sin
s s s
s s
o ì c ì
o c ì
=
=
where c is the true obliquity of the ecliptic. This number is calculated from the mean
obliquity of the ecliptic
m
c and the nutation in obliquity c A in this function with the
following expressions:
( )
( ) ( ) ( ) ( )
7
1 2
7
10 4090928 446cos 28cos
10 226938 75 96926 2491 12104
m
m
A A
U U U U U
c c c
c
c
÷
÷
= + A
= + +
A = ÷ + ÷ + + ÷ ÷
Finally, we can compute the three components of the apparent, geocentric equatorial position
vector of the Sun with the following three expressions:
cos cos
sin cos
sin
x s s
y s
z s
r r
r r
r r
s
o o
o o
o
=
=
=
where r is the geocentric distance of the Sun.
This function requires initialization the first time it is called. The following statement in the
main MATLAB script will accomplish this:
suncoef = 1;
Page 75
Celestial Computing with MATLAB
This variable should also be placed in a global statement at the beginning of the main
script that calls this function.
The syntax of this MATLAB function is
function [rasc, decl, rsun] = sun1 (jdate)
% precision ephemeris of the Sun
% input
% jdate = julian ephemeris date
% output
% rasc = right ascension of the Sun (radians)
% (0 <= rasc <= 2 pi)
% decl = declination of the Sun (radians)
% (pi/2 <= decl <= pi/2)
% rsun = eci position vector of the Sun (km)
elp2000.m – osculating orbital elements of the moon
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 ChaprontTouze and Jean
Chapront. This book and its optional companion software are available from WillmannBell
(www.willbell.com).
The fundamental time argument of this algorithm is
2451545
36525
JED
t
÷
=
where JED is the Julian Ephemeris Date.
The osculating orbital elements are calculated from series of the form
383397.6
a a
a S tS'' = + +
where
( ) ( ) ( ) ( ) ( )
( )
( ) ( )
( )
30
0 1 2 3 4 4 2 6 3 8 4
1
3
0 1
1
cos 10 10 10
cos
a n n n n n n
n
a n n n
n
S a t t t t
S a t
ç ç ç ç ç
ç ç
÷ ÷
=
=
= + + + +
'' '' '' '' = +
¿
¿
÷
The first few multipliers and trigonometric arguments for this orbital element are
Page 76
Celestial Computing with MATLAB
n
( ) 0
n
ç
( ) 1
n
ç
( ) 2
n
ç
( ) 3
n
ç
( ) 4
n
ç
n
a
1 3400.4 235.7004 890534.223
0
32.601 3.664 1.769
2 635.6 100.7370 413335.355
4
122.571 10.684 5.028
n
n
a''
( ) 0
n
ç''
( ) 1
n
ç''
1 0.55 238.2 854535.2
2 0.10 103.2 377336.3
The following is the syntax for this MATLAB function.
function oev = elp2000(tjd)
% osculating orbital elements of the moon
% mean ecliptic and mean equinox of date
% input
% tjd = tdt Julian date
% output
% oev(1) = semimajor axis (kilometers)
% oev(2) = orbital eccentricity (nondimensional)
% (0 <= eccentricity < 1)
% oev(3) = orbital inclination (radians)
% (0 <= inclination <= pi)
% oev(4) = argument of perigee (radians)
% (0 <= argument of perigee <= 2 pi)
% oev(5) = right ascension of ascending node (radians)
% (0 <= raan <= 2 pi)
% oev(6) = true anomaly (radians)
% (0 <= true anomaly <= 2 pi)
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
< orbital elements of the moon >
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
? 1,1,1999
please input the simulation period (days)
? 360
please input the graphics step size (days)
Page 77
Celestial Computing with MATLAB
? .1
please select the orbital element to plot
<1> semimajor axis
<2> eccentricity
<3> orbital inclination
<4> argument of perigee
<5> right ascension of the ascending node
<6> true anomaly
<7> apogee radius
<8> perigee radius
<9> geocentric distance
? 2
The following is the graphics display for this example.
01/01/99 04/01/99 07/01/99 10/01/99 01/01/00
0.02
0.03
0.04
0.05
0.06
0.07
0.08
Calendar Date
O
r
b
i
t
a
l
E
c
c
e
n
t
r
i
c
i
t
y
Orbital Eccentricity of the Moon
planet1.m – mean ecliptic and equinox of data planetary ephemeredes
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
2 3
0 1 2 3
a a T a T a T + + +
where the fundamental time argument T is given by
Page 78
Celestial Computing with MATLAB
2451545
36525
JED
T
÷
=
In this expression JED is the Julian ephemeris date.
The syntax of this MATLAB function is
function [r, v] = planet1(ip, jdate)
% planetary ephemeris
% input
% ip = planet index (1 = mercury, 2 = venus, etc.)
% jdate = Julian date
% output
% r = heliocentric position vector (kilometers)
% v = heliocentric velocity vector (kilometers/second)
planet2.m – mean ecliptic and equinox of J2000 planetary ephemerides
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
2 3
0 1 2 3
a a T a T a T + + +
where the fundamental time argument T is given by
2451545
36525
JED
T
÷
=
In this expression JED is the Julian ephemeris date.
The syntax of this MATLAB function is
function [r, v] = planet2(ip, jdate)
% planetary ephemeris
% input
% ip = planet index (1 = mercury, 2 = venus, etc.)
% jdate = Julian date
% output
Page 79
Celestial Computing with MATLAB
% r = heliocentric position vector (kilometers)
% v = heliocentric velocity vector (kilometers/second)
seleno.m – selenographic coordinate transformation
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.
The syntax of this MATLAB function is
function a = seleno(jd, it)
% transformation matrix from eci mean of date to
% selenographic mean of date or true of date
% input
% jd = julian date
% it = transformation flag
% = 0 transform to mean selenographic
% <> 0 transform to true selenographic
% (include physical librations)
% output
% a(3, 3) = transformation matrix
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
16. Apparent Greenwich Sidereal Time
This section describes three MATLAB functions that can be used to calculate apparent
Greenwich sidereal time.
gast.m – low precision
This function calculates the apparent Greenwich sidereal time using the first few terms of the
IAU 1980 nutation algorithm.
The Greenwich apparent sidereal time is given by the expression
( ) cos
m m
u u ¢ c c = + A + A
where
m
u is the Greenwich mean sidereal time, ¢ A is the nutation in longitude,
m
c is the
mean obliquity of the ecliptic and c A is the nutation in obliquity.
The Greenwich mean sidereal time is calculated using the expression
2 3
100.46061837 36000.770053608 0.000387933 / 38710000
m
T T T u = + + ÷
where and JD is the Julian date on the UT1 time scale. The
mean obliquity of the ecliptic is determined from
( 2451545) / 36525 T JD = ÷
0 2
23 26 21. 448 46. 8150 0. 00059 0. 001813
m
T T c ' '' '' '' '' = ÷ ÷ +
3
T
The nutations in obliquity and longitude involve the following three trigonometric arguments
(in degrees):
280.4665 36000.7698
218.3165 481267.8813
125.04452 1934.136261
L T
L T
T
= +
' = +
O = ÷
The calculation of the nutations use the following two equations:
17.20sin 1.32sin2 0.23sin2 0.21sin2 L L ¢ ' A = ÷ O÷ ÷ + O
9.20cos 0.57cos2 0.10cos2 0.09cos2 L L c ' A = O+ + ÷ O
where these corrections are in units of arc seconds.
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 u is the observer’s local sidereal time.
The syntax of this MATLAB function is as follows:
function gst = gast (jdate)
% Greenwich apparent sidereal time
% input
% jdate = Julian date
% output
% gst = Greenwich apparent sidereal time (radians)
% (0 <= gst <= 2 pi)
gast1.m – full precision
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 highorder and loworder 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
For this numerical method, the nutation in longitude is determined from
1
sin
n
i i
i
S A ¢
=
A =
¿
and the nutation in obliquity is determined from
1
cos
n
i i
i
C A c
=
A =
¿
where
i i i i i i
A a l bl c F d D e ' = + + + + O
and are fundamental arguments. , , , and l l F D ' O
The syntax of this MATLAB function is as follows:
function gst = gast1 (tjdh, tjdl, k)
% this function computes the greenwich sidereal time
% (either mean or apparent) at julian date tjdh + tjdl
% input
% tjdh = julian date, highorder part
% tjdl = julian date, loworder part
% julian date may be split at any point, but for
% highest precision, set tjdh to be the integral part of
% the julian date, and set tjdl to be the fractional part
% k = time selection code
% set k=0 for greenwich mean sidereal time
% set k=1 for greenwich apparent sidereal time
% output
% gst = greenwich (mean or apparent) sidereal time in hours
gast2.m – DE405 nutations
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 highorder and loworder 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
The syntax of this MATLAB function is as follows:
function gst = gast2 (tjdh, tjdl, k)
% this function computes the greenwich sidereal time
% (either mean or apparent) at julian date tjdh + tjdl
% this version reads the nutation values from jpleph
% reference
% aoki, et al. (1982) astronomy and astropysics 105, 359361
% input
% tjdh = julian date, highorder part
% tjdl = julian date, loworder part
% julian date may be split at any point, but for
% highest precision, set tjdh to be the integral part of
% the julian date, and set tjdl to be the fractional part
% k = time selection code
% set k = 0 for greenwich mean sidereal time
% set k = 1 for greenwich apparent sidereal time
% output
% gst = greenwich (mean or apparent) sidereal time in hours
Page 84
Celestial Computing with MATLAB
17. IAU 1980 Nutation in Longitude and Obliquity
This MATLAB function (nutation.m) calculates the nutation in longitude and obliquity
using the coefficients defined by the IAU 1980 nutation theory.
The nutation in longitude is determined from
1
sin
n
i i
i
S A ¢
=
A =
¿
Likewise, the nutation in obliquity is determined from
1
cos
n
i i
i
C A c
=
A =
¿
where
i i i i i i
A a l bl c F d D e ' = + + + + O
and are fundamental arguments. The number of terms in this nutation theory
is 106.
, , , and l l F D ' O
The nutation matrix defined by
0 0
0 0 0
0 0 0
cos sin cos sin sin
sin cos cos cos cos sin sin cos cos cos sin cos
sin sin cos sin cos cos sin cos sin sin cos cos
¢ ¢ c ¢ c
0
0
¢ c ¢ c c c c ¢ c c c c
¢ c ¢ c c c c ¢ c c c
A ÷ A ÷ A
(
(
= A A + A ÷
(
A A ÷ A + (
¸ ¸
N
c
can be used to transform a mean equinox of date position vector to a true equinox of date
position vector as follows:
0
r
r
 
0
= r N r
In this matrix
0
c is the mean obliquity of the ecliptic and
0
c c c = + A is the true obliquity.
The nutation matrix can also be expressed as a combination of individual rotations according
to
( ) ( ) ( )
1 3 1 0
c ¢ c = ÷ ÷A + N R R R
The mean obliquity of the ecliptic is calculated from
0 2
0
23 26 21. 448 46. 8150 0. 00059 0. 001813 T T c ' '' '' '' '' = ÷ ÷ +
3
T
where and JD is the Julian Date on the UT1 time scale. ( ) 2451545.0 / 36525 T JD = ÷
Page 85
Celestial Computing with MATLAB
If secondorder terms are neglected, a linearized nutation matrix can be calculated from
1 cos s
cos 1
sin 1
N
in ¢ c ¢
¢ c c
¢ c c
÷A ÷A
(
(
= A ÷A
(
A A (
¸ ¸
c
Finally, mean equinox equatorial rectangular position coordinates can be converted to true
equinox coordinates by adding the following corrections to the respective components:
( )
cos sin
cos
sin
x y z
y x z
z x y
r r r
r r r
r r r
c c ¢
c ¢ c
c ¢ c
A = ÷ + A
A = A ÷ A
A = A + A
The syntax of this MATLAB function is as follows:
function [dpsi, deps] = nutation (jdate)
% nutation in longitude and obliquity
% IAU 1980 version
% input
% jdate = julian date
% output
% dpsi = nutation in longitude (arc seconds)
% deps = nutation in obliquity (arc seconds)
Page 86
Celestial Computing with MATLAB
18. Precession Transformation
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.
According to J. H. Lieske, “Precession Matrix Based on IAU (1976) System of Astronomical
Constants”, Astronomy and Astrophysics, 73, 282284 (1979), the fundamental precession
matrix is defined by
cos cos cos sin sin cos cos sin sin cos cos sin
sin cos cos cos sin sin cos sin cos cos sin sin
sin cos sin sin cos
a a a a a a a a a a a a
a a a a a a a a a a a a
a a a a a
z z z z z
z z z z z
u , , u , , u
u , , u , ,
u , u , u
÷ ÷ ÷ ÷
(
(
= + ÷ + ÷
(
÷ (
¸ ¸
P u
The precession transformation of a position vector at epoch 1, , to a position vector at
epoch 2, , is determined from
1
r
2
r
   
2 1
2 2 1 1
2 1
x x
y y
z z
r r
r r
r r
¦ ¹ ¦ ¹
¦ ¦ ¦ ¦
¦ ¦ ¦
= = =
¦
´ ` ´ `
¦ ¦ ¦ ¦
¦ ¦ ¦
¹ ) ¹ )
r P r P
¦
The precession angles are given by
( ) ( )
( ) ( )
( ) ( )
2 2
2 2
2 2
2306.2181 1.39656 0.000139 0.30188 0.000344 0.017998
2306.2181 1.39656 0.000139 1.09468 0.000066 0.018203
2004.3109 0.85330 0.000217 0.42665 0.000217 0.041833
a
a
a
T T t T t
z T T t T t
T T t T t
,
u
= + ÷ + ÷ +
= + ÷ + + +
= ÷ ÷ + ÷ ÷ ÷
3
3
3
t
t
t
where the unit of these angular arguments is arc seconds and the time arguments are
( )
( )
1
1 2
2451545 / 36525
/ 36525
T JED
t JED JED
= ÷
= ÷
In these two equations
1
is the TDB Julian Date of the first epoch and is the TDB
Julian Date of the second epoch.
JED
2
JED
Page 87
Celestial Computing with MATLAB
The syntax of this MATLAB function is as follows:
function pos2 = precess (tjd1, pos1, tjd2)
% this function precesses equatorial rectangular coordinates from
% one epoch to another. the coordinates are referred to the mean
% equator and equinox of the two respective epochs. see pages 3034
% of the explanatory supplement to the ae, lieske, et al. (1977)
% astronomy and astrophysics 58, 116, and lieske (1979) astronomy
% and astrophysics 73, 282284.
% input
% tjd1 = tdb julian date of first epoch
% pos1 = position vector, geocentric equatorial rectangular
% coordinates, referred to mean equator and equinox of
% first epoch
% tjd2 = tdb julian date of second epoch
% output
% pos2 = position vector, geocentric equatorial rectangular
% coordinates, referred to mean equator and equinox of
% second epoch
Page 88
Celestial Computing with MATLAB
19. Kepler’s Equation
This section describes three MATLAB functions that can be used to solve the elliptic form of
Kepler’s equation given by
sin M E e E = ÷
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.
kepler1.m – Danby’s method
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) 95107, 317328 and 40
(1987) 303312.
The initial guess for Danby's method is
( )
0
0.85sign sin E M M = + e
The fundamental equation we want to solve is
( ) sin 0 f E E e E M = ÷ ÷ =
which has the first three derivatives given by
( )
( )
( )
1 cos
sin
cos
f E e
f E e E
f E e E
' = ÷
'' =
''' =
E
The iteration for an updated eccentric anomaly based on a current value is given by the
next four equations:
n
E
( )
( )
( )
2
1
1
2
1 1
2 6
n
n
n n
n n n
f
E
f
f
E
f f
f
E
f f f
E E


+
A = ÷
'
A = ÷
' '' + A
A = ÷
' '' ''' + A + A
= + A
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 c s
where c is the convergence tolerance. This tolerance is hardwired in the software to c
=1.0e10. Finally, the true anomaly can be calculated with the following two equations
2
sin 1 sin
cos cos
e E
E e
v
v
= ÷
= ÷
and the four quadrant inverse tangent given by
( )
1
tan sin , cos v v v
÷
=
If the orbit is hyperbolic the initial guess is
0
2
log 1.8
M
H
e
 
= +

\ .
where is the hyperbolic anomaly.
The fundamental equation and first three derivatives for this case are as follows:
0
H
( )
( )
( )
( )
sinh
cosh 1
sinh
cosh
f H e H H M
f H e H
f H e H
f H e H
= ÷ ÷
' = ÷
'' =
''' =
Otherwise, the iteration loop which calculates ,

A A , and so forth is the same. The true
anomaly for hyperbolic orbits is determined with this next set of equations:
2
sin 1sinh
cos cosh
e H
e H
v
v
= ÷
= ÷
The true anomaly is then determined from a four quadrant inverse tangent evaluation of these
two equations.
The syntax of this MATLAB function is
Page 90
Celestial Computing with MATLAB
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 (nondimensional)
% output
% eanom = eccentric anomaly (radians)
% tanom = true anomaly (radians)
kepler2.m – Danby’s method with Mikkola’s initial guess
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) 329334.
The elliptic orbit initial guess for this method is given by the expression
( )
3
0
3 4 E M e s s = + ÷
where
( )
( )
1
1
5
1
1/ 3
2 2
2
0.078
1
sign
1
1
4
2
1
2
1
4
2
s s ds
s z
s
ds
e
z
e
e
M
e
o
  o 
o

= +
= ÷
= ÷
+
= + +
÷
=
+
=
+
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
( ) ( )
5
2 2
0.071
1 0.45 1 4
s
ds
e s
=
+ + s
and the following initial guess for the hyperbolic anomaly:
( )
2
0
3log 1 H s = + + s
The syntax for 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)
% ecc = orbital eccentricity (nondimensional)
% output
% eanom = eccentric anomaly (radians)
% tanom = true anomaly (radians)
kepler3.m – Gooding’s two iteration method
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) 307334.
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 (nondimensional)
% output
% eanom = eccentric anomaly (radians)
% tanom = true anomaly (radians)
Page 92
Celestial Computing with MATLAB
kepler4.m – parabolic and nearparabolic orbits
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.
The form of Kepler’s equation solved by this function is
( ) ( ) ( )
0 3
sin E t e E t t t
a
µ
÷ = ÷
where
0
eccentric anomaly
orbital eccentricity
gravitational constant of the Sun
semimajor axis
time
time of perihelion passage
E
e
a
t
t
µ
=
=
=
=
=
=
The relationship between semimajor axis a and perihelion radius q is as follows:
1
q
a
e
=
÷
By introducing the variable
( )
3
3
1
ec E
U E
e
=
÷
Kepler’s equation is now given by
( ) ( )
3
3 0 3
1
6
3 2
U U ec E t t
q
µ
+ = ÷
where ( ) ( )
3
3
sin c E E e E E = ÷ . The kepler4 function iteratively solves for U.
The heliocentric distance is determined from the expression
2 2
3
2
1
6
c
r q U
c
  (
= +

(
¸ ¸
\ .
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 v =
where
2 2
3
1
3
2
1
6
1 1
2
2 6
c
x q U
ec
e
y q c
e c
 
(
= ÷

(
¸ ¸
\ .
U
( +
=
(
¸ ¸
The true anomaly can also be determined from
2
3 1
1
tan
2 3
e c
U
ec c
v
 
+
 
=


\ .
\ .
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
( )
( )
( )
0
1
0,1, 2,
2 !
k
k
n
k
x
c x k
k n
·
=
÷
= =
+
¿
For x real and , the first few terms are given by the following expressions: 0 x =
( ) ( )
( ) ( )
( ) ( )
2 2
0 0
2 2
1 1
2 2
2 2
cos cosh
sin sinh
1 cos cosh 1
c x x c x x
x x
c x c x
x x
x x
c x c x
x x
= ÷ =
= ÷ =
÷ ÷
= ÷ =
The Stumpff functions also satisfy the recursion relationship defined by
( ) ( )
2
1
0,1, 2,
!
k k
xc x c x k
k
+
= ÷ =
For , 0 x =
( )
1
!
n
c x
n
=
It is most efficient to compute and by series and then compute and by recursion
according to the following:
2
c
3
c
0
c
1
c
Page 94
Celestial Computing with MATLAB
( )
( )
0 2
1 3
1
1
c x xc
c x xc
= ÷
= ÷
The following is the syntax for this MATLAB function.
function [r, tanom] = kepler4(t, q, ecc)
% Kepler's equation for heliocentric
% parabolic and nearparabolic orbits
% input
% t = time relative to perihelion passage (days)
% q = perihelion radius (AU)
% ecc = orbital eccentricity (nondimensional)
% output
% r = heliocentric distance (AU)
% tanom = true anomaly (radians)
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
20. Twobody Orbital Motion
The following three MATLAB functions can be used to quickly and efficiently propagate
two body or “unperturbed” orbits. For programming flexibility the input and output
arguments for each routine are identical.
twobody1.m – Goodyear’s method
This function is a MATLAB implementation of Goodyear’s two body propagation algorithm.
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 ¢ =
where r is the distance of the spacecraft or celestial body.
The relationship between this generalized anomaly ¢ and the classical eccentric anomaly E
and hyperbolic anomaly F is given by
0 0
/ /
E E F F
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 r and r are as follows:
0 0
0 0 0
0 0 0
0 0
0
2
r
r
o
µ
o
= 
= 
=  ÷
r r
r r
r r
The generalized eccentric anomaly ¢ and the four transcendental functions given by
2 2 4 3 6
0
3 2 5 3 7
1
2 4 2 6 3 8
2
3 5 2 7 3 9
3
1
2! 4! 6!
3! 5! 7!
2! 4! 6! 8!
3! 5! 7! 9!
s
s
s
s
o¢ o ¢ o ¢
o¢ o ¢ o ¢
¢
¢ o¢ o ¢ o ¢
¢ o¢ o ¢ o ¢
= + + + +
= + + + +
= + + + +
= + + + +
Page 96
Celestial Computing with MATLAB
can be obtained by solving the next equation
0 0 1 0 2
t t r s s s
3
o µ = + + +
for the value of ¢ which satisfies all these equations.
The position magnitude at the final time is given by
0 0 0 2 3
r r s s s o µ = + +
The f and g functions and their derivatives are calculated with the four equations given by
( )
2
0
1
0
0 3
2
1
1
s
f
r
s
f
rr
g t t s
s
g
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:
( )
( )
0 0
0 0
t f g
t f g
= +
= +
r r
r r
r
r
The twobody gravity acceleration vector at the final time is given by
( )
3
t µ = ÷
r
r
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.
The syntax of this MATLAB function is
function [rf, vf] = twobody1 (tau, ri, vi)
Page 97
Celestial Computing with MATLAB
% solve the two body initial value problem
% Goodyear's method
% input
% tau = propagation time interval (seconds)
% ri = initial eci position vector (kilometers)
% vi = initial eci velocity vector (km/sec)
% output
% rf = final eci position vector (kilometers)
% vf = final eci velocity vector (km/sec)
twobody2.m – Sheppard’s method
This function is a MATLAB implementation of Stanley Shepperd’s two body propagation
algorithm. The derivation of this algorithm is described in “Universal Keplerian State
Transition Matrix”, Celestial Mechanics, 35 (1985) 129144. This algorithm uses a
combination of universal variables and continued fractions to propagate twobody orbits.
The syntax of this MATLAB function is
function [rf, vf] = twobody2 (tau, ri, vi)
% solution of the two body initial value problem
% Shepperd's method
% input
% tau = propagation time interval (seconds)
% ri = initial eci position vector (kilometers)
% vi = initial eci velocity vector (km/sec)
% output
% rf = final eci position vector (kilometers)
% vf = final eci velocity vector (km/sec)
twobody3.m – Stumpff/Danby method
This function is a MATLAB implementation of the Stumpff/Danby two body propagation
algorithm. It is based on a universal variable technique and Stumpff functions. This function
is valid for elliptic and hyperbolic orbits. The derivation of this algorithm can be found in
Professor Danby’s classic text Fundamentals of Celestial Mechanics.
The algorithm begins by computing an initial guess for s according to
2
x s o =
where
Page 98
Celestial Computing with MATLAB
0 0
0 0
2 2 2
0 0 0 0 0
2 2 2
0 0 0 0 0
2
0
0
position vector at initial time
velocity vector at initial time
2
x y z
x y z
t
t
r r r r
v v v v
v
r
µ
o
=
=
= = + +
= = + +
= ÷
r
v
r
v
This algorithm uses a universal variable form of Kepler’s equation defined by
( ) ( ) ( ) ( ) ( )
2 2 2 3 2
0 1 0 0 2 3 0
0 f s r sc s r r s c s s c s t t o o µ o = + + ÷ ÷ =
The first three derivatives of this form of Kepler’s equation are given by
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
2 2 2
0 0 0 0 1 2
2 2
0 1 0 0 0
2 2
0 0 0 0 1
2
f s r c s r r sc s s c s
f s r sc s r r c s
f s r c s r r sc s
o o µ
o µ o o
o µ o o o
' = + +
'' = ÷ + +
''' = ÷ + ÷
o
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
( )
( )
( )
0
1
0,1, 2,
2 !
k
k
n
k
x
c x k
k n
·
=
÷
= =
+
¿
for x real and x = 0
( ) ( )
( ) ( )
( ) ( )
2 2
0 0
2 2
1 1
2 2
2 2
cos cosh
sin sinh
1 cos cosh 1
c x x c x x
x x
c x c x
x x
x x
c x c x
x x
= ÷ =
= ÷ =
÷ ÷
= ÷ =
The Stumpff functions also satisfy the recursion relationship defined by
( ) ( )
2
1
0,1, 2,
!
k k
xc x c x k
k
+
= ÷ =
For x = 0,
Page 99
Celestial Computing with MATLAB
( )
1
!
n
c x
n
=
It is most efficient to compute c and c by series, and then compute c and c by recursion
according to the following:
2 3 0 1
( )
( )
0 2
1 3
1
1
c x xc
c x xc
= ÷
= ÷
The equations for the f and g functions and derivatives are as follows:
( )
( )
( )
( )
2 2
2
0
3 2
0 3
2
1
0
2 2
2
1
1
f s c s
r
g t t s c s
f sc s
rr
g s c
r
µ
o
µ o
µ
o
µ
o
 
= ÷

\ .
= ÷ ÷
 
= ÷

\ .
 
= ÷

\ .
s
Finally, the position and velocity vectors at the final time t are given by
( )
( )
0 0
0 0
t f g
t f g
= +
= +
r r
r r
r
r
The syntax of this MATLAB function is
function [rf, vf] = twobody3 (tau, ri, vi)
% solve the two body initial value problem
% Danby/Stumpff method
% input
% tau = propagation time interval (seconds)
% ri = initial eci position vector (kilometers)
% vi = initial eci velocity vector (km/sec)
% output
% rf = final eci position vector (kilometers)
% vf = final eci velocity vector (km/sec)
Page 100
Celestial Computing with MATLAB
21. Time and Date Functions
This section describes several MATLAB functions that can be used for time and date
conversions and manipulations.
julian.m – calendar date to Julian date
This MATLAB function converts a calendar date to its corresponding Julian date. Be sure to
pass this routine all digits of the calendar year.
The syntax of this MATLAB function is
function jdate = julian (month, day, year)
% Julian date subroutine
% Input
% month = calendar month [1  12]
% day = calendar day [1  31]
% year = calendar year [yyyy]
% Output
% jdate = Julian date
gdate.m – julian date to calendar date
This MATLAB function converts a Julian date to its corresponding calendar date.
The syntax of this MATLAB function is
function [month, day, year] = gdate (jdate)
% convert Julian date to Gregorian (calendar) date
% input
% jdate = Julian date
% output
% month = calendar month [1  12]
% day = calendar day [1  31]
% year = calendar year [yyyy]
jd2str.m – julian date to calendar date and universal time strings
This function converts a Julian date to its equivalent calendar date and universal time strings.
The syntax of this MATLAB function is
function [cdstr, utstr] = jd2str(jdate)
Page 101
Celestial Computing with MATLAB
% convert Julian date to string equivalent
% calendar date and universal time
% input
% jdate = Julian date
% output
% cdstr = calendar date string
% utstr = universal time string
utc2tdt.m – convert UTC Julian date to TDT Julian date
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.
The syntax of this MATLAB function is
function jdtdt = utc2tdt(jdutc)
% convert utc julian date to tdt julian date
% input
% jdutc = universal time julian date
% output
% jdtdt = terrestrial dynamic time julian date
tdt2tdb.m – convert TDT Julian date to TDB Julian date
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.
The syntax of this MATLAB function is
function jdtdb = tdt2tdb(jdtdt)
% convert terrestrial dynamic time julian
Page 102
Celestial Computing with MATLAB
% date to barycentric dynamic time julian date
% input
% jdtdt = tdt julian date
% output
% jdtdb = tdb julian date
hrs2hms.m – convert hours function
This function can be used to convert a floating point argument in hours into its equivalent
degrees, minutes, seconds, and string representation.
The syntax of this MATLAB function is
function [h, m, s, hmsstr] = hrs2hms (hrs)
% convert decimal hours to hours,
% minutes, seconds and equivalent string
% 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
22. Numerical Methods and Utility Routines
This section describes several fundamental MATLAB functions that can be used to create
custom applications.
TRIGONOMETRY AND VECTOR ROUTINES
atan3.m – four quadrant inverse tangent
This function calculates the four quadrant inverse tangent.
The syntax of this MATLAB function is
function y = atan3 (a, b)
% four quadrant inverse tangent
% input
% a = sine of angle
% b = cosine of angle
% output
% y = angle (radians; 0 =< c <= 2 * pi)
modulo.m – modulo 2 pi
This function will modulo an angle (in radians) between 0 and 2 t.
The syntax of this MATLAB function is
function y = modulo (x)
% modulo 2 pi function
% input
% x = argument (radians)
% output
% y = x modulo 2 pi
uvector.m – unit vector
This function calculates a unit vector from a user provided three component vector.
The syntax of this MATLAB function is
function vhat = uvector(x)
% unit vector
Page 104
Celestial Computing with MATLAB
% input
% x = 3component input vector
% output
% vhat = 3component unit vector
DIFFERENTIAL EQUATIONS
rkf45.m – RungeKuttaFehlberg 4(5) method for firstorder systems
This function is a MATLAB implementation of the 4(5) version of the RungeKuttaFehlberg
algorithm. It can be used to solve systems of first order, nonlinear vector differential
equations of the form . , y y = f t a f
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.
The syntax of this MATLAB function is
function xout = rkf45 (deq, neq, ti, tf, h, tetol, y)
% solution of first order system of differential equations
% RungeKuttaFehlberg 4(5)
% fourthorder solution with fifthorder error control
% input
% neq = number of equations in system
% ti = initial simulation time
% tf = final simulation time
% h = guess for step size
% tetol = truncation error tolerance
% y = initial integration vector
% output
% xout = final integration vector
rkf78.m – RungeKuttaFehlberg 7(8) method for firstorder systems
This function is a MATLAB implementation of the 7(8) version of the RungeKuttaFehlberg
algorithm. It can be used to solve systems of first order, nonlinear vector differential
equations of the form ( ) , f t = y y .
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.
Near the end of this function is the following code:
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;
% compute new step size
dt = 0.7 * dt * (1 / xerr) ^ (1 / 8);
else
% rectify and reinitialize
ytbf = twobody4(dt, ytbi);
for i = 1:1:6
ytrue(i) = ytbf(i) + x(i);
ytbi(i) = ytrue(i);
x(i) = 0;
end
tsaved = ti;
end
The following is the syntax for this MATLAB function.
function xout = rkf78 (deq, neq, ti, tf, h, tetol, x)
Page 106
Celestial Computing with MATLAB
% solve first order system of differential equations
% RungeKuttaFehlberg 7(8) method
% input
% deq = name of function which defines the
% system of differential equations
% neq = number of differential equations
% ti = initial simulation time
% tf = final simulation time
% h = initial guess for integration step size
% tetol = truncation error tolerance (nondimensional)
% x = integration vector at time = ti
% output
% xout = integration vector at time = tf
nym4.m – Nystrom fourthorder method for secondorder systems
This function is a MATLAB implementation of a fourthorder Nystrom algorithm. It can be
used to solve systems of second order differential equations of the form . , , x x x = f t b g
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.
The syntax of this MATLAB function is
function [rf, vf] = nym4(deq, n, tp, dt, rs, vs)
% solve a system of second order differential equations
% fourth order Nystrom method (fixed step size)
% input
% deq = function name of systems of
% differential equations
% n = number of equations in userdefined
% system of differential equations
% tp = current simulation time
% dt = integration step size
% rs = position vector at initial time
% vs = velocity vector at initial time
% output
% rf = position vector at time = tp + dt
% vf = velocity vector at time = tp + dt
Page 107
Celestial Computing with MATLAB
ceqm1.m – firstorder heliocentric equations of orbital motion
This MATLAB function evaluates the firstorder form of the heliocentric equations of orbital
motion. It includes the pointmass gravity perturbations due to Venus, Earth, Mars, Jupiter
and Saturn. The fundamental coordinate system used in this algorithm is the trueofdate
ecliptic and equinox.
The syntax of this MATLAB function is
function yddot = ceqm1 (time, y)
% first order form of the heliocentric
% equations of motion
% includes point mass gravity
% perturbations of Venus, Earth,
% Mars, Jupiter and Saturn
% input
% time = current simulation time
% y = current state vector
% output
% yddot = equations of motion
The secondorder heliocentric equations of motion of a satellite or celestial body subject to
the pointmass gravitational attraction of the Sun and planets are given by
( )
( )
( )
2 9
3 3 2
1
,
i i
i
i
i
p b
p
s b
s p
i
s b
p
p b
d
t
dt
µ µ
÷
÷
=
÷
÷
 

= = ÷ ÷ +


\ .
¿
r
r
r r
r r
r
r
r
3
where
gravitational constant of the Sun
gravitational constant of planet
position vector from the Sun to planet
position vector from the Sun to the body
position vector from the plane
i
s
p
p
s b
p b
i
µ
µ
÷
÷
=
=
=
=
=
r
r
r t to the body
These position vectors are related according to
r r r
s b p p b ÷ ÷
= +
Page 108
Celestial Computing with MATLAB
meeeqm.m – modified equinoctial equations of motion
This MATLAB function evaluates the modified equinoctial orbital elements form of the
equations of heliocentric orbital motion.
The syntax for this MATLAB function is
function ydot = meeeqm(t, y)
% modified equinoctial equations of motion
% input
% y(1) = semilatus rectum of orbit (kilometers)
% y(2) = f equinoctial element
% y(3) = g equinoctial element
% y(4) = h equinoctial element
% y(5) = k equinoctial element
% y(6) = true longitude (radians)
% output
% ydot = first time derivatives of
% modified equinoctial elements
The perturbation vector used in these calculations is computed in a MATLAB function called
ceqm2.m. The syntax of this function is as follows:
function ywrk = ceqm2 (t, r, v)
% eci perturbation vector
% support function for cowell4.m
% includes perturbations due to:
% nonspherical earth gravity
% aerodynamic drag (us 76 model)
% solar radiation pressure
% sun and moon
% input
% t = current simulation time
% r = current eci position vector
% v = current eci velocity vector
% output
% ywrk = eci perturbation vector
The equations of orbital motion expressed in terms of modified equinoctial orbital elements
are as follows:
Page 109
Celestial Computing with MATLAB
( ) ( )
( ) ( )
2
2
2
2
sin 1 cos sin cos
cos 1 sin sin cos
cos
2
sin
2
1
sin cos
t
t n
r
t n
r
n
n
dp p p
p
dt w
df p g
f L w L f h L k
dt w w
dg p g
g L w L g h L k
dt w w
dh p s
h L
dt w
dk p s
k L
dt w
dL w p
L p h L k
dt p w
µ
µ
µ
µ
µ
µ
µ
= = A
A A
(
= = A + + + ÷ ÷ (
¸ ¸
(
¸ ¸
L
L
A A
(
= = ÷A + + + + ÷ (
¸ ¸
(
¸ ¸
A
= =
A
= =
 
= = + ÷

\ .
( )
n
L A
where are external perturbations in the radial, tangential and orbit normal
directions, respectively.
, ,
r t
A A A
n
ROOTFINDING AND OPTIMIZATION
broot.m – bracket a single root of a nonlinear function
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
1
x and
2
x such that ( ) ( )
1 2
0 f x f x < .
The user must supply this function with an initial guess for
1
x and
2
x . Typically
1
x is the
time of an objective function minimum or maximum and
2
x is a time 10 seconds after
(forward root) or 10 seconds before (backward root) the value of
1
x
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 xaxis is the number of steps taken
in the search for the bracketing interval and the yaxis 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
1
x and
2
x of this bracketing interval.
0 5 10 15 20 25 30
0.243
0.244
0.245
0.246
0.247
0.248
0.249
0.25
Number of Steps
S
i
m
u
l
a
t
i
o
n
T
i
m
e
(
d
a
y
s
)
rectification
root
minimum
The syntax of this MATLAB function is
function [x1out, x2out] = broot (f, x1in, x2in, factor, dxmax)
% bracket a single root of a nonlinear equation
% input
% f = objective function coded as y = f(x)
% x1in = initial guess for first bracketing x value
% x2in = initial guess for second bracketing x value
% factor = acceleration factor (nondimensional)
% dxmax = rectification interval
% output
% x1out = final value for first bracketing x value
% x2out = final value for second bracketing x value
brent.m – solve for a single root of a nonlinear function
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 ( ) ( ) (
1 2
0 f x f x
)
< before calling this routine.
The syntax of this MATLAB function is
Page 111
Celestial Computing with MATLAB
function [xroot, froot] = brent (f, x1, x2, rtol)
% solve for a single real root of a nonlinear equation
% Brent's method
% input
% f = objective function coded as y = f(x)
% x1 = lower bound of search interval
% x2 = upper bound of search interval
% rtol = algorithm convergence criterion
% output
% xroot = real root of f(x) = 0
% froot = function value at f(x) = 0
minima.m – onedimensional minimization
This function uses Brent’s method to find a single minimum or maximum of a single user
defined nonlinear “objective” function.
The syntax of this MATLAB function is
function [xmin, fmin] = minima (f, a, b, tolm)
% onedimensional minimization subroutine
% Brent's method
% input
% f = objective function coded as y = f(x)
% a = initial x search value
% b = final x search value
% tolm = convergence criterion
% output
% xmin = minimum x value
% fmin = minimum function value
oevent1.m – find minimization/root finding orbital event
This MATLAB function is a combined onedimensional minimization and rootfinding
algorithm. It first finds minima or maxima within a userdefined search interval, and then
calculates the corresponding “reverse” and “forward” root.
The syntax of this MATLAB function is
function oevent1 (objfunc, prtfunc, ti, tf, dt, dtsml)
% predict minimization/rootfinding orbital events
% input
Page 112
Celestial Computing with MATLAB
% objfunc = objective function
% prtfunc = display results function
% ti = initial simulation time
% tf = final simulation time
% dt = step size used for bounding minima
% dtsml = small step size used to determine whether
% the function is increasing or decreasing
ATMOSPHERIC REFRACTION
refract.m – refraction correction function
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
10.3
tan
5.11
E
E
E
A =
 
+

+
\ .
where E is the true topocentric elevation angle in degrees.
The syntax of this MATLAB function is
function elev2 = refract(elev1)
% refraction correction
% input
% elev1 = uncorrected angle (radians)
% output
% elev2 = angle corrected for refraction (radians)
refract1.m – NOVAS refraction correction function
This MATLAB function determines the effect of atmospheric refraction using the algorithm
included in the NOVAS software suite from the Naval Observatory.
The syntax of this MATLAB function is
function refr = refract1 (height, zdobs)
% this subroutine computes atmospheric refraction in zenith
% distance. this version computes approximate refraction for
% optical wavelengths. it can be used for planning observations
% or telescope pointing, but should not be used for the reduction
% of precise observations. basic algorithm is described in the
% explanatory supplement to the astronomical almanac, p. 144,
% and is an adaptation of a formula in bennett (1982), journal
% of navigation (royal institute) 35, 255259.
% height = height of observer in meters (in)
Page 113
Celestial Computing with MATLAB
% zdobs = observed zenith distance in degrees (in)
% refr = atmospheric refraction in degrees (out)
refract2.m – refraction correction function including temperature/pressure effects
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 4224.
The syntax of this MATLAB function is
function elev2 = refract2(press, temp, elev1)
% optical refraction correction
% input
% press = atmospheric pressure (mm of Hg)
% temp = atmospheric temperature (degrees C)
% elev1 = uncorrected elevation angle (radians)
% output
% elev2 = elevation angle corrected
% for refraction (radians)
UTILITY ROUTINES
oeprint1.m – formatted classical orbital elements screen display
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.
The syntax of this MATLAB function is
function oeprint1(oev)
% print six classical orbital elements
% (orbital period in days)
% input
% oev(1) = semimajor axis (kilometers)
% oev(2) = orbital eccentricity (nondimensional)
% (0 <= eccentricity < 1)
% oev(3) = orbital inclination (radians)
% (0 <= inclination <= pi)
% oev(4) = argument of periapsis (radians)
% (0 <= argument of periapsis <= 2 pi)
% oev(5) = right ascension of ascending node (radians)
% (0 <= raan <= 2 pi)
% oev(6) = true anomaly (radians)
% (0 <= true anomaly <= 2 pi)
Page 114
Celestial Computing with MATLAB
svprint.m – formatted state vector screen display
This function prints a formatted display of the components and scalar magnitudes of a state
vector (position and velocity vectors and magnitudes).
The syntax of this MATLAB function is
function svprint(r, v)
% print position and velocity vectors and magnitudes
% input
% r = position vector (kilometers)
% v = velocity vector (kilometers/second)
deg2dms.m – convert degrees function
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)
produces the following screen output:
+22d 07m 24.42s
The syntax of this MATLAB function is
function [d, m, s, dmsstr] = deg2dms (dd)
% convert decimal degrees to degrees,
% minutes, seconds and equivalent string
% input
% dd = angle in decimal degrees
% output
% d = integer degrees
% m = integer minutes
% s = seconds
% dmsstr = string equivalent of input
INTERACTIVE REQUEST OF PROGRAM INPUTS
getdate.m – request calendar date
This function interactively requests the calendar date. Please note that all digits of the
calendar year are required.
Page 115
Celestial Computing with MATLAB
The syntax of this MATLAB function is
function [m, d, y] = getdate
% interactive request and input of calendar date
% 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.
please input the calendar date
(1 <= month <= 12, 1 <= day <= 31, year = all digits!)
?
The calendar date should be input with individual elements separated by commas.
getobs.m – request observer coordinates
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.
The syntax of this MATLAB function is
function [obslat, obslong, obsalt] = getobs
% interactive request of ground site coordinates
% output
% obslat = geographic latitude (radians)
% obslong = geographic longitude (radians)
% obsalt = geodetic altitude (kilometers)
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.
please input the geographic latitude of the ground site
(90 <= degrees <= +90, 0 <= minutes <= 60, 0 <= seconds <= 60)
(north latitude is positive, south latitude is negative)
? 40,35,10
please input the geographic longitude of the ground site
(0 <= degrees <= 360, 0 <= minutes <= 60, 0 <= seconds <= 60)
(east longitude is positive, west longitude is negative)
? 105,30,45
please input the altitude of the ground site (meters)
(positive above sea level, negative below sea level)
? 100
Page 116
Celestial Computing with MATLAB
getoe.m – request classical orbital elements
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.
The syntax of this MATLAB function is
function oev = getoe(ioev)
% interactive request of classical orbital elements
% NOTE: all angular elements are returned in radians
% input
% ioev = request array (1 = yes, 0 = no)
% 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
gettime.m – request universal time
This function interactively requests the universal time in hours, minutes and seconds.
The syntax of this MATLAB function is
function [uthr, utmin, utsec] = gettime
% interactive request and input of universal time
% output
% uthr = universal time (hours)
% utmin = universal time (minutes)
% utsec = universal time (seconds)
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
RECTANGULAR AND ORTHOGRAPHIC GRAPHICS
demomwdb.m – MicroWorld Database map files
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 IBMPC compatible computers. The map features that are plotted by this
utility are defined in the code as follows:
% define plot features
% (set to 1 to activate);
allfeatures = 0;
coastlines = 1;
countries = 0;
states = 0;
islands = 1;
lakes = 0;
rivers = 0;
The following is a typical plot created with this script.
−150 −100 −50 0 50 100 150
−80
−60
−40
−20
0
20
40
60
80
pltortho.m – plot orthographic view of the Earth
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.
The syntax of this MATLAB function is
Page 118
Celestial Computing with MATLAB
function pltortho(vplat, vplong, dlat, dlong)
% plot orthographic world map
% input
% vplat = viewpoint latitude (degrees)
% (90 <= vplat <= 90)
% vplong = viewpoint longitude (degrees)
% (180 <= vplong <= 180)
% dlat = latitude grid spacing (degrees)
% (0 <= dlat <= 90)
% dlong = longitude grid spacing (degrees)
% (0 <= dlong <= 360)
% note
% east longitudes are positive,
% west longitudes are negative
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
pltrect.m – plot rectangular map of the Earth
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.
−180 −120 −60 0 60 120 180
−90
−60
−30
0
30
60
90
longitude
l
a
t
i
t
u
d
e
Page 120
Celestial Computing with MATLAB
23. Astronomical Coordinates
This section describes several MATLAB functions that can be used to calculate and convert
different types of astronomical coordinates.
In the following discussions
right ascension
declination
ecliptic longitude
ecliptic latitude
topocentric azimuth
topocentric altitude
hour angle
observer's local sidereal time
observer's geodetic latitude
A
h
H
o
o
ì

u o
u

=
=
=
=
=
=
= = ÷
=
=
obliquity of the ecliptic c =
Also, equations involving a two argument inverse tangent denote calculations that are
performed with the four quadrant inverse tangent function atan3.m.
rec2pol.m – rectangular to polar coordinate conversion
The scalar distance can be determined from the three components of the rectangular position
vector as follows:
2 2 2
x y z
r r r µ = + +
The longitudinal polar coordinate is computed using a four quadrant inverse tangent function
as follows:
( )
1
tan ,
y x
r r u
÷
=
The latitudinal polar coordinate is calculated using the expression given by
1
2 2
tan
z
x y
r
r r
o
÷
 

=

+
\ .
The syntax of this MATLAB function is
function [rmag, lambda, phi] = rec2pol(r)
% rectangular to polar coordinate conversion
Page 121
Celestial Computing with MATLAB
% input
% r = rectangular position vector
% output
% rmag = vector scalar magnitude
% lambda = longitudinal polar coordinate (radians)
% (0 <= lambda <= 2*pi)
% phi = latitudinal polar coordinate (radians)
% (pi/2 <= phi <= pi/2)
pol2rec.m – polar to rectangular coordinate conversion
The three components of the rectangular position vector are determined from the scalar
distance µ , the longitudinal polar coordinate u and the latitudinal polar coordinate o
as follows:
cos cos
sin cos
sin
o u
µ o u
u
 

=


\ .
r
The syntax of this MATLAB function is
function r = pol2rec(rmag, lambda, phi)
% polar to rectangular coordinate conversion
% input
% rmag = vector scalar magnitude
% lambda = longitudinal polar coordinate (radians)
% (0 <= lambda <= 2*pi)
% phi = latitudinal polar coordinate (radians)
% (pi/2 <= phi <= pi/2)
% output
% r = rectangular position vector
ecl2equ.m – ecliptic to equatorial coordinate conversion
The conversion from ecliptic to equatorial coordinates is given by the following two
equations:
( )
1
tan sin cos tan sin , cos o ì c  c ì
÷
= ÷
( )
1
sin sin cos cos sin sin o  c  c ì
÷
= +
The syntax of this MATLAB function is
function [rasc, decl] = ecl2equ(lat, lon, obliq)
% ecliptic to equatorial coordinate conversion
Page 122
Celestial Computing with MATLAB
% input
% lat = ecliptic latitude (radians)
% lon = ecliptic longitude (radians)
% obliq = obliquity of the ecliptic (radians)
% output
% rasc = geocentric right ascension (radians)
% decl = geocentric declination (radians)
equ2ecl.m – equatorial to ecliptic coordinate conversion
The following two equations convert equatorial coordinates to ecliptic coordinates:
( )
1
tan sin cos tan sin , cos ì o c o c o
÷
= +
( )
1
sin sin cos cos sin sin  o c o c o
÷
= ÷
The syntax of this MATLAB function is
function [lat, long] = equ2ecl(decl, rasc, obliq)
% equatorial to ecliptic coordinate conversion
% input
% rasc = geocentric right ascension (radians)
% decl = geocentric declination (radians)
% obliq = obliquity of the ecliptic (radians)
% output
% lat = ecliptic latitude (radians)
% lon = ecliptic longitude (radians)
equ2hor.m – equatorial to local horizontal coordinate conversion
The conversion from equatorial to local horizontal coordinates is given by the following two
expressions:
( )
1
tan sin , cos sin tan cos A H H  o 
÷
= ÷
( )
1
sin sin sin cos cos cos h H  o  o
÷
= +
The syntax of this MATLAB function is
function [azimuth, elevation] = equ2hor(obslat, obslst, decl, rasc)
% equatorial to local horizontal coordinate conversion
% input
Page 123
Celestial Computing with MATLAB
% obslat = observer's geodetic latitude (radians)
% obslst = observer's local sidereal time (radians)
% decl = object's declination (radians)
% rasc = object's right ascension (radians)
% output
% azimuth = object's topocentric azimuth angle (radians)
% elevation = object's topocentric elevation angle (radians)
% notes
% (1) azimuth positive clockwise from north
% (2) elevation positive above the local horizontal
hor2equ.m – local horizontal to equatorial coordinate conversion
The conversion from local horizontal to equatorial coordinates is as follows:
( )
1
tan sin , cos cos tan cos H A A h  
÷
= +
( )
1
sin sin sin cos cos cos h h o  
÷
= ÷ A
The syntax of this MATLAB function is
function [decl, rasc] = hor2equ(obslat, obslst, azimuth, elevation)
% local horizontal to equatorial coordinate conversion
% input
% azimuth = object's topocentric azimuth angle (radians)
% elevation = object's topocentric elevation angle (radians)
% obslat = observer's geodetic latitude (radians)
% obslst = observer's local sidereal time (radians)
% output
% decl = object's declination (radians)
% rasc = object's right ascension (radians)
% notes
% (1) azimuth positive clockwise from north
% (2) elevation positive above the local horizontal
oepreces.m – transform angular orbital elements from one equinox to another
This MATLAB function can be used to transform angular orbital elements from one equinox
to another. The orbital inclination , argument of periapsis i e , and longitude of ascending
node O are the only orbital elements that depend on the position of the equinox.
In the equations which follow, ,
0
i
0
O , and
0
e 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:
( )
0 0
cos cos cos sin sin cos
A A A
i i i t t = + H
0
÷ O
( ) ( )
0 0
sin sin sin sin
A A A
i p i + H ÷ O = H ÷ O
( ) ( )
0 0
sin cos sin cos cos sin cos
A A A A A
i p i i t t + H ÷ O = ÷ + H ÷ O
0
The correction to the argument of perapsis can be calculated from the following two
expressions:
( )
0 0
sin sin sin cos cos sin cos
A A A
i i i e t t A = ÷ H ÷ O
0
( )
0 0
cos sin sin cos cos sin cos
A A A
i i i e t t A = ÷ H ÷ O
0
The argument of periapsis corrected for precession is as follows:
0
e e e = + A
In these expressions
A
t ,
A
H , and
A
p are fundamental precessional quantities which are
functions of time. They are described in “Precession Matrix Based on IAU (1976) System of
Astronomical Constants”, Astronomy and Astrophysics, 73, 282284 (1979) by J. H. Lieske.
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.
The syntax of this MATLAB function is
function oev2 = oepreces (eqnx1, eqnx2, oev1)
% transform angular orbital elements
% from one equinox to another equinox
% input
% eqnx1 = initial equinox
% eqnx2 = final equinox
% oev1 = orbital elements referred to eqnx1
% oev1(1) = orbital inclination
% oev1(2) = longitude of ascending node
% oev1(3) = argument of periapsis
% output
Page 125
Celestial Computing with MATLAB
% oev2 = orbital elements referred to eqnx2
% oev2(1) = orbital inclination
% oev2(2) = longitude of ascending node
% oev2(3) = argument of periapsis
gsite.m – ground site position vector
This MATLAB function calculates either the Earthcenteredinertial (ECI) or Earthcentered
fixed (ECF) position vector of a ground site located on an oblate Earth.
1
2
2
cos cos
cos sin
sin
x
y
z
r G
r G
r G
 u
 u

=
=
=
For ECI site coordinates u is equal to the local sidereal time, and for ECF coordinates u 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.
The geodetic constants and are calculated as follows:
1
G
2
G
( )
( )
( )
1
2 2
2
2
2 2
1 2 sin
1
1 2 sin
eq
eq
r
G h
f f
r f
G h
f f


= +
÷ ÷
÷
= +
÷ ÷
where
Earth flattening factor
Earth equatorial radius
geodetic latitude
geodetic altitude
eq
f
r
h

=
=
=
=
The syntax of this MATLAB function is
function rsite = gsite (lat, alt, angle)
% ground site position vector
% input
% lat = geodetic latitude (radians)
% (+north, south; pi/2 <= lat <= pi/2)
% alt = geodetic altitude (meters)
% (+ above sea level,  below sea level)
% angle = local sidereal time or east longitude
% (radians; 0 <= angle <= 2*pi)
Page 126
Celestial Computing with MATLAB
% output
% rsite = ground site position vector (kilometers)
geodet1.m – convert geocentric coordinates to geodetic coordinates  series solution
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, o 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
( )
( )
cos cos 0
sin sin 0
c h r
s h r
¢ o
¢ o
+ ÷ =
+ ÷ =
where the geodetic constants c and s are given by
( )
( )
2 2
2
1 2 sin
1
eq
r
c
f f
s c f
¢
=
÷ ÷
= ÷
and is the Earth equatorial radius (6378.14 kilometers) and
eq
r f is the flattening factor for
the Earth (1/298.257).
The geodetic latitude is determined using the following expression:
Page 127
Celestial Computing with MATLAB
2
2
sin2 1 1
sin4
4
f f
o
 o o
µ µ µ
(    
= + + ÷
(  
\ . \ .
¸ ¸
The geodetic altitude is calculated from
( ) ( )
2
1 cos2 1 1
ˆ
ˆ 1 1
2 4 16
h r f f
o
o
µ
¦ ¹
(
  ÷ ¦ ¦  
= ÷ + + ÷ ÷
´ ` (  
\ .
\ . ¦ ¦ ¸ ¸ ¹ )
cos4
In these equations, µ is the geocentric distance of the object, and
ˆ
/
eq
h h r = ˆ /
eq
r r µ = .
The syntax of this MATLAB function is
function [alt, lat] = geodet1 (rmag, dec)
% geodetic latitude and altitude
% series solution
% input
% rmag = geocentric radius (kilometers)
% dec = geocentric declination (radians)
% (+north, south; pi/2 <= dec <= +pi/2)
% output
% alt = geodetic altitude (kilometers)
% lat = geodetic latitude (radians)
% (+north, south; pi/2 <= lat <= +pi/2)
geodet2.m – convert geocentric coordinates to geodetic coordinates – exact solution
This MATLAB function uses the exact solution of K. M. Borkowski (“Accurate Algorithms
to Transform Geocentric to Geodetic Coordinates”, Bullentin Geodesique, 63 No. 1, 5056)
to convert geocentric distance and declination to geodetic altitude and latitude. The
calculation steps for this numerical method are as follows:
( )
( )
2 2
2 2
2 2
z
z
x y
br a b
E
ar
br a b
F
ar
r r r
(
÷ ÷
¸ ¸
=
(
+ ÷
¸ ¸
=
= +
where a is the equatorial radius of the Earth and b is determined from
Page 128
Celestial Computing with MATLAB
( ) sign
z
a
b r a
f
 
= ÷

\ .
The calculations continue with
( )
( )
( )
2 2
3 2
1/ 3
1/ 2
2
2
4
1
3
2
1
2
2
P EF
Q E F
D P Q
v D Q
G E v E
F vG
t G
G E
= +
= ÷
= +
= ÷
(
= + +
¸ ¸
÷
(
= +
(
÷
¸ ¸
The geodetic latitude is determined from the expression
2
1
arctan
2
t
a
bt

  ÷
=

\ .
and the geodetic altitude is calculated from
( ) ( ) cos sin
z
h r at r b   = ÷ + ÷
The syntax of this MATLAB function is
function [xlat, alt] = geodet2(decl, rmag)
% geocentric to geodetic coordinates
% exact solution (Borkowski, 1989)
% input
% decl = geocentric declination (radians)
% rmag = geocentric distance (kilometers)
% output
% xlat = geodetic latitude (radians)
% alt = geodetic altitude (kilometers)
geodet3.m – convert geodetic coordinates to ECF position vector
This function converts geodetic latitude, longitude and altitude to an Earthcenteredfixed
(ECF) position vector. The components of this vector are given by
Page 129
Celestial Computing with MATLAB
( )
( )
( )
2
cos cos
cos sin
1 si
e
geocentric e
N h
N h
N e h n
 ì
 ì

(
+
(
( = +
(
(
÷ +
(
¸ ¸
¸ ¸
r
where
2 2
2 2
1 sin
2
Earth flattening factor
Earth equatorial radius
geodetic latitude
east longitude
geodetic altitude
eq
eq
e
r
N
e
e f f
f
r
h


ì
=
÷
= ÷
=
=
=
=
=
The geocentric distance is determined from the components of the geocentric position vector
as follows:
2 2 2
x y z
r r r r = + +
The geocentric declination can be computed from the z component of the geocentric position
vector with
1
sin
z
r
r
o
÷
 
=

\ .
The syntax of this MATLAB function is
function r = geodet3 (lat, long, alt)
% ecf position vector
% input
% lat = geodetic latitude (radians)
% (+north, south; pi/2 <= lat <= +pi/2)
% long = geodetic longitude (radians)
% alt = geodetic altitude (kilometers)
% output
% r = ecf position vector (kilometers)
geodet4.m – convert geodetic coordinates to geocentric coordinates
This MATLAB function converts geodetic latitude and altitude to geocentric position
magnitude and geocentric declination.
Page 130
Celestial Computing with MATLAB
The equations for this method are as follows:
( ) ( )
( )
2
2 2
sin2 sin2 1 1
sin4
ˆ ˆ
ˆ ˆ 1 4 1
2 1 4 1
f f
h h
h h
 
o  
¦ ¹
(
÷ ÷ ¦ ¦  
(
= + + + +
´ `

(
+ \ . +
+ + ¦ ¦
(
¸ ¸ ¹ )
and
( )
( )
( )
2
cos2 1 1 1
ˆ
ˆ 1 1
ˆ
2 16
4 1
h f
h

µ  cos4 f
¦ ¹
(
÷ ¦ ¦  
(
= + + + + ÷
´ `

( \ . +
¦ ¦
¸ ¸ ¹ )
where the geocentric distance r and geodetic altitude h have been normalized by ˆ /
eq
r r µ =
and , respectively, and is the equatorial radius of the Earth.
ˆ
/
eq
h h r =
eq
r
The syntax of this MATLAB function is
function [rmag, dec] = geodet4 (lat, alt)
% geodetic to geocentric coordinates
% input
% lat = geodetic latitude (radians)
% (+north, south; pi/2 <= lat <= +pi/2)
% alt = geodetic altitude (kilometers)
% output
% rmag = geocentric position magnitude (kilometers)
% dec = geocentric declination (radians)
% (+north, south; pi/2 <= dec <= +pi/2)
triaxial.m – geodetic altitude to a triaxial ellipsoid
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, JulySeptember 1988, pp. 279283.
This function solves for the real root of the following nonlinear equation:
( )
( ) ( )
2 2
2 2
2 2 2 2
1 0
y
x
p p
z p z p
c
c
f z z c
c b c z c a c z
¦ ¹
¦ ¦
= + + ÷ =
´ `
( (
+ ÷ + ÷ ¦ ¦
¸ ¸ ¸ ¸ ¹ )
where
Page 131
Celestial Computing with MATLAB
( )
( )
( )
2
2
2
, , semiaxes
, , geocentric coordinates of satellite
z coordinate of subpoint
x s
y s
z s
s s s
p
c acx
c bcy
c c z
a b c a b c
x y z
z
=
=
=
= > >
=
=
The bracketing interval used during the rootfinding is
0
10 10
p p p
z z z
0
÷ s s + (kilometers)
where
( ) ( ) ( )
0
2 2
/ / /
s
p
s s s
z
z
2
x a y b z c
=
+ +
The syntax of this MATLAB function is
function alt = triaxial(rsc)
% geodetic altitude relative
% to a triaxial ellipsoid
% input
% rsc = geocentric position vector (km)
% output
% alt = geodetic altitude (km)
The semiaxes in this function are “hardwired” to the values 6378.138 a = and
(kilometers), and the flattening factor is
6367 b =
1/ 298.257 f = . These are representative values for
the Earth and can be easily changed for other planets or the Moon.
orb2eci.m – convert classical orbital elements to inertial state vector
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
( ) ( )
( ) ( )
( )
cos cos sin cos sin
sin cos cos cos sin
sin sin
x
y
z
r p i
r p i
r p i
e v e v
e v e
e v
= O + ÷ O + (
¸ ¸
= O + + O + (
¸ ¸
= +
v
The components of the inertial velocity vector are computed using the following equations:
Page 132
Celestial Computing with MATLAB
( ) { } ( ) { }
( ) { } ( ) { }
( ) { }
cos sin sin sin cos cos cos
sin sin sin cos cos cos cos
sin cos cos
x
y
z
v e i
p
v e i
p
v i e
p
µ
e
e
e v e e v
µ
e
e v e e v
µ
e v e
( = ÷ O + + + O + +
¸ ¸
( = ÷ O + + ÷ O + +
¸ ¸
( = ÷ + +
¸ ¸
e
where
( )
2
semimajor axis
orbital eccentricity
orbital inclination
argument of periapsis
right ascension of the ascending node
true anomaly
1
a
e
i
p a e
e
v
=
=
=
=
O =
=
= ÷
The syntax of this MATLAB function is
function [r, v] = orb2eci(oev)
% convert classical orbital elements to inertial state vector
% input
% oev(1) = semimajor axis (kilometers)
% oev(2) = orbital eccentricity (nondimensional)
% (0 <= eccentricity < 1)
% oev(3) = orbital inclination (radians)
% (0 <= inclination <= pi)
% oev(4) = argument of periapsis (radians)
% (0 <= argument of periapsis <= 2 pi)
% oev(5) = right ascension of ascending node (radians)
% (0 <= raan <= 2 pi)
% oev(6) = true anomaly (radians)
% (0 <= true anomaly <= 2 pi)
% output
% r = eci position vector (kilometers)
% v = eci velocity vector (kilometers/second)
eci2orb.m – convert inertial state vector to six classical orbital elements
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
semimajor axis
orbital eccentricity
orbital inclination
argument of periapsis
right ascension of the ascending node
true anomaly
a
e
i
e
v
=
=
=
=
O =
=
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 xaxis,
the vernal equinox, and a fundamental plane, the ecliptic or the equator. The zaxis of this
system is collinear with either the spin axis of the Earth or the north ecliptic pole, and the y
axis completes a righthanded 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 xaxis (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 v e = + .
The orbital eccentricity is an indication of the type of orbit. For values of , the orbit
is circular or elliptic. The orbit is parabolic when
0 e s <1
1 e = and the orbit is hyperbolic if 1 e >
The semimajor axis is calculated using the following expression:
2
1
2
a
v
r µ
=
÷
where
2 2 2
x y z
r r r = = + + r r and
2 2 2
x y z
v v v v = = + + v . The angular orbital elements are
calculated from the equinoctial orbital elements that are calculated from the ECI position and
velocity vectors.
The scalar orbital eccentricity is determined from h and k as follows:
2 2
e h k = +
The orbital inclination is determined from p and q using the following expression
( )
1 2 2
2tan i p
÷
= + q
For values of inclination greater than a small value c , the right ascension of the ascending
node (RAAN) is given by
( )
1
tan , p q
÷
O =
Otherwise, the orbit is equatorial and there is no RAAN. If the value of orbital eccentricity is
greater than c , the argument of perigapsis is determined from
( )
1
tan , h k e
÷
= ÷ O
Otherwise, the orbit is circular and there is no argument of periapsis. In the MATLAB code
for these calculations, .
8
10 c
÷
=
Finally, the true anomaly is found from the expression
v ì e = ÷ O÷
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 2t function, modulo.m.
The syntax of this MATLAB function is
function oev = eci2orb (r, v)
% convert inertial state vector to six
% classical orbital elements via
% equinoctial elements
% input
% r = inertial position vector (kilometers)
% v = inertial velocity vector (kilometers/second)
% output
% oev(1) = semimajor axis (kilometers)
% oev(2) = orbital eccentricity (nondimensional)
% (0 <= eccentricity < 1)
% oev(3) = orbital inclination (radians)
% (0 <= inclination <= pi)
% oev(4) = argument of periapsis (radians)
% (0 <= argument of periapsis <= 2 pi)
% oev(5) = right ascension of ascending node (radians)
% (0 <= raan <= 2 pi)
% oev(6) = true anomaly (radians)
% (0 <= true anomaly <= 2 pi)
mee2coe.m – convert modified equinoctial orbital elements to classical orbital elements
This MATLAB function can be used to convert modified equinoctial orbital elements to
classical orbital elements.
The syntax of this MATLAB function is
function coev = mee2coe(mee)
% convert modified equinoctial elements
% to classical orbit elements
% input
% mee(1) = semilatus rectum of orbit (kilometers)
% mee(2) = f equinoctial element
% mee(3) = g equinoctial element
% mee(4) = h equinoctial element
% mee(5) = k equinoctial element
% mee(6) = true longitude (radians)
% output
% coev(1) = semimajor axis (kilometers)
% coev(2) = eccentricity
Page 136
Celestial Computing with MATLAB
% coev(3) = inclination (radians)
% coev(4) = right ascension of ascending node (radians)
% coev(5) = argument of periapsis (radians)
% coev(6) = true anomaly (radians)
The relationship between modified equinoctial and classical orbital elements is given by
( )
( )
( )
( )
( )
2
1
cos
sin
tan 2 cos
tan 2 sin
p a e
f e
g e
h i
k i
L
e
e
e u
= ÷
= + O
= + O
= O
= O
= O+ +
where
semiparameter
semimajor axis
orbital eccentricity
orbital inclination
argument of perigee
right ascension of the ascending node
true anomaly
true longitude
p
a
e
i
L
e
u
=
=
=
=
=
O =
=
=
The relationship between classical and modified equinoctial orbital elements is as follows:
semimajor axis
2 2
1
p
a
f g
=
÷ ÷
orbital eccentricity
2 2
e f g = +
orbital inclination
( )
1 2 2
2tan i h
÷
= + k
argument of periapsis
( ) ( )
1 1
tan tan g f k h e
÷ ÷
= ÷
Page 137
Celestial Computing with MATLAB
right ascension of the ascending node
( )
1
tan k h
÷
O =
true anomaly
( ) ( )
1
tan L L g u e
÷
= ÷ O+ = ÷ f
mee2eci.m – convert modified equinoctial orbital elements to ECI state vector
This MATLAB function can be used to convert modified equinoctial orbital elements to ECI
position and velocity vectors.
The syntax of this MATLAB function is
function [r, v] = mee2eci(mee)
% convert modified equinoctial orbital
% elements to eci position and velocity vectors
% input
% mee(1) = semilatus rectum of orbit (kilometers)
% mee(2) = f equinoctial element
% mee(3) = g equinoctial element
% mee(4) = h equinoctial element
% mee(5) = k equinoctial element
% mee(6) = true longitude (radians)
% output
% r = eci position vector (kilometers)
% v = eci velocity vector (kilometers/second)
The relationship between ECI position and velocity vectors and modified equinoctial
elements is defined by the following series of equations:
position vector
( )
( )
( )
2
2
2
2
2
cos cos 2 sin
sin sin 2 cos
sin cos
r
L L hk
s
r
L L hk
s
r
h L k L
s
o
o
(
+ +
(
(
(
= ÷ +
(
(
( ÷
(
¸ ¸
r
L
L
velocity vector
Page 138
Celestial Computing with MATLAB
( )
( )
( )
2 2
2
2 2
2
2
1
sin sin 2 cos 2
1
cos cos 2 sin 2
2
cos sin
L L hk L g f hk g
s p
L L hk L g f ghk
s p
h L k L f h gk
s p
µ
o o
µ
o o
µ
(
÷ + ÷ + ÷ +
(
(
(
( = ÷ ÷ + + + ÷ + +
(
(
(
+ + +
(
¸ ¸
v f
where
2 2 2
2 2 2
1
1 cos sin
h k
s h k
p
r
w
w f L g
o = ÷
= + +
=
= + + L
eci2mee.m – convert ECI state vector to modified equinoctial elements
This MATLAB function can be used to convert an ECI state vector (position and velocity
vectors) to modified equinoctial orbital elements.
The syntax of this MATLAB function is
function mee = eci2mee(reci, veci)
% convert eci state vector to
% modified equinoctial elements
% input
% reci = eci position vector (kilometers)
% veci = eci velocity vector (kilometers/second)
% output
% mee(1) = semiparameter of orbit (kilometers)
% mee(2) = f equinoctial element
% mee(3) = g equinoctial element
% mee(4) = h equinoctial element
% mee(5) = k equinoctial element
% mee(6) = true longitude (radians)
Page 139
Celestial Computing with MATLAB
rotmat.m – fundamental rotation matrix
This MATLAB function computes the elementary rotation matrix for a userdefined rotation
angle about a userdefined rotation axis. All calculations follow the righthanded rule and
counterclockwise rotation angles are positive.
The three rotation matrices for the x, y and z axes are defined by
( )
1 0 0
0 cos sin
0 sin cos
x
R u u u
u u
(
(
=
(
÷ (
¸ ¸
( )
cos 0 sin
0 1 0
sin 0 cos
y
R
u u
u
u u
÷
(
(
=
(
(
¸ ¸
( )
cos sin 0
sin cos 0
0 0
z
R
u u
u u u
1
(
(
= ÷
(
(
¸ ¸
where u is the rotation angle.
Transformations between fundamental astronomical coordinate systems can also be
accomplished using various combinations of these matrices. For example, to transform a
position vector between the ecliptic and equatorial coordinate systems, the following matrix
vector relationships can be used:
( )
, ,
x
x x
y y
z z
ì  o
c
   
 
=
 
 
\ . \ .
R
o
( )
, ,
x
x x
y y
z z
o o ì
c
   
 
= ÷
 
 
\ . \ .
R

The matrixvector form of the transformation between the equatorial and local horizontal
coordinate systems are as follows:
Page 140
Celestial Computing with MATLAB
( ) ( )
, ,
180 90
z y
A a h
x x
y y
z z
o

   
 
= ÷ ÷
 
 
\ . \ .
R R
( ) ( )
, ,
90 180
y z
h A
x x
y y
z z
o

   
 
= ÷
 
 
\ . \ .
R R
a
The syntax of this MATLAB function is
function rmatrix = rotmat(iaxis, theta)
% rotation matrix
% input
% iaxis = 1 ==> xaxis
% = 2 ==> yaxis
% = 3 ==> zaxis
% theta = rotation angle (radians)
% output
% rmatrix = rotation matrix
Page 141
Celestial Computing with MATLAB
24. NOVAS Routines
The Celestial Computing with MATLAB software suite includes MATLAB versions of
several of the Fortran subroutines contained in the NOVAS (Naval Observatory Vector
Astrometry Subroutines) software package. This section documents the purpose and calling
arguments for these routines. Additional information about NOVAS can be found at the
Naval Observatory web site located at
http://aa.usno.navy.mil/AA/software/novas/novas_info.html
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
11971210, 1989.
aberat.m – correction for the aberration of light
function pos2 = aberat (pos1, ve, tlight)
% this function corrects position vector for aberration of light.
% algorithm includes relativistic terms. see murray (1981)
% mon. notices royal ast. society 195, 639648.
% input
% pos1 = position vector, referred to origin at center of
% mass of the earth, components in au
% ve = velocity vector of center of mass of the earth,
% referred to origin at solar system barycenter,
% components in au/day
% tlight = light time from body to earth in days
% if tlight = 0, this function will compute tlight
% output
% pos2 = position vector, referred to origin at center of
% mass of the earth, corrected for aberration,
% components in au
etilt1.m – orientation quantities based on DE405
function [oblm, oblt, eqeq, dpsi, deps] = etilt1 (tjd)
% this function computes quantities related to the orientation
% of the earth's rotation axis at julian date tjd
% nutation parameters obtained from jpleph
% input
% tjd = tdb julian date for orientation parameters
% output
% oblm = mean obliquity of the ecliptic at date tjd (degrees)
Page 142
Celestial Computing with MATLAB
% oblt = true obliquity of the ecliptic at date tjd (degrees)
% eqeq = equation of the equinoxes at date tjd (arc seconds)
% dpsi = nutation in longitude at date tjd (arc seconds)
% deps = nutation in obliquity at date tjd (arc seconds)
etilt2.m – orientation quantities based on IAU 1980 nutation
function [oblm, oblt, eqeq, dpsi, deps] = etilt2 (tjd)
% this function computes quantities related to the orientation
% of the earth's rotation axis at julian date tjd
% nutation parameters obtained from function nutation
% input
% tjd = tdb julian date for orientation parameters
% output
% oblm = mean obliquity of the ecliptic at date tjd (degrees)
% oblt = true obliquity of the ecliptic at date tjd (degrees)
% eqeq = equation of the equinoxes at date tjd (arc seconds)
% dpsi = nutation in longitude at date tjd (arc seconds)
% deps = nutation in obliquity at date tjd (arc seconds)
geocen.m – move coordinates origin to the Earth centerofmass
function [pos2, tlight] = geocen (pos1, pe)
% this function moves the origin of coordinates from the
% barycenter of the solar system to the center of mass of the
% earth, i.e., this function corrects for parallax.
% input
% pos1 = position vector, referred to origin at solar system
% barycenter (au)
% pe = position vector of center of mass of the earth,
% referred to origin at solar system barycenter (au)
% output
% pos2 = position vector, referred to origin at center of
% mass of the earth (au)
% tlight = light time from body to earth in days
nutate1.m – nutation transformation
function pos2 = nutate (tjd, pos1)
% this function nutates equatorial rectangular coordinates from
% mean equator and equinox of epoch to true equator and equinox of
% epoch. see pages 4145 of the explanatory supplement to the ae.
% source ephemeris is jpleph via etilt1
% input
% tjd = tdb julian date of epoch
Page 143
Celestial Computing with MATLAB
% pos1 = position vector, geocentric equatorial rectangular
% coordinates, referred to mean equator and equinox
% of epoch
% output
% pos2 = position vector, geocentric equatorial rectangular
% coordinates, referred to true equator and equinox
% of epoch (out)
% note:
% if tjd is negative, inverse nutation (true to mean) is applied
nutate2.m – nutation transformation
function pos2 = nutate2 (tjd, pos1)
% this function nutates equatorial rectangular coordinates from
% mean equator and equinox of epoch to true equator and equinox of
% epoch. see pages 4145 of the explanatory supplement to the ae.
% uses nutation function via etilt2
% input
% tjd = tdb julian date of epoch
% pos1 = position vector, geocentric equatorial rectangular
% coordinates, referred to mean equator and equinox
% of epoch
% output
% pos2 = position vector, geocentric equatorial rectangular
% coordinates, referred to true equator and equinox
% of epoch (out)
% note:
% if tjd is negative, inverse nutation (true to mean) is applied
pnsw.m – Earthfixed to spacefixed transformation
function vecs = pnsw (tjd, gast, x, y, vece)
% transforms a vector from earthfixed system to spacefixed system
% by applying rotations for wobble, spin, nutation, and precession.
% (combined rotation is symbolized p n s w.) specifically,
% it transforms a vector from earthfixed geographic system to
% spacefixed system based on mean equator and equinox of j2000.0.
% input
% tjd = tdt julian date
% gast = greenwich apparent sidereal time (hours)
% x = conventionallydefined x coordinate of rotational
% pole with respect to cio (arc seconds)
% y = conventionallydefined y coordinate of rotational
% pole with respect to cio (arc seconds)
% vece = vector in geocentric rectangular
% earthfixed system, referred to geographic
% equator and greenwich meridian
Page 144
Celestial Computing with MATLAB
% output
% vecs = vector in geocentric rectangular spacefixed system,
% referred to mean equator and equinox of j2000.0
% note
% tjd = 0 means no precession/nutation transformation
% gast = 0 means no spin transformation
% x = y = 0 means no wobble transformation
propmo.m – apply proper motion correction
function pos2 = propmo (tjd1, pos1, vel1, tjd2)
% this function applies proper motion, including
% foreshortening effects, to a star's position.
% input
% tjd1 = tdb julian date of first epoch
% pos1 = position vector at first epoch
% vel1 = velocity vector at first epoch
% tjd2 = tdb julian date of second epoch
% output
% pos2 = position vector at second epoch
solsys.m – interface to JPL ephemerides
function [pos, vel, ierr] = solsys (tjd, body, origin)
% purpose
% this is solsys version '2da'. it is intended to provide
% an interface between the jpl directaccess solar system
% ephemerides and the 'novas' astrometric function library
% references
% standish, e.m. and newhall, x x (1988). "the jpl
% export planetary ephemeris"; jpl document dated 17 june 1988.
% kaplan, g.h. (1988). "novas: naval observatory vector astrometry
% subroutines"; usno document dated 20 october 1988
% 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
% pos = position vector of 'body' at tjd;
% equatorial rectangular coordinates in
% au referred to the mean equator and
% equinox of j2000.0
Page 145
Celestial Computing with MATLAB
% vel = velocity vector of 'body' at tjd;
% equatorial rectangular system referred
% to the mean equator and equinox of
% j2000.0, in au/day
% ierr = 0 ... everything ok .
% = 1 ... invalid value of 'body'
% = 2 ... invalid value of 'origin'
% = 3 ... error detected by jpl software;
% tjd out of range
spin.m – rotating to nonrotating transformation
function pos2 = spin (st, pos1)
% this subroutine transforms geocentric rectangular coordinates
% from rotating system based on rotational equator and orthogonal
% reference meridian to nonrotating system based on true equator
% and equinox of date.
% input
% st = local apparent sidereal time at reference meridian (hours)
% pos1 = vector in geocentric rectangular rotating system, referred
% to rotational equator and orthogonal reference meridian
% output
% pos2 = vector in geocentric rectangular nonrotating system,
% referred to true equator and equinox of date
sunfld.m – correct for the deflection of light
function pos2 = sunfld (pos1, pe)
% this function corrects position vector for the deflection
% of light in the gravitational field of the sun. see murray (1981)
% mon. notices royal ast. society 195, 639648. this function valid
% for bodies within the solar system as well as for stars.
% input
% pos1 = position vector, referred to origin at center of mass
% of the earth, components in au
% pe = position vector of center of mass of the earth,
% referred to origin at center of mass of the sun,
% components in au
% output
% pos2 = position vector, referred to origin at center of mass
% of the earth, corrected for gravitational deflection,
% components in au
tdtimes.m – compute TDT julian date
function [tdtjd, secdif] = tdtimes (tdbjd)
% this function computes the terrestrial dynamical
% time (tdt) julian date corresponding to a barycentric
% dynamical time (tdb) julian date. expressions used in
Page 146
Celestial Computing with MATLAB
% this version are approximations resulting in accuracies
% of about 20 microseconds.
% input
% tdbjd = tdb julian date
% output
% tdtjd = tdt julian date
% secdif = difference tdbjdtdtjd, in seconds (out)
terra.m – position and velocity vectors of a terrestrial observer
function [pos, vel] = terra (glon, glat, ht, st)
% this functions computes the position and velocity vectors of
% a terrestrial observer with respect to the center of the earth.
% input
% glon = longitude of observer with respect to reference
% meridian (east +) in degrees
% glat = geodetic latitude (north +) of observer in degrees
% ht = height of observer in meters
% st = local apparent sidereal time at reference meridian
% in hours
% output
% pos = position vector of observer with respect to center
% of earth, equatorial rectangular coordinates,
% referred to true equator and equinox of date,
% components in au
% vel = velocity vector of observer with respect to center
% of earth, equatorial rectangular coordinates,
% referred to true equator and equinox of date,
% components in au/day
% note: if reference meridian is greenwich and st=0, pos
% is effectively referred to equator and greenwich
vectrs.m – convert angular quantities to vectors
function [pos, vel] = vectrs (ra, dec, pmra, pmdec, parllx, rv)
% this function converts angular quantities to vectors
% input
% ra = right ascension (hours)
% dec = declination (degrees)
% pmra = proper motion in ra (seconds of time per julian century)
% pmdec = proper motion in dec per julian century (seconds of arc)
% parllx = parallax (seconds of arc)
% rv = radial velocity (kilometers per second)
% output
% pos = position vector, equatorial rectangular coordinates (au)
Page 147
Celestial Computing with MATLAB
% vel = velocity vector, equatorial rectangular coordinates (au/day)
wobble.m – polar motion correction
function pos2 = wobble (x, y, pos1)
% this subroutine corrects earthfixed geocentric rectangular
% coordinates for polar motion. it transforms a vector from
% earthfixed geographic system to rotating system based on
% rotational equator and orthogonal greenwich meridian through
% axis of rotation.
% input
% x = conventionallydefined x coordinate of rotational
% pole with respect to cio (arc seconds)
% y = conventionallydefined y coordinate of rotational
% pole with respect to cio (arc seconds)
% pos1 = vector in geocentric rectangular earthfixed system,
% referred to geographic equator and greenwich meridian
% output
% pos2 = vector in geocentric rectangular rotating system,
% referred to rotational equator and orthogonal greenwich meridian
Page 148
Celestial Computing with MATLAB
25. Bibliography and References
Bonavito, N. L. and Der, G. J., Orbital and Celestial Mechanics, AIAA Progress in
Astronautics and Aeronautics, Volume 177, 1998.
Bretagnon, P., and Simon, J., Planetary Programs and Tables from –4000 to +2800,
WillmannBell, 1986.
Brouwer, D., and Clemence, G., Methods of Celestial Mechanics, Academic Press, 1961.
Brumberg, V. A., Analytical Techniques of Celestial Mechanics, SpringerVerlag, 1995.
Chapront, J., and ChaprontTouze, M., Lunar Tables and Programs from 4000 B.C. to A.D.
8000, WillmannBell, 1991.
Chebotarev, G. A., Analytical and Numerical Methods of Celestial Mechanics, American
Elsevier Publishing Company, 1967.
Danby, J. M. A., Fundamentals of Celestial Mechanics, WillmannBell, 1988.
Dormand, J. R., Numerical Methods for Differential Equations, CRC Press, 1996.
Dubyago, A. D., The Determination of Orbits, The Macmillian Company, 1961.
Escobal, P. R., Methods of Orbit Determination, Robert E. Krieger Publishing, 1976.
Escobal, P. R., Methods of Astrodynamics, Robert E. Krieger Publishing, 1979.
Forsythe, G. E., Malcolm, M. A., and Moler, C. B., Computer Methods for Mathematical
Computations, PrenticeHall, 1977.
Heafner, P. J., Fundamental Ephemeris Computations, WillmannBell, 1999.
Meeus, J., Astronomical Algorithms, WillmannBell, 1991.
Meeus, J., Tables of the Sun, Moon and Planets, WillmannBell, 1995.
Meeus, J., Transits, WillmannBell, 1989.
Meeus, J., Mathematical Astronomy Morsels, WillmannBell, 1997.
Montenbruck, O., and Pfleger, T., Astronomy on the Personal Computer, SpringerVerlag,
1994.
Moulton, F. R., An Introduction to Celestial Mechanics, Dover, 1970.
Page 149
Celestial Computing with MATLAB
Page 150
Seidelmann, P. K. (Editor), Explanatory Supplement to the Astronomical Alamanac,
University Science Books, 1992.
Szebehely, V. G., Adventures in Celestial Mechanics, University of Texas Press, 1989.
Celestial Computing with MATLAB
INTRODUCTION ....................................................................................................... 7 1. RISE AND SET OF THE SUN, MOON AND PLANETS........................................ 9 2. LUNAR ECLIPSES.............................................................................................. 17 3. LUNAR OCCULTATIONS ................................................................................... 20 4. SOLAR ECLIPSES.............................................................................................. 23 5. TRANSITS OF MERCURY AND VENUS ............................................................ 25 6. CLOSEST APPROACH BETWEEN THE EARTH AND HELIOCENTRIC OBJECTS................................................................................................................ 28 7. EQUINOXES AND SOLSTICES.......................................................................... 31 8. COWELL’S METHOD FOR HELIOCENTRIC ORBITS....................................... 32
cowell1.m – rectangular position and velocity vector formulation ................................................................32 cowell2.m – modified equinoctial orbital elements formulation.....................................................................34
9. ENCKE’S METHOD FOR HELIOCENTRIC ORBITS.......................................... 39 10. THE CIRCULARRESTRICTED THREEBODY PROBLEM............................. 43
crtbp1.m – coordinates and energy of the libration points .............................................................................44 g3body.m – graphics display of threebody motion.........................................................................................46 zvcurve1.m – graphics display of zero velocity curves through equilibrium points .....................................49 zvcurve2.m – graphics display of userdefined zero relative velocity curves ................................................51
11. APPARENT COORDINATES OF A PLANET OR THE MOON ........................ 55 12. APPARENT COORDINATES OF A STAR........................................................ 59 13. JPL DE405 LUNAR, SOLAR AND PLANETARY EPHEMERIS....................... 62 14. SLP96 LUNAR, SOLAR AND PLANETARY EPHEMERIS .............................. 65
Page 1
Celestial Computing with MATLAB 15. OTHER LUNAR, SOLAR AND PLANETARY EPHEMERIS ALGORITHMS.... 69
sun.m – solar ephemeris.....................................................................................................................................69 moon.m – lunar ephemeris ................................................................................................................................70 mercury.m – Mercury ephemeris......................................................................................................................70 venus.m – Venus ephemeris...............................................................................................................................71 earth.m – Earth ephemeris ................................................................................................................................71 mars.m – Mars ephemeris .................................................................................................................................71 jupiter.m – Jupiter ephemeris ...........................................................................................................................72 saturn.m – Saturn ephemeris ............................................................................................................................72 uranus.m – Uranus ephemeris...........................................................................................................................72 neptune.m – Neptune ephemeris .......................................................................................................................73 pluto.m – Pluto ephemeris .................................................................................................................................73 sun1.m – precision Sun ephemeris ....................................................................................................................74 elp2000.m – osculating orbital elements of the moon ......................................................................................76 planet1.m – mean ecliptic and equinox of data planetary ephemeredes........................................................78 planet2.m – mean ecliptic and equinox of J2000 planetary ephemerides......................................................79 seleno.m – selenographic coordinate transformation ......................................................................................80
16. APPARENT GREENWICH SIDEREAL TIME ................................................... 81
gast.m – low precision ........................................................................................................................................81 gast1.m – full precision.......................................................................................................................................82 gast2.m – DE405 nutations ................................................................................................................................83
17. IAU 1980 NUTATION IN LONGITUDE AND OBLIQUITY ................................ 85 18. PRECESSION TRANSFORMATION ................................................................ 87 19. KEPLER’S EQUATION ..................................................................................... 89
kepler1.m – Danby’s method.............................................................................................................................89 kepler2.m – Danby’s method with Mikkola’s initial guess .............................................................................91
Page 2
..........................Celestial Computing with MATLAB kepler3.................. 104 TRIGONOMETRY AND VECTOR ROUTINES................m – Sheppard’s method......96 twobody2...............................98 twobody3.......................................................m – Gooding’s two iteration method..................................................................................m – RungeKuttaFehlberg 7(8) method for firstorder systems ....................................................................................107 ceqm1.................................m – solve for a single root of a nonlinear function ..................m – four quadrant inverse tangent ................................................... NUMERICAL METHODS AND UTILITY ROUTINES... 101 julian...............................................................m – convert hours function ...............................................................................................................104 uvector..m – Stumpff/Danby method .....105 rkf78...........104 DIFFERENTIAL EQUATIONS ....108 meeeqm...............................................................105 rkf45................. 96 twobody1........................................................................................................................................................................................................m – convert UTC Julian date to TDT Julian date ........................m – Goodyear’s method.....................................m – julian date to calendar date and universal time strings................................110 broot.m – julian date to calendar date....101 jd2str...................................................................................................................m – unit vector ...................................................................................................................101 utc2tdt..........................................................................................................m – modulo 2 pi..............92 kepler4...........m – calendar date to Julian date .....................................................m – firstorder heliocentric equations of orbital motion..................................................................102 tdt2tdb......... TIME AND DATE FUNCTIONS ...................................................................................................................m – RungeKuttaFehlberg 4(5) method for firstorder systems ............................................................110 brent....98 21..............................................................................m – modified equinoctial equations of motion ...............................................................................103 22.....................m – Nystrom fourthorder method for secondorder systems.............................................................................................................................................................m – bracket a single root of a nonlinear function...........................................104 atan3..........................................................104 modulo.93 20............ TWOBODY ORBITAL MOTION...105 nym4......................109 ROOTFINDING AND OPTIMIZATION ...................................................................................................................m – parabolic and nearparabolic orbits ........111 Page 3 .....................................................................102 hrs2hms................................................101 gdate.................................m – convert TDT Julian date to TDB Julian date..........
m – equatorial to local horizontal coordinate conversion ...m – refraction correction function ...........m – plot orthographic view of the Earth......................................113 refract...................................................114 UTILITY ROUTINES .........m – find minimization/root finding orbital event ......................................................117 gettime................m – transform angular orbital elements from one equinox to another ....... 121 rec2pol.................................115 INTERACTIVE REQUEST OF PROGRAM INPUTS...................................118 demomwdb..............112 oevent1................114 oeprint1..........................................................124 Page 4 .................. ASTRONOMICAL COORDINATES .............m – local horizontal to equatorial coordinate conversion ...m – request universal time ..................................117 RECTANGULAR AND ORTHOGRAPHIC GRAPHICS......................................................................120 23.................................................................................................................121 pol2rec...............113 refract1........................................................................................................................Celestial Computing with MATLAB minima...........................................................................m – convert degrees function...................................................................................................................................................................m – refraction correction function including temperature/pressure effects .......114 svprint..................................................................................................m – NOVAS refraction correction function..........115 getdate......m – rectangular to polar coordinate conversion ...................................m – ecliptic to equatorial coordinate conversion........................................................m – equatorial to ecliptic coordinate conversion.......................m – MicroWorld Database map files ...............................m – request calendar date.....................................................................................................................................................................................................................................................................................................m – formatted classical orbital elements screen display .........................................................................................m – onedimensional minimization ...................................................................................m – polar to rectangular coordinate conversion ...............118 pltrect...................m – request observer coordinates..........................................113 refract2............................115 deg2dms..................................115 getobs...........................118 pltortho.................................116 getoe.......................................................122 ecl2equ................123 equ2hor....122 equ2ecl..................m – request classical orbital elements .................124 oepreces......................................................................................................................................123 hor2equ..................m – plot rectangular map of the Earth.........m – formatted state vector screen display ................................................................................112 ATMOSPHERIC REFRACTION ............................................................................
..............................................m – convert geodetic coordinates to geocentric coordinates ........................................................................................m – nutation transformation..................................................................m – convert geodetic coordinates to ECF position vector ..144 propmo.........m – convert geocentric coordinates to geodetic coordinates .............................................m – orientation quantities based on IAU 1980 nutation .................................m – move coordinates origin to the Earth centerofmass.....138 eci2mee....................................................127 geodet2......................................130 triaxial.....................m – convert classical orbital elements to inertial state vector ............................................ NOVAS ROUTINES.........m – position and velocity vectors of a terrestrial observer.........m – interface to JPL ephemerides ..................m – geodetic altitude to a triaxial ellipsoid........................143 geocen.....................................m – correction for the aberration of light..........................................................142 etilt2.........................................................m – nutation transformation.m – convert modified equinoctial orbital elements to classical orbital elements ..................126 geodet1.........................................133 mee2coe........................................................................................................................................................m – convert geocentric coordinates to geodetic coordinates – exact solution.....146 terra............................................146 sunfld................................................................................................m – compute TDT julian date ................................144 pnsw..143 nutate2..145 solsys.........................................147 Page 5 ....................................................m – ground site position vector................................................128 geodet3..........m – rotating to nonrotating transformation .....Celestial Computing with MATLAB gsite........................................................................................... 142 aberat.145 spin................139 rotmat........m – convert modified equinoctial orbital elements to ECI state vector..................m – fundamental rotation matrix ......................................................................................................................................................................................136 mee2eci...................132 eci2orb........m – convert ECI state vector to modified equinoctial elements ................................m – convert inertial state vector to six classical orbital elements ..................140 24..................................................m – orientation quantities based on DE405 .129 geodet4.........m – convert angular quantities to vectors .......................................................................................................................131 orb2eci..........................................................142 etilt1.m – Earthfixed to spacefixed transformation ..........147 vectrs....................................143 nutate1.............................................................................146 tdtimes.............................series solution...................................................m – apply proper motion correction................................................m – correct for the deflection of light .............
...................................... 149 Page 6 ............................Celestial Computing with MATLAB wobble............... BIBLIOGRAPHY AND REFERENCES ...m – polar motion correction .................................................................148 25........................
The following is a summary of these routines: Date and time routines Lunar. Inc. This suite of applications and functions can be used to solve practical problems in the following areas of computational celestial mechanics: Rise and Set of the Sun. Moon and Planets Lunar and Solar Eclipses Lunar Occultations Transits of Mercury and Venus Equinoxes and Solstices The CircularRestricted ThreeBody Problem Cowell’s and Encke’s Method for Heliocentric Objects Apparent Coordinates of the Sun. Windows is a registered trademark of Microsoft Corporation Page 7 . solar and planetary ephemerides Astronomical Coordinates and Transformations Rootfinding and optimization Differential equations of heliocentric orbital motion The Celestial Computing with MATLAB software suite also includes binary data files for the SLP96 and DE403 ephemeris. basic celestial mechanics functions and data files that can be used to create your own applications. MATLAB is a registered trademark of The Mathworks. scripts and data files that can be used to solve a variety of problems in fundamental and advanced celestial mechanics. Moon. Requirements Celestial Computing with MATLAB requires MATLAB version 5.Celestial Computing with MATLAB Introduction Celestial Computing with MATLAB is a comprehensive collection of MATLAB functions. Please note that the binary ephemeris and map files provided with this software package are only compatible with the Windows version of MATLAB. Planets and Stars Kepler’s Equation Twobody Orbital Motion This MATLAB toolbox also contains many numerical methods.3 or higher.
Celestial Computing with MATLAB Page 8 .
25 days and for planetary events dt can be between 0.Celestial Computing with MATLAB 1. Be careful not to make dt too large or the algorithm may “step over” one or more solutions. The source ephemeris for this routine is the JPL DE405. 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”.1 and 0. For lunar events dt can be between 0. tf. The basic procedure for predicting rise and set of a celestial body involves the following computational steps and MATLAB functions: (1) locate an extrema using the functions oevent1 and minima (2) bracket a “forward” and “backward” root using the function broot (3) find each root using the function brent (4) calculate the event circumstances using the function events1 (5) display the event circumstances using the function rsfunc The main MATLAB function that solves this problem has the following syntax and arguments: function oevent1 (objfunc. dtsml) % predict minimization/rootfinding events % input % % % % % % % objfunc prtfunc ti tf dt dtsml = = = = = = objective function display results function initial simulation time final simulation time step size used for bounding minima small step size used to determine whether the function is increasing or decreasing The name of the userdefined objective function (objfunc) and a function that prints the important results (prtfunc) is passed to this routine in the argument list. ti. This is similar to choosing the value of x when numerically estimating the derivative of a function of the Page 9 . the value of dt is used to bound one or more extremas and depends on how long the event lasts.m) determines rise and set conditions of the Sun.1 and 0.5 days. dt. For shorter events dt should be smaller and for longer events dt can be larger. Choosing the Search Parameters 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. Moon and planets. prtfunc. Moon and Planets This MATLAB script (riseset. Rise and Set of the Sun. This software uses a combination of onedimensional minimization and rootfinding to predict visibility.
b. x is the current function argument and fx is the objective function evaluated at x. The syntax of this optimization function is as follows: function [xmin. a.Celestial Computing with MATLAB form y f x . tolm) % onedimensional minimization % Brent's method % input % % % % f a b tolm = = = = objective function coded as y = f(x) initial x search value final x search value convergence criterion % output % % xmin = minimum x value fmin = minimum function value This function in turn requires an objective function coded as fx = objfunc(x) where objfunc is the name of the userdefined objective function. 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. For this script the objective function is equal to the topocentric elevation angle of the body. fmin] = minima (f.01 and 0. During the search process the oevent1 function calls a MATLAB function called minima that calculates the extremum of a onedimensional userdefined objective function.1 days should be adequate. For lunar events this number should be a number between 0. For planetary events a value of dtsml = 0. A numerical value of 1e4 for the convergence criterion should be adequate for most userdefined objective functions.05 days. The source code of the objective function for this example is as follows: function fx = rsfunc(x) % topocentric elevation angle % objective function % input % x = elpased simulation time (days) % output % fx = objective function at x % Celestial Computing with MATLAB %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% global jdatei itarg icent rootflg global obslat glon glat ht stlocl Page 10 .
else % no semidiameter correction for planets tsdia = 0.5 * 696000 / aunit) / dis). end else dref = 0. % topocentric elevation (degrees) elevation = rtd * asin(sin(obslat) * sin(dtr * dec) . For this script the input argument is the elapsed time in days since the simulation Page 11 .(2 * pi * ra / 24). dec. end % evaluate objective function fx = (elevation + tsdia + dref). % topocentric azimuth (degrees) tmp1 = sin(hangle). jdutc = jdatei + x. 360). 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. azimuth = mod(180 + rtd * atan3(tmp1. jdutc. + cos(obslat) * cos(dtr * dec) * cos(hangle)). [ra. elseif (itarg == 10) % correct for semidiameter of the sun tsdia = rtd * asin((0. icent. dtr = pi / 180. 1. glon. % apparent hour angle hangle = stlocl .Celestial Computing with MATLAB global aunit elevation azimuth rtd = 180 / pi. itarg. glat. tmp2 = cos(hangle) * sin(obslat) .tan(dtr * dec) * cos(obslat). if (itarg == 11) % correct for semidiameter of the moon tsdia = rtd * asin((1738 / aunit) / dis). This function calculates the topocentric elevation angle of the celestial object for any input argument x. tsdia = 0. if (rootflg == 1) % correct for horizontal refraction dref = (34 / 60). tmp2). jdtdt = utc2tdt(jdutc).. dis] = applan1(jdtdt.. ht).
prtfunc. This condition guarantees that there is at least one root in the interval because the objective function changes sign. 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.Celestial Computing with MATLAB began. After each root is calculated this routine then calls a MATLAB function called rsfunc that actually displays the event conditions. The name of the userdefined objective function f is passed to this routine in the argument list.05 days after (forward root) or 0. topt) % compute and display celestial events % input % % % % % objfunc prtfunc ti tf topt = = = = = objective function display results function initial simulation time final simulation time extrema time 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. For the riseset script the userdefined (and coded) objective function is called rsfunc. The syntax of this MATLAB function is as follows: function [x1out. dxmax) % bracket a single root of a nonlinear equation % input % f = objective function coded as y = f(x) Page 12 . Typically x1 is the time of an objective function minimum or maximum and x2 is a time 0. x1in.05 days before (backward root) the value of x1 . The user must supply this function with an initial guess for x1 and x2 . x2out] = broot (f. Notice the corrections for the semidiameter of the Moon and the horizontal refraction during the rootfinding calculations. factor. The sign of this delta tells the algorithm in which direction to move. x2in. tf. The syntax of the MATLAB function that calculates and displays the actual roots of the userdefined objective function is as follows: function events1 (objfunc. The basic idea is to find the endpoints of a time interval x1 and x2 such that f x1 f x2 0 . ti. The following is a brief description of the function that brackets each root.
PrenticeHall. the user should ensure that a root is bracketed. P. x1. x2. However. this algorithm does not require derivatives of the objective function. The syntax of this MATLAB function is as follows: function [xroot. the process will bracket the root and the function will return the endpoints of this bracketing interval.Celestial Computing with MATLAB % % % % x1in x2in factor dxmax = = = = initial guess for first bracketing x value initial guess for second bracketing x value acceleration factor (nondimensional) rectification interval % output % % x1out = final value for first bracketing x value x2out = final value for second bracketing x value The acceleration factor used in this script is 0. Brent. As the title of this book indicates. The acceleration factor increases the size of each step geometrically and the rectification interval monitors the length of the current bracketing interval. The size of each step increases geometrically until the length of the current step reaches the value of the rectification 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.25 and the rectification interval is 0. This feature is important because the analytic first derivative of many objective functions is difficult to derive and code. Additional information about this numerical method can be found in Algorithms for Minimization Without Derivatives. Eventually. froot] = brent (f. At that point the step size is reset and the process begins again. rtol) % solve for a single real root of a nonlinear equation % Brent's method % input % % % % f x1 x2 rtol = = = = objective function coded as y = f(x) lower bound of search interval upper bound of search interval algorithm convergence criterion % output % % xroot froot = real root of f(x) = 0 = function value at f(x) = 0 Page 13 . f x1 f x2 0 . before calling this routine.1 days. The following is a brief description of the MATLAB function that solves for each root. Derivatives are not required for this algorithm. function brent This function uses Brent’s method to find a single root of a single nonlinear equation of the form y f x . 1972. R.
Also note that east longitudes are positive and west longitudes are negative.0 please input the geographic longitude of the ground site (0 <= degrees <= 360. 0 <= seconds <= 60) (north latitude is positive.Celestial Computing with MATLAB The rootfinding performance of this algorithm is determined by rtol. moon or planets please input an initial UTC calendar date please input the calendar date (1 <= month <= 12.1. rise and set of the sun. and the search interval in days. The riseset MATLAB script will prompt you for an initial calendar date. The initial calendar date was January 1. 0 <= minutes <= 60. south latitude is negative) ? 40. and the observer was located at 40 north latitude and 105 west longitude. A value of 1. year = all digits!) ? 1.0 please input the altitude of the ground site (meters) Page 14 . on the UTC time scale. 1 <= day <= 31. The altitude of the site is 0 meters. The following is a typical user interaction with this script. The calendar date and time displayed is on the UTC time scale.0. 0 <= seconds <= 60) (east longitude is positive.1998 please input the search duration (days) ? 5 target body menu <1> Mercury <2> Venus <3> Earth <4> Mars <5> Jupiter <6> Saturn <7> Uranus <8> Neptune <9> Pluto <10> Sun <11> Moon please select the target body ? 11 please input the geographic latitude of the ground site (90 <= degrees <= +90. It will also ask you for the geographic coordinates of the observer. observer sites above sea level have positive altitudes and sites below sea level are negative. west longitude is negative) ? 105.0. 0 <= minutes <= 60. Please note that north latitudes are positive and south latitudes are negative. Smaller values will predict roots more accurately at the expense of longer program execution times. It illustrates two rise and sets of the Moon. Furthermore.0e8 should be adequate for most problems. 1998.
41s < please press any key to continue > set conditions calendar date universal time UTC Julian date azimuth angle elevation angle event duration 02Jan1998 03:25:20 2450815.4137 +180d 44m 55.6827s < please press any key to continue > rise conditions Page 15 .04s +00d 50m 09.37s +10h 58m 17.84s +00d 50m 08.1854 +107d 16m 34.Celestial Computing with MATLAB (positive above sea level.02s < please press any key to continue > maximum elevation conditions calendar date universal time UTC Julian date azimuth angle elevation angle 01Jan1998 21:55:47 2450815.6426 +254d 49m 56.48s +36d 55m 51.0000 meters rise conditions calendar date universal time UTC Julian date azimuth angle elevation angle 01Jan1998 16:27:02 2450815.00s 105d 00m 00.00s 0. negative below sea level) ? 0 rise and set conditions 'Moon' observer latitude observer east longitude observer altitude +40d 00m 00.
Page 16 .02s < please press any key to continue > set conditions calendar date universal time UTC Julian date azimuth angle elevation angle event duration 03Jan1998 04:33:46 2450816.07s +00d 50m 10.Celestial Computing with MATLAB calendar date universal time UTC Julian date azimuth angle elevation angle 02Jan1998 17:07:18 2450816.6901 +260d 17m 02.4513 +180d 53m 01.77s +11h 26m 27.40s < please press any key to continue > maximum elevation conditions calendar date universal time UTC Julian date azimuth angle elevation angle 02Jan1998 22:49:50 2450816.22s +00d 50m 10.6213s This same technique can be used to predict rise and set of stars and other stellar objects.2134 +102d 17m 18. For this case simply call the apstar1 or apstar2 MATLAB functions from within the rsfunc objective function.40s +40d 55m 36.
a penumbral lunar eclipse occurs whenever the following geometric condition is satisfied: 1. Lunar Eclipses This MATLAB script (eclipse. the code can be easily modified to use DE405 as the source ephemeris.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.m) can be used to predict lunar eclipses. This script uses a combination of onedimensional minimization and rootfinding to solve this classic problem. and the time and coordinates at maximum eclipse. the universal times and topocentric coordinates of the Moon at the beginning and end of the penumbra contacts.Celestial Computing with MATLAB 2. The source ephemeris for this script is SLP96. This function is given by the following expression: ˆ ˆ f t cos 1 U m U s f1 sm where ˆ U s geocentric unit position vector of the Sun ˆ U m geocentric unit position vector of the Moon f1 1. The objective function used in these calculations involves the geocentric separation angle between the center of the Moon and the antiSun position vector or shadow axis.02 1 s ss sm In these expressions Page 17 . However.02 1 s ss size of penumbra shadow 1 0.02 1 s ss sm The geometric condition for a total lunar eclipse is given by 1. and the semidiameter and horizontal parallax of the Sun and Moon. This software provides the eclipse type.02 1 s ss sm A partial lunar eclipse will happen whenever the following is true: 1.
0 <= minutes <= 60. 1993. 0 <= seconds <= 60) (east longitude is positive. year = all digits!) ? 11.6438 +99d 45m 53.0 please input the geographic longitude of the ground site (0 <= degrees <= 360.Celestial Computing with MATLAB m sin 1 req dm s sin 1 req ds r sm sin 1 m dm r ss sin 1 s ds where req is the equatorial radius of the Earth (6378. total lunar eclipse begin penumbral phase of lunar eclipse calendar date universal time UTC Julian date lunar azimuth angle lunar elevation angle 29Nov1993 03:27:08 2449320.1993 please input the search duration (days) ? 30 please input the geographic latitude of the ground site (90 <= degrees <= +90.0 please input the altitude of the ground site (meters) (positive above sea level.0. Colorado. The following is a typical user interaction with this script... The topocentric coordinates are for an observer located in Denver. 0 <= seconds <= 60) (north latitude is positive.0. negative below sea level) ? 0 working .. lunar eclipses please input the calendar date (1 <= month <= 12.14 kilometers). d m is the geocentric distance of the Moon and d s is the geocentric distance of the Sun.. rm is the radius of the Moon (1738 kilometers). 1 <= day <= 31. 0 <= minutes <= 60.1. It illustrates the circumstances of the total lunar eclipse of November 28.83s +43d 53m 09. west longitude is negative) ? 105. south latitude is negative) ? 40. rs is the radius of the Sun (696. Page 18 .000 kilometers).29s < please press any key to continue > working .
61s +52d 24m 42.8379s Page 19 ..53s +05h 57m 51.8924 lunar azimuth angle lunar elevation angle event duration +250d 53m 05.7682 +164d 18m 16. end penumbral phase of lunar eclipse calendar date universal time UTC Julian date 29Nov1993 09:25:00 2449320.73s +70d 13m 39..Celestial Computing with MATLAB greatest eclipse conditions calendar date universal time UTC Julian date lunar azimuth angle lunar elevation angle 29Nov1993 06:26:13 2449320.01s < please press any key to continue > working .
the code can be easily modified to use DE405 as the source ephemeris. This script uses a combination of onedimensional minimization and rootfinding to solve this problem. Colorado. This function is given by the following expression: ˆ ˆ f t cos 1 U m U b sm sb where ˆ U m topocentric unit position vector of the Moon ˆ U b topocentric unit position vector of the object sm semidiameter of the Moon sb semidiameter of the object The semidiameter of the Moon is given by 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. However.1. The following is a typical user interaction with this script. The semidiameter of a star is zero and the semidiameter of a planet is sp s p0 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. year = all digits!) ? 2. The objective function used in these calculations is the topocentric separation angle between the center of the Moon and the object being occulted. Lunar Occultations This MATLAB script (occult. The source ephemeris for this script is SLP96.1987 please input the search duration (days) ? 30 Page 20 . lunar occultations please input the calendar date (1 <= month <= 12.Celestial Computing with MATLAB 3. It illustrates a lunar occultation of the star Spica relative to an observer located in Denver. 1 <= day <= 31.m) can be used to predict the local circumstances of lunar occultations of a planet or star.
0540 lunar azimuth angle +226d 06m 05. begin lunar occultation calendar date universal time UTC Julian date 18Feb1987 12:27:04 2446845.48 please input the altitude of the ground site (meters) (positive above sea level. end lunar occultation calendar date universal time UTC Julian date 18Feb1987 13:17:46 2446845.0 please input the geographic longitude of the ground site (0 <= degrees <= 360.58.91s +32d 52m 22.. 0 <= minutes <= 60. south latitude is negative) ? 39.10s < please press any key to continue > working .Celestial Computing with MATLAB target body menu <1> <2> <3> <4> <5> <6> <7> <8> <9> Mercury Venus Mars Jupiter Saturn Uranus Neptune Pluto Star please select the target body ? 9 please input the star data file name (be sure to include the file name extension) ? spica.dat please input the geographic latitude of the ground site (90 <= degrees <= +90. 0 <= seconds <= 60) (north latitude is positive.. 0 <= seconds <= 60) (east longitude is positive.. 0 <= minutes <= 60.. negative below sea level) ? 0 working .0188 lunar azimuth angle lunar elevation angle +214d 02m 41.45.32s Page 21 . west longitude is negative) ? 104.
0 Page 22 .6772s < please press any key to continue > The following is the star data file used in this example. star name SPICA J2000 right ascension (hours) 13.1613083330 J2000 proper motion in right ascension (seconds/Julian century) 0.0210 radial velocity (kilometers/second) 1.8300 parallax (arcseconds) 0.4198852780 J2000 declination (degrees) 11.Celestial Computing with MATLAB lunar elevation angle event duration +26d 31m 56.13s +00h 50m 41.2780 J2000 proper motion in declination (arcseconds/Julian century) 2.
1994 please input the search duration (days) Page 23 .Celestial Computing with MATLAB 4. The source ephemeris for this script is SLP96.m) can be used to predict local circumstances of solar eclipses. The following is a typical user interaction with this script. This script uses a combination of onedimensional minimization and rootfinding to solve this problem. and the time and coordinates at maximum eclipse. The selenocentric position vector of the Sun is computed from the expression R ms 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.1. year = all digits!) ? 5. solar eclipses please input the calendar date (1 <= month <= 12. rs is the radius of the Sun. This function is given by the following expression: ˆ ˆ f t cos 1 U axis U m o p where ˆ U axis selenocentric unit vector of the Moon's shadow ˆ U m o selenocentric unit position vector of the observer p penumbra shadow angle The penumbra shadow angle at the distance of the Earth observer is determined from p sin 1 rm 1 rs rm sin dm d ms In this expression rm is the radius of the Moon. 1 <= day <= 31. the code can be easily modified to use DE405 as the source ephemeris. The objective function used in these calculations is the selenocentric separation angle between the axis of the shadow cast by the Moon and an Earth observer. Solar Eclipses This MATLAB script (seclipse. However. This software provides the universal times and topocentric coordinates of the Moon at the beginning and end of the penumbra contacts. This example is taken from page 209 of Astronomy with the Personal Computer. d m is the topocentric distance of the Moon and d m s is the distance from the Moon to the Sun.
.97s +15d 58m 45. 0 <= minutes <= 60.28s < please press any key to continue > working . end penumbral phase of solar eclipse calendar date universal time UTC Julian date lunar azimuth angle lunar elevation angle event duration 10May1994 19:59:20 2449483. south latitude is negative) ? 33..07s 08d 14m 55. 0 <= seconds <= 60) (north latitude is positive. west longitude is negative) ? 6.2904 +289d 25m 24.Celestial Computing with MATLAB ? 30 please input the geographic latitude of the ground site (90 <= degrees <= +90..2436 +280d 49m 06.57.50. negative below sea level) ? 0 working ..3329 +297d 56m 19.0 please input the altitude of the ground site (meters) (positive above sea level.94s +02d 55m 27.2403s Page 24 .69s +02h 08m 34.0 please input the geographic longitude of the ground site (0 <= degrees <= 360. begin penumbral phase of solar eclipse calendar date universal time UTC Julian date lunar azimuth angle lunar elevation angle 10May1994 17:50:46 2449483. 0 <= seconds <= 60) (east longitude is positive.. 0 <= minutes <= 60..39s < please press any key to continue > working . greatest eclipse conditions calendar date universal time UTC Julian date lunar azimuth angle lunar elevation angle 10May1994 18:58:15 2449483.
The semidiameter of the Sun is given by r ss sin 1 s ds where rs is the radius of the Sun (696. The objective function used in these calculations is the topocentric separation angle between the center of the Sun and the planet in transit. The following is a typical user interaction with this script. the code can be easily modified to use DE405 as the source ephemeris.000 kilometers) and d s is the topocentric distance of the Sun.41 arc seconds for Venus.Celestial Computing with MATLAB 5. This function is given by the following expression: ˆ ˆ f t cos 1 U s U p ss s p where ˆ U s topocentric unit position vector of the Sun ˆ U p topocentric unit position vector of the planet ss semidiameter of the Sun s p semidiameter of the planet During the search for minimum separation angles.36 arc seconds for Mercury and 8. The software will also display the topocentric coordinates of the Sun at the time of ingress. Page 25 . This example is Example 6 from the book Transits by Jean Meeus. The ingress and egress conditions correspond to exterior contact. This script uses a value of 3.m) can be used to predict the local circumstances of transits of Mercury and Venus. This script uses a combination of onedimensional minimization and rootfinding to solve this problem. Transits of Mercury and Venus This MATLAB script (transit. least separation distance and egress. the software also checks to see if the planet is between the observer and the Sun. However. The semidiameter of Mercury and Venus is determined from the expression sp s p0 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 source ephemeris for this script is SLP96.
exterior contact .17 please input the geographic longitude of the ground site (0 <= degrees <= 360.4193 azimuth angle of the sun elevation angle of the sun +279d 05m 05. negative below sea level) ? 84 working . year = all digits!) ? 6. 0 <= seconds <= 60) (east longitude is positive.81s < please press any key to continue > working . west longitude is negative) ? 77. 0 <= minutes <= 60. ingress . 1 <= day <= 31.56 please input the altitude of the ground site (meters) (positive above sea level.5599 +309d 48m 31.55.41s 09d 40m 16.84s Page 26 .Venus calendar date universal time UTC Julian date 05Jun2012 22:03:45 2456084. least distance of the Sun and Venus calendar date universal time UTC Julian date azimuth angle of the sun elevation angle of the sun 06Jun2012 01:26:18 2456084.2012 please input the search duration (days) ? 30 target body menu <1> Mercury <2> Venus please select the target body ? 2 please input the geographic latitude of the ground site (90 <= degrees <= +90.3. 0 <= seconds <= 60) (north latitude is positive.Celestial Computing with MATLAB transits of Mercury and Venus please input the calendar date (1 <= month <= 12.. 0 <= minutes <= 60...27s +25d 56m 12.1. south latitude is negative) ? 38..
34s +06h 47m 15.7021 +355d 50m 23..Celestial Computing with MATLAB < please press any key to continue > working .Venus calendar date universal time UTC Julian date azimuth angle of the sun elevation angle of the sun event duration 06Jun2012 04:51:00 2456084.. egress .84s 28d 16m 44.4074s Page 27 .exterior contact .
jpl. 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.P. Additional information about this numerical method can be found in Algorithms for Minimization Without Derivatives. Closest Approach Between the Earth and Heliocentric Objects This MATLAB script (cae2ho. this algorithm does not require derivatives of the Page 28 . Additional information about the SLP96 ephemeris can be found on the Internet at ftp://ftp. As the title of this book indicates. 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. The software expects to find one or both of these binary files in the same directory as cae2ho. comets and other bodies in heliocentric elliptic orbits. Saturn and the Sun. Mars. Venus. 1972. Jupiter.nasa.gov. PrenticeHall. Information about the DE405 ephemeris is available at ftp://navigator. It includes the point mass gravity perturbations due to the planets Mercury. It also includes the pointmass effect of the Moon via a combined Earth/Moon gravitational constant.fr/pub/ephem/sun/slp96.bdl.Celestial Computing with MATLAB 6. Brent. The secondorder heliocentric equations of motion of a satellite or celestial body subject to the point mass gravitational attraction of the Sun and planets are given by 9 rpi rs b d 2r r p b i 2 r. This software also uses a onedimensional optimization algorithm due to Richard Brent to solve the close approach problem. R.m) uses a combination of Cowell’s method and onedimensional minimization to predict closest approach conditions between the Earth and objects such as asteroids. t s pi r 3 3 3 dt rs b i 1 rpi r p b i where s gravitational constant of the Sun p gravitational constant of planet i i rp position vector from the Sun to planet rs b position vector from the Sun to the body rp b position vector from the planet to the body These position vectors are related according to rs b rp rp b This program uses the RungeKuttaFehlberg 7(8) method to numerically integrate the firstorder form of the orbital equations of motion. Earth.
jpl. This feature is important because the analytic first derivative of many objective functions is difficult to derive and code.1998 initial TDB (0 <= hours <= 24.4836740409964595D+00 initial orbital inclination (J2000 equator and equinox) (degrees. 0 <= argument of perihelion <= 360) 0. initial calendar date (1 <= month <= 12.2708752703925974D+03 Please note the proper units and coordinate system (J2000 equinox and equator) of the input orbital elements.0. The software will ask you for the name of a simple ASCII input file that defines the simulation. The following is a typical input data file for this program. 0 <= seconds <= 60) 0. When responding to this request be sure to include the file name extension. This file was created using data available on the Horizons ephemeris system which is located on the Internet at http://ssd. Do not change the total number of lines or the order of annotation and data in this file. 0 <= raan <= 360) 0.2017287833484568D+02 initial argument of perihelion (J2000 equator and equinox) (degrees.gov/horizons.0 initial semimajor axis (AU) (semimajor axis > 0) 0. Notice also that time on the TDB scale is used. program cae2ho < closest approach between the Earth and a heliocentric object > Page 29 . The following is a typical user interaction with this MATLAB script.3533298230482567D+03 initial mean anomaly (J2000 equator and equinox) (degrees. The user can specify the search duration in days and a minimum close approach distance in Astronomical Units. It contains the J2000 equator and equinox heliocentric orbital elements of the asteroid 1997 XF 11. Be sure to include all the digits of the calendar year. The objective function for this program is the scalar geocentric distance of the heliocentric object.Celestial Computing with MATLAB objective function.html.1441779254846407D+01 initial orbital eccentricity (nondimensional) (0 <= eccentricity < 1) 0. 1 <= day <= 31. 0 <= mean anomaly <= 360) 0.nasa. The software expects to find exactly 31 lines of information in the input data file.3228014264370198D+03 initial right ascension of the ascending node (J2000 equator and equinox) (degrees. 0 <= inclination <= 180) 0. year = all digits!) 10. 0 <= minutes <= 60.20.
5334764382e+002 eccentricity 4. the output will be with respect to the J2000 dynamical equinox and equator.8445583509e+002 < please press any key to continue > DE405 ephemeris time and conditions at closest approach calendar date TDB time TDB Julian date geocentric distance geocentric distance 31Oct2002 00:26:38 2452578.Celestial Computing with MATLAB < please press any key to continue > please input the name of the data file (be sure to include the file name extension) ? xf11.0165272969e+001 argper (deg) 3. Page 30 .1 please select the ephemeris source (1 = DE405.5332982305e+002 eccentricity 4.8412378833e001 inclination (deg) 2.06350013 AU km 9499483.9902794530e+001 < please press any key to continue > For this example the output is with respect to the J2000/ICRF equinox and equator.3186814210e003 true anomaly (deg) arglat (deg) 2.0172878335e+001 argper (deg) 3.83935515 heliocentric orbital elements (J2000/ICRF equinox and equator) sma (au) 1.dat please input the search duration (days) ? 2000 would you like to enforce a minimum distance constraint (y = yes.3224150847e003 true anomaly (deg) arglat (deg) 7. n = no) ? y please input the minimum distance constraint (AU) ? .2279202361e+002 period (days) 7. When using SLP96 as the source ephemeris.4422695673e+000 raan (deg) 3.4417792548e+000 raan (deg) 3. 2 = SLP96) ? 1 The software will display the initial conditions as follows: initial heliocentric orbital elements (J2000/ICRF equinox and equator) sma (au) 1.2165440865e+002 1.7110770918e+001 3.8367404100e001 inclination (deg) 2.5185 0.2280142644e+002 period (days) 7.
For each event. time of the equinoxes and solstices please input the calendar year ? 2000 time of the equinoxes and solstices spring equinox calendar date dynamical time summer solstice calendar date dynamical time fall equinox calendar date dynamical time winter solstice calendar date dynamical time 21Dec2000 13:38:30 22Sep2000 17:28:45 21Jun2000 01:48:48 20Mar2000 07:36:11 Page 31 . where 90 for the summer solstice.m solar ephemeris to calculate these events. The initial time for the spring equinox is March 15. The following is a typical user interaction with this script. The equsol script will prompt you for the calendar date of interest. Please note that the event is displayed in dynamical or ephemeris time. Brent’s method also requires an initial and final time which bounds the root of the objective function. 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 . This script uses Brent’s rootfinder and the sun1.Celestial Computing with MATLAB 7. Brent’s method requires an objective function that defines the nonlinear equation to be solved. for the summer solstice June 15.m) determines the time of the equinoxes and solstices of the Earth. 270 for the winter solstice and s is the geocentric apparent longitude of the Sun. for the fall equinox September 15 and for the winter solstice December 15. the final time is equal to these initial dates plus 15 days. Equinoxes and Solstices This MATLAB script (equsol. These events are the times when the apparent geocentric longitude of the Sun is an exact multiple of 90 degrees.
Cowell’s Method for Heliocentric Orbits cowell1.m) uses Cowell’s method to propagate the motion of spacecraft.967329 orbital inclination (degrees) (0 <= inclination <= 180) Page 32 . calendar date of perihelion passage (1 <= month <= 12. The low precision ephemerides used in this application can be replaced with the DE405 or SLP96 algorithms. Earth. 1 <= day <= 31. t s pi r 3 3 3 dt rs b i 1 rpi r p b i where s gravitational constant of the Sun p gravitational constant of planet i i rp position vector from the Sun to planet rs b position vector from the Sun to the body rp b position vector from the planet to the body These position vectors are related according to rs b rp rp b The following data file defines a simulation for Halley’s comet.587478 orbital eccentricity (nondimensional) (0 <= eccentricity < 1) 0. Mars. Saturn and the Sun. It includes the point mass gravity perturbations due to the planets Venus.m – rectangular position and velocity vector formulation This MATLAB script (cowell1.1986 universal time of perihelion passage (0 <= hours <= 24. 0 <= seconds <= 60) 15.52. year = all digits!) 2. Jupiter.14. The secondorder heliocentric equations of motion of a satellite or celestial body subject to the point mass gravitational attraction of the Sun and planets are given by 9 rpi rs b d 2r r p b i 2 r.Celestial Computing with MATLAB 8.9. 0 <= minutes <= 60.592 perihelion radius (Astronomical Units) (perihelion radius > 0) 0. comets and other celestial bodies in heliocentric elliptic orbits.
1291 The syntax of the MATLAB function that reads this file is as follows: function [fid.dat initial calendar date and universal time please input the calendar date (1 <= month <= 12. oev1. year = all digits!) ? 1.m and cowell2. jdpp] = readoe2(filename) % read orbital elements data file % required by encke. program cowell1 < heliocentric orbit propagation using Cowell's method > < please press any key to continue > simulation data menu <1> user input <2> data file ? 2 please input the simulation data file name (be sure to include the file name extension) ? halley.1986 please input the universal time Page 33 .Celestial Computing with MATLAB 162.8114 right ascension of the ascending node (degrees) (0 <= raan <= 360) 58.2486 argument of perigee (degrees) (0 <= argument of perigee <= 360) 111.m % input % filename = name of orbital element data file % output % % % % % % % % fid jdpp oev(1) oev(2) oev(3) oev(4) oev(5) oev(6) = = = = = = = = file id julian date of perihelion passage semimajor axis orbital eccentricity orbital inclination argument of perigee right ascension of the ascending node true anomaly The following is a typical user interaction with this script.1. 1 <= day <= 31.
m) determines the longterm orbit evolution of objects in heliocentric orbits using Cowell’s solution of the modified equinoctial orbital elements form of the differential equations of motion.6903161323e+009 raan (deg) 5. program cowell2 < heliocentric orbit propagation using Cowell's method > simulation data menu <1> user input <2> data file ? 2 please input the simulation data file name (be sure to include the file name extension) Page 34 . The following is a typical user interaction with this script.1932241905e+002 perihelion radius 5.0. 0 <= seconds <= 60) ? 0.m – modified equinoctial orbital elements formulation This MATLAB script (cowell2.6733201594e001 inclination (deg) 1.Cowell's method > final conditions calendar date universal time sma (km) 2.1181332479e+002 period (days) 2.0750909426e+002 2.Celestial Computing with MATLAB (0 <= hours <= 24.m script above.8748967570e001 AU cowell2.0 please input the simulation period (days) ? 120 please input the algorithm error tolerance (a value of 1. 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.8130641784e+001 01May1986 00:00:00 eccentricity 9.0e10 is recommended) ? 1e8 The following is the output created for this example: program cowell1 < heliocentric orbital motion .6224898626e+002 argper (deg) 1.7855777571e+004 true anomaly (deg) arglat (deg) 1. 0 <= minutes <= 60.
0750909422e+002 2.0.6224898624e+002 argper (deg) 1. 1 <= day <= 31.6733201271e001 inclination (deg) 1.Celestial Computing with MATLAB ? halley. 0 <= minutes <= 60.0e8 is recommended) ? 1e8 The following is the data display for this example.8748967534e001 AU 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 . year = all digits!) ? 1. program cowell2 < heliocentric orbital motion .6903158654e+009 raan (deg) 5.1181332505e+002 period (days) 2.1986 please input the universal time (0 <= hours <= 24.Cowell's method > final conditions calendar date universal time sma (km) 2.0 please input the simulation period (days) ? 120 please input the algorithm error tolerance (a value of 1.1932241926e+002 perihelion radius 5.7855773424e+004 true anomaly (deg) arglat (deg) 1.1. 0 <= seconds <= 60) ? 0.8130641942e+001 01May1986 00:00:00 eccentricity 9.dat initial calendar date and universal time please input the calendar date (1 <= month <= 12.
n are external perturbations in the radial. respectively. tangential and orbit normal directions. The equations of motion can also be expressed as follows: y dy A yP b dt Page 36 . t .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: p dp 2 p dt w p t df f dt dg dt p g r sin L w 1 cos L f t h sin L k cos L n w w p g r cos L w 1 sin L g t h sin L k cos L n w w p s2n cos L 2w p s2n sin L 2w 2 g dh h dt dk k dt dL p w 1 p h sin L k cos L L n dt p w where r .
tangential and normal directions given i i i by Page 37 . ˆt and ˆn are unit vectors in the radial. ˆr . Other perturbations such as solar radiation pressure can also be included.Celestial Computing with MATLAB where A y 0 p sin L cos L 2p p q p1 q 1 cos L f q p p g h sin L k cos L q p f h sin L k cos L q 2 p s cos L 2q p s 2 sin L 2q p h sin L k cos L 0 p q 1 sin L g 0 0 0 0 0 0 and 0 0 0 0 b 0 2 q p p In this equation P is the total disturbing acceleration vector given by P r ˆr t ˆt n ˆn i i i In this MATLAB script these perturbations consist of the pointmass gravity effects of the planets. Furthermore.
Celestial Computing with MATLAB ˆ r ir r ˆ rv in rv ˆ ˆ ˆ it i n i r Page 38 .
the time interval used is usually a function of the numerical integration technique and the magnitude of the perturbations. When these errors become “large”. Jupiter. t dt 2 rp where rp is the perturbed position vector at any time t and a rp . The classic form of Encke’s special perturbation method solves the initial value problem (IVP) of celestial mechanics by analytically propagating a twobody “reference” orbit and numerically integrating the deviations from twobody motion. The numerical algorithm used in this script simplifies this technique by using a variable stepsize integration method to automatically select the propagation step size. The difference between these two types of orbital motion is Page 39 . This involves adding the integrated deviations to the twobody orbit to produce a new reference orbit called the osculating orbit. The twobody or unperturbed equations of motion of a spacecraft or celestial body are r t d 2rk k 3 0 2 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. Furthermore. These two procedures are performed for the same time interval or step size. Mars. a process known as rectification of the orbit is performed. Since the twobody solution is “exact”. After rectification. After each propagation interval. Since this type of integrator “senses” the magnitude of the perturbations. the errors between the reference orbit and the perturbed orbit are evaluated. Encke’s Method for Heliocentric Orbits This MATLAB application (encke. Earth. It includes the point mass gravity perturbations due to the planets Venus.m) demonstrates heliocentric orbit propagation using Encke’s method.Celestial Computing with MATLAB 9. Saturn and the Sun. The user can control how well this procedure is performed with the algorithm truncation error tolerance. the software eliminates the logic required to determine when rectification should occur by simply rectifying the orbit after each and every propagation step. it will choose the “best” and largest step size for each propagation interval. The equations of motion of motion of a spacecraft subject to a point mass central body and other external perturbations are r t d 2r p p 3 a rp . t is the vector of perturbations or other accelerations. 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.
Celestial Computing with MATLAB 2r d 2rp d 2rk 2 2 dt 2 dt dt In order to avoid numerical difficulties when subtracting small differences of vector equations. t p b 3 p 3 rp b rp 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. Page 40 . t 3 3 3q q 2 f q q 1 1 q 3/ 2 where 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 r a r. The “deviation” equations of motion are integrated using a slightly modified version of the RungeKuttaFehlberg 7(8) method called rkencke. the following form of the equations of motion is used: 2r dt 2 f q r p t r p t a rp .
the integrator would use the initial step size defined by the user. This is accomplished by setting the initial step size guess to a small value and the truncation error tolerance to a very large value. 1992. the simulation duration in days. February 2426.1986 please input the universal time (0 <= hours <= 24.1.dat initial calendar date and universal time please input the calendar date (1 <= month <= 12. year = all digits!) ? 1. 0 <= seconds <= 60) ? 0. A tolerance of 1. AAS/AIAA Spaceflight Mechanics Meeting. Colorado Springs.0 Page 41 . and the algorithm error tolerance. 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 userdefined error tolerance. program encke < orbit propagation using Encke's method > < please press any key to continue > simulation data menu <1> user input <2> data file ? 2 please input the simulation data file name (be sure to include the file name extension) ? halley. The truncation error tolerance for this phase is set to a very small number. For both options the program will always ask the user for the initial calendar date and Universal Time of the simulation. The “best” initial step size depends on the type of orbit propagation and the initial conditions. 1 <= day <= 31. Colorado. For the second phase of the propagation. Since there are no perturbations at the initial epoch of the osculating reference orbit. Additional information about this algorithm can be found in AAS 92196.0. “A Simple and Efficient Computer Implementation of Encke’s Method”. 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.Celestial Computing with MATLAB Although simple and straightforward. To avoid this problem. the software forces the algorithm to perform the first phase of the orbit propagation with a fixed step size. 0 <= minutes <= 60. This will cause very large errors before rectification can be performed. The following is a typical user interaction with this program. this approach does require special attention to the initialization at the start of each propagation step.0e8 is recommended.
6903155747e+009 raan (deg) 5.1932241926e+002 perihelion radius 5. final conditions calendar date universal time sma (km) 2.7855768910e+004 true anomaly (deg) arglat (deg) 1.6224898624e+002 argper (deg) 1.Celestial Computing with MATLAB please input the simulation period (days) ? 120 please input the algorithm error tolerance (a value of 1.6733200916e001 inclination (deg) 1.1181332495e+002 period (days) 2. The following is the screen display created by this software for this example.0750909431e+002 2.8130641692e+001 01May1986 00:00:00 eccentricity 9.8748967589e001 AU The low precision ephemeris used in this application can be replaced with the DE405 or SLP96 algorithms very easily.0e8 is recommended) ? 1e8 This program also uses the readoe2 function to process the input data file. Page 42 .
subscript 1 is the Earth and subscript 2 is the Moon. Academic Press. This is a special case of the general threebody problem where the primary and secondary bodies move in circular orbits about the common center of mass. and the unit of time is chosen such that the Earth and Moon have an angular velocity about the barycenter equal to 1. Kepler’s third law for this formulation is given by 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 x2 1 y1 0 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. In the discussion that follows.Celestial Computing with MATLAB 10. Technical Discussion The motion of the spacecraft or celestial body is modeled in a coordinate system which is rotating about the centerofmass or barycenter of the EarthMoon system. The CircularRestricted ThreeBody Problem This section describes several MATLAB scripts that can be used to analyze and display orbits in the circularrestricted threebody problem (CRTBP). However. The classic textbook for this problem is Theory of Orbits by Victor Szebehely. The applications described here are for orbital problems in the EarthMoonsatellite system. Dover Publications. New York. 1967. The system of secondorder nondimensional differential equations of motion of a pointmass satellite or celestial body in this rotating coordinate system are given by Page 43 . For convenience. 1970. An excellent discussion about this problem can also be found in Chapter 8 of An Introduction to Celestial Mechanics by Forest Ray Moulton. The unit of length is taken to be the constant distance between the Earth and Moon. The motion of all three bodies is confined to the xy plane. and the effect of the gravitational attraction of the smallest body and any other perturbations such as solar radiation pressure are ignored. the equations and algorithms are valid for any circularrestricted threebody system for which the mass ratio of the primary and secondary is between 0 and 1/2. nonrotating coordinate system. the problem is formulated in canonical or nondimensional units.
Page 44 .27 r12 x x1 y 2 z 2 2 r22 x x2 y 2 z 2 2 The Jacobi integral for the threebody problem is given by V 2 x2 y2 2 1 2 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. it will stay there permanently provided there are no perturbations. JosephLouis Lagrange proved that there are five equilibrium points in the circularrestricted threebody problem. These special positions are also called libration points or stationary Lagrange points.m – coordinates and energy of the libration points In his prize memoir of 1772. Three of these libration points are on the xaxis (collinear points) and the other two form equilateral triangles with the positions of the Earth and Moon. crtbp1. If a satellite or celestial body is located at one of these points with zero initial velocity relative to the rotating coordinate system.Celestial Computing with MATLAB d 2x dy xx xx 2 x 1 3 1 3 2 2 dt dt r1 r2 d2y dx y y 2 y 1 3 3 2 dt dt r1 r2 d 2z z z 1 3 3 2 dt r1 r2 where x x component of position y y component of position z z component of position x1 x2 1 EarthMoon mass ratio m1 / m2 1/ 81.
For the collinear libration points this script solves three nonlinear equations. For these two libration points r1 r2 1 .01 The following is the program output for this example.000000 energy 1. program crtbp1 < equilibrium coordinates and energy > please input the value for the mass ratio ? . The nonlinear equation for the L1 libration point is given by x 1 x 2 x 1 2 0 The nonlinear equation for the L2 libration point is x 1 x 2 x 1 2 0 and the nonlinear equation for the L3 collinear libration point is x 1 x 2 x 1 2 0 The lower and upper bounds used during the rootfinding search for all three equations are x 2 and x 2 respectively.5838206546e+000 Page 45 .0000000000e002 location L1 xcoordinate 0. program crtbp1 < equilibrium coordinates and energy > mass ratio = 1.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.848079 ycoordinate 0. The L4 libration point is located at x 1 2 . The following is a typical user interaction with this script. y 3 2 and the L5 libration point is at x 1 2 . y 3 2 .
Celestial Computing with MATLAB L2 L3 L4 L5 1. The initial conditions for each of these example orbits are as follows: (1) periodic orbit about the L1 libration point x0 0.146765 1.300000161 y0 2. Broucke.004167 0.490000 0.536145497 0. 1968. A. This script begins by displaying the following main menu.4950500000e+000 g3body.5049988584e+000 1.747640074 0.933318588 Page 46 . by R.490000 0.000000 0.349501906 (2) periodic orbit about the L2 libration point x0 2.866025 1.000000 0.m – graphics display of threebody motion This MATLAB script graphically displays motion of a spacecraft or small celestial body in the circularrestricted threebody problem. This algorithm and program examples are based on the methods described in “Periodic Orbits in the Restricted ThreeBody Problem with EarthMoon Masses”. 2. JPL TR 321168.866025 0.012155092 t f 5. program g3body < graphics display of threebody motion > main menu <1> periodic orbit about L1 <2> periodic orbit about L2 <3> periodic orbit about L3 <4> user input of initial conditions selection (1.012155085 t f 11.4950500000e+000 1.5771597543e+000 1. 3 or 4) The first three menu options will display typical periodic orbits about the respective libration point.840829343 y0 2.
Celestial Computing with MATLAB
(3) periodic orbit about the L3 libration point
x0 1/ 600000312 y0 2.066174572
0.012155092
t f 6.303856312
Notice that each orbit is defined by an initial xcomponent of position, x0 , an initial y component of velocity, y0 , a value of EarthMoon mass ratio , and an orbital period t f . The initial ycomponent of position and xcomponent of velocity for each of these orbits is equal to zero. The software will draw the location of the Earth, Moon and libration point on the graphics screen. 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. (1) Retrograde periodic orbit about m1
x0 2.499999883 y0 2.100046263
0.012155092
t f 11.99941766
(2) Direct periodic orbit about m1
x0 0.952281734 y0 0.957747254
0.012155092
t f 6.450768946
(3) Direct periodic orbit about m1 and m2
Page 47
Celestial Computing with MATLAB
x0 3.147603117 y0 3.07676285
0.012155092
t f 12.567475674
(4) Direct periodic orbit about m2
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.
Periodic Orbit about the L3 Libration Point
2
1.5
1
0.5
y coordinate
0
−0.5
−1
−1.5
−2 −2
−1.5
−1
−0.5
0 0.5 x coordinate
1
1.5
2
Another excellent source of circularrestricted threebody problems is described in the report, “A Collection of Restricted Threebody Test Problems” by Philip W. Sharp, Report Series
Page 48
Celestial Computing with MATLAB
460, Department of Mathematics, University of Auckland, March 2001. A copy of this report in PDF format can be found at the following web site: http://www.scitec.auckland.ac.nz/~sharp/papers/preprints.html 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 .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0.994000E+00 0.994000E+00 0.994000E+00 0.997000E+00 0.879962E+00 0.879962E+00 0.879962E+00 0.997000E+00 0.100000E+01 0.100300E+01 0.120000E+01 0.120000E+01 0.120000E+01 0.120000E+01 0.120000E+01 0.102745E+01 0.976680E+00 0.766650E+00 0.109137E+01 0.110137E+01 0.21138987966945026683E+01 0.20317326295573368357E+01 0.20015851063790825224E+01 0.16251217072210773125E+01 0.66647197988564140807E+00 0.43965281709207999128E+00 0.38089067106386964470E+00 0.18445010489730401177E+01 0.16018768253456252603E+01 0.14465123738451062297E+01 0.71407169828407848921E+00 0.67985320356540547720E+00 0.67153130632829144331E+00 0.66998291305226832207E+00 0.66975741517271092087E+00 0.40334488290490413053E01 0.61191623926410837000E01 0.51230158665978820282E+00 0.14301959822238380020E+00 0.15354250908611454510E+00 0.54367954392601899690E+01 0.11124340337266085135E+02 0.17065216560157962559E+02 0.22929723423442969481E+02 0.63006757422352314657E+01 0.12729711861022426544E+02 0.19138746281183026809E+02 0.12353901248612092736E+02 0.12294387796695023304E+02 0.12267904265603897140E+02 0.18337451820715063383E+02 0.30753758552146029263E+02 0.43214375227857454128E+02 0.55672334134347612727E+02 0.68127906604713772763E+02 0.18371316400018903965E+03 0.17733241131524483004E+03 0.17660722897242937108E+03 0.82949461922342093092E+02 0.60952121909407746612E+02
zvcurve1.m – graphics display of zero velocity curves through equilibrium points
This MATLAB script can be used to display zero relative velocity curves that pass through the five equilibrium or libration points of the EarthMoon circularrestricted threebody problem (CRTBP). These twodimensional drawings are also called equipotential curves.
Page 49
The libration points are labeled with asterisks and the Earth and Moon are shown as small dots. 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. 3. program zvcurve1 graphics display of zero relative velocity curves through the crtbp equilibrium points <1> L1 contour <2> L2 contour <3> L3 contour <4> L4 and L5 contour <5> all points contour selection (1. E0 1 2 x y2 1 r 2 r1 2 From the Jacobi integral we can see that imaginary velocities occur whenever the following expression is smaller than the Jacobi constant C. The following is a typical user interaction with this script. 2. If we set the velocity components to zero in the equation for the Jacobi integral. Page 50 .Celestial Computing with MATLAB The zero velocity curves define regions of the xy plane that a satellite or celestial body with a given energy level can or cannot attain. 4 or 5) ?5 The following is a graphics display of the equipotential curves through each libration point. x2 y2 2 1 2 r1 r2 This MATLAB script computes and displays zero relative velocity contour plots that actually pass through the five libration points.
5 0 x coordinate 0.Celestial Computing with MATLAB Zero Relative Velocity Curves through L1−L5 1.5 −1 −0. Please note that if the mesh grid increment is too large the script may not plot “complete” contour levels.5 −1.5 −1 −1. program zvcurve2 graphics display of userdefined zero relative velocity curves Page 51 .5 1 0. 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.5 1 1.m – graphics display of userdefined zero relative velocity curves This MATLAB script can be used to display zero relative velocity contour curves of the circularrestricted threebody problem (CRTBP) for userdefined 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 userdefined increment. The following is a typical user interaction with this MATLAB script.5 zvcurve2.5 y coordinate 0 −0.
0 would you like to label the contours (y = yes. The libration points for this threebody system are labeled with asterisks and the primary and secondary bodies are shown as small dots. Page 52 .2 contour level input menu <1> lower value.0 please input the contour increment ? 0. increment.01 and 0. upper value <2> discrete contour values selection (1 or 2) ? 1 please input the lower contour value ? 3.005 is recommended) ? 0.Celestial Computing with MATLAB please input the value for the mass ratio ? 0. n = no) ? n please input the minimum value for the x and y coordinates ? 2 please input the maximum value for the x and y coordinates ? 2 please input the mesh grid value for x and y (a value between 0.01 The following is the graphics display for this example.1 please input the upper contour value ? 4.
0 Page 53 .5 −1 −1.Celestial Computing with MATLAB Zero Relative Velocity Curves for Mass Ratio = 0.5 0 0.2 2 1.2 contour level input menu <1> lower value.5 2 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. upper value <2> discrete contour values selection (1 or 2) ? 1 please input the lower contour value ? 3.5 x coordinate 1 1.5 −1 −0.5 −2 −2 −1.5 y coordinate 0 −0. increment. program zvcurve2 graphics display of userdefined zero relative velocity curves please input the value for the mass ratio ? 0.5 1 0.
5 please input the mesh grid value for x and y (a value between 0.5 x coordinate 1 1.01 and 0.2 1. Zero Relative Velocity Curves for Mass Ratio = 0. The libration points for this threebody system are labeled with asterisks and the primary and secondary bodies are shown as small dots.3 3.2 0 0 0.1 please input the upper contour value ? 3.5 3.01 The following is the graphics display for this example.005 is recommended) ? 0. n = no) ? y please input the minimum value for the x and y coordinates ? 0 please input the maximum value for the x and y coordinates ? 1.5 would you like to label the contours (y = yes.5 3.5 Page 54 .1 y coordinate 0.Celestial Computing with MATLAB please input the contour increment ? 0.5 3.4 3 1 3.
Yallop. III. Hughes. Vol.D. 4. Apparent Coordinates of a Planet or the Moon These two MATLAB functions can be used to determine the apparent geocentric and topocentric coordinates of a planet or the Moon. pages 11971210. 1989. and Astrometric Places of Planets and Stars”.Celestial Computing with MATLAB 11. The processing steps used in these two MATLAB scripts are as follows: (1) input a calendar date on the UT1 time scale (2) compute the UT1 Julian date (3) compute the TDT Julian date (4) compute the TDB Julian date (5) select the target body (6) define type of coordinates (7) evaluate the ephemeris The topocentric azimuth A and elevation (altitude) h are calculated using the topocentric right ascension and declination and the observer's coordinates as follow: tan A sin H cos H sin tan cos Page 55 . J. P. These functions use several functions ported to MATLAB using the Fortran versions of the NOVAS (Naval Observatory Vector Astrometry Subroutines) source code that was developed at the United States Naval Observatory. 97. Kaplan. These functions includes the following types of coordinate corrections: (1) precession (2) nutation (3) aberration (4) gravitational deflection of light Please note that these functions do not include a correction for atmospheric refraction. Smith and B. The Astronomical Journal. C. An excellent discussion about these corrections can be found in “Mean and Apparent Place Computations in the New IAU System. Apparent.K. Topocentric.H. Seidelmann. G.A. No.A.
For example.m The source ephemeris for this routine is the DE405 binary file jpleph. glon. the “target” body and the type of ephemeris (topocentric or geocentric). universal time. The following is the syntax for this MATLAB function. rectangular coordinates of % solar system bodies are obtained from function solsys. observer coordinates. ujd. The program defaults to the Earth as the central or “primary” body. function [ra. glat. referred to true equator and equinox of date (degrees) dis = true distance from earth to planet (astronomical units) A MATLAB script called aplanet1 demonstrates how to interact with this function. aplanet1 . east is an azimuth of 90.apparent coordinates please input a UTC calendar date please input the calendar date Page 56 . referred to true equator and equinox of date (hours) dec = apparent geocentric or topocentric declination. dec. l. topo. degrees) geodetic latitude of observer (north +. dis] = applan1 (tjd. This script will prompt you for the calendar date.Celestial Computing with MATLAB where H is the apparent hour angle of the celestial object and is the geodetic latitude of the observer. ht) % this function computes the apparent geocentric or topocentric place % of a planet or other solar system body. degrees) height of observer (meters) % output % % % % % ra = apparent geocentric or topocentric right ascension. south is 180 and so forth. 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. The following is a typical user interaction with this demonstration script. % input % % % % % % % % % % tjd ujd l n topo = = = = = = = glon = glat = ht = tdt julian date for apparent geocentric place ut1 julian date for apparent topocentric place body identification number for desired planet body identification number for the earth type of apparent place calculation 0 ==> geocentric 1 ==> topocentric geodetic longitude of observer (east +. function applan1. n.
00s +40d 00m 00.0 please input the altitude of the ground site (meters) (positive above sea level. 0 <= seconds <= 60) (east longitude is positive.1998 please input the universal time (0 <= hours <= 24. year = all digits!) ? 1. 0 <= seconds <= 60) (north latitude is positive.9309 105d 00m 00.20. 0 <= seconds <= 60) ? 10.0. 0 <= minutes <= 60.00s Page 57 . apparent topocentric coordinates 'Moon' UTC calendar date universal time UTC julian date observer latitude observer east longitude 01Jan1998 10:20:30 2450814.1. 0 <= minutes <= 60. negative below sea level) ? 1000 The following is the program output created for this example.Celestial Computing with MATLAB (1 <= month <= 12.30 target body menu <1> Mercury <2> Venus <3> Earth <4> Mars <5> Jupiter <6> Saturn <7> Uranus <8> Neptune <9> Pluto <10> Sun <11> Moon please select the target body ? 11 coordinate type menu <1> geocentric <2> topocentric please select coordinate type ? 2 please input the geographic latitude of the ground site (90 <= degrees <= +90.0. 1 <= day <= 31.0 please input the geographic longitude of the ground site (0 <= degrees <= 360. west longitude is negative) ? 105. south latitude is negative) ? 40. 0 <= minutes <= 60.
The user interaction with this script is identical to the interaction with the aplanet1 script described above.Celestial Computing with MATLAB observer altitude right ascension declination azimuth elevation topocentric distance 1000.0000 meters +21h 12m 2.08s 376284.4187 kilometers function applan2. l.9587s 14d 17m 47. dec. degrees) height of observer (meters) % output % % % % % ra = apparent geocentric or topocentric right ascension. The following is the syntax for this function. referred to true equator and equinox of date (hours) dec = apparent geocentric or topocentric declination. referred to true equator and equinox of date (degrees) dis = true distance from earth to planet (astronomical units) The MATLAB script called aplanet2 demonstrates how to use this function. glon. degrees) geodetic latitude of observer (north +. n. % input % % % % % % % % % % tjd ujd l n topo = = = = = = = glon = glat = ht = tdt julian date for apparent geocentric place ut1 julian date for apparent topocentric place body identification number for desired planet body identification number for the earth type of apparent place calculation 0 ==> geocentric 1 ==> topocentric geodetic longitude of observer (east +. Page 58 . glat. ht) % this function computes the apparent geocentric or topocentric place % of a planet or other solar system body. function [ra. rectangular coordinates of % solar system bodies are obtained from function slp96.m The source ephemeris for this routine is the SLP96 binary file slp96. dis] = applan2(tjd. topo.57s +27d 31m 13. ujd.82s 61d 53m 39.
For extragalatic objects the proper motions. 97. No. parallax and radial velocity (6) define type of coordinates (7) calculate apparent coordinates The syntax and arguments for the MATLAB function that actually performs most of the calculations are as follows: Page 59 . Yallop. G.A. and Astrometric Places of Planets and Stars”. The processing steps used in this program are as follows: (1) input a calendar date on the UT1 time scale (2) compute the UT1 Julian date (3) compute the TDT Julian date (4) compute the TDB Julian date (5) read the star's coordinates. 1989.K. Topocentric. Smith and B.H. parallax and radial velocity should all be set to 0. proper motions. 4. An excellent discussion about these corrections can be found in “Mean and Apparent Place Computations in the New IAU System. The second script is called astar2 and it uses SLP96 as its source ephemeris. C. These applications use several functions ported to MATLAB from the Fortran versions of the NOVAS (Naval Observatory Vector Astrometry Subroutines) source code that was developed at the United States Naval Observatory. J. Apparent. III. P.A. Kaplan. Seidelmann. Vol.Celestial Computing with MATLAB 12. Apparent Coordinates of a Star These two MATLAB scripts demonstrate how to calculate the apparent topocentric and geocentric coordinates of a star. This program includes the following types of coordinate corrections: (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. Hughes.D. The Astronomical Journal. The first script is called astar1 and it uses DE405 as its source ephemeris. pages 11971210.
The following is a typical star data file named altair. to true equator and equinox of date (hours) geocentric or topocentric declination. It illustrates the topocentric coordinates of the star Altair relative to a sea level observer at 40 north latitude and 105 west longitude. to true equator and equinox of date (degrees) The astar software will prompt you for the calendar date.0 (hours) mean declination j2000. ujd..30 The following is a typical user interaction with the star1 (and star2) scripts. at 0 hours UT. parlax.6290 J2000 proper motion in declination (arcseconds/Julian century) 38. dec] = apstar1 (tjd. Page 60 .dat. parallax.. star name ALTAIR J2000 right ascension (hours) 19. the name of the star data file and the type of ephemeris (topocentric or geocentric). universal time. Do not delete any lines of text or data as the software expects to find exactly 20 lines of information. ram.0. pmdec. .8463894440 J2000 declination (degrees) 8. observer coordinates.Celestial Computing with MATLAB function [ra. decm.0 (degrees) proper motion in ra (seconds of time/julian century) proper motion in dec (seconds of arc/julian century) parallax (seconds of arc) radial velocity (kilometers per second) % output % % % % ra = apparent referred dec = apparent referred geocentric or topocentric right ascension.8683416670 J2000 proper motion in right ascension (seconds/Julian century) 3. % input % % % % % % % % % % % % tjd ujd n topo = = = = = = ram = decm = pmra = pmdec = parlax = radvel = tdt julian date for apparent place ut1 julian date for apparent topocentric place body identification number for the earth type of apparent place calculation 0 ==> geocentric 1 ==> topocentric mean right ascension j2000. glat. pmra. topo.6300 parallax (arcseconds) 0. given its mean place. and radial % velocity for j2000. n.1981 radial velocity (kilometers/second) 26. proper motion. radvel) % this subroutine computes the geocentric or topocentric apparent place % of a star. ht. glon.
1 <= day <= 31.0000 meters +19h 50m 39. 0 <= minutes <= 60. 0 <= minutes <= 60. 0 <= minutes <= 60.00s +40d 00m 00.1.00s 0.0.0.09s Page 61 .Celestial Computing with MATLAB star1 .1998 please input the universal time (0 <= hours <= 24.0 please input the star data file name (be sure to include the file name extension) ? altair. south latitude is negative) ? 40.1674s +08d 51m 46.dat coordinate type menu <1> geocentric <2> topocentric please select coordinate type ? 2 please input the geographic latitude of the ground site (90 <= degrees <= +90. west longitude is negative) ? 105. 0 <= seconds <= 60) ? 0.apparent coordinates .0 please input the altitude of the ground site (meters) (positive above sea level.5000 105d 00m 00.0 please input the geographic longitude of the ground site (0 <= degrees <= 360. 0 <= seconds <= 60) (north latitude is positive.jplephem ephemeris please input a UTC calendar date please input the calendar date (1 <= month <= 12. year = all digits!) ? 1. negative below sea level) ? 0 apparent topocentric coordinates ALTAIR UTC calendar date universal time UTC julian date observer latitude observer east longitude observer altitude right ascension declination 01Jan1998 00:00:00 2450814. 0 <= seconds <= 60) (east longitude is positive.0.
A. This variable should also be placed in a global statement at the beginning of the main script that calls this function. A. Gontier. Charlot. O. T. Arias. Eubanks.nasa. ntarg. and calculate the position and velocity vectors of a planet or the Moon. C. The following statement in the main MATLAB script will accomplish this: iephem = 1. B. ncent) % reads the jpl planetary ephemeris and gives % the position and velocity of the point 'ntarg' % with respect to point 'ncent' % input % % % % % % % % % % % et = julian ephemeris date at which interpolation is wanted ntarg = integer number of 'target' point ncent = integer number of center point the numbering convention for 'ntarg' and 'ncent' is: 1 2 3 4 5 6 7 = = = = = = = mercury venus earth mars jupiter saturn uranus 8 9 10 11 12 13 14 = = = = = = = neptune pluto moon sun solarsystem barycenter earthmoon barycenter nutations (longitude and obliq) Page 62 . The following is the syntax for this MATLAB function: function rrd = jplephem (et.gov. Ma. C. Jacobs.Celestial Computing with MATLAB 13. This function was ported to MATLAB using the Fortran source code subroutine provided by JPL. July.jpl. E. The name of this binary file is jpleph and it is valid between Julian date 2429616. Sovers. The jplephem function requires initialization the first time it is called. These ASCII files can be found on the Internet at ftp://navigator. 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”. 1998. Fey. The Astronomical Journal.5 (calendar date 12/19/1939) and Julian date 2473488. Archinal and P. JPL DE405 Lunar. Demojpl is a simple MATLAB script that demonstrates how to call the jplephem routine. 116:516546. A sample binary file for IBMPC compatible computers is included on the Celestial Computing with MATLAB CD ROM. Solar and Planetary Ephemeris This MATLAB script demonstrates how to read DE405 binary ephemeris files created using the Fortran programs and ASCII data files provided by the Jet Propulsion Laboratory. A CD ROM containing these ASCII data files and Fortran source code is also available from WillmannBell.5 (calendar date 1/30/2060).
21.1998 target body menu <1> Mercury <2> Venus <3> Earth <4> Mars <5> Jupiter <6> Saturn <7> Uranus <8> Neptune <9> Pluto <10> Moon <11> Sun please select the target body ? 10 central body menu <1> Mercury <2> Venus <3> Earth <4> Mars <5> Jupiter <6> Saturn <7> Uranus <8> Neptune <9> Pluto <10> Moon <11> Sun <12> solarsystem barycenter <13> EarthMoon barycenter please select the central body Page 63 . the option is available to have the units in km and km/sec. set ncent = 0.m function please input a UTC calendar date please input the calendar date (1 <= month <= 12. the units are au and au/day. year = all digits!) ? 10. having units of radians and radians/day. 15 = librations. in the case of nutations the first four words of rrd will be set to nutations and rates. demojpl . for librations. The following is a typical user interaction with this script. for librations the units are radians and radians per day.Celestial Computing with MATLAB % % % % output % % % % % % % % rrd = output 6word array containing position and velocity of point 'ntarg' relative to 'ncent'. set ntarg = 14. set km = 1 via global in the calling program. for this. 1 <= day <= 31. if on ephemeris file if nutations are wanted. set ntarg = 15.demonstrates how to use the jplephem.
5000 state vector rx (km) 3.Celestial Computing with MATLAB ? 3 target body central body 'Moon' 'Earth' UTC calendar date UTC Julian date 21Oct1998 2451107.0665239060e+005 vmag (kps) +9.8617936544e001 rmag (km) +4.9817990536e+004 vz (kps) 2.3908644803e001 ry (km) 2.1902562142e+005 vy (kps) 7.7111907995e001 Page 64 .3736590217e+005 vx (kps) +5.5535385071e001 rz (km) 5.
iframe. and calculate the position and velocity vectors of a planet or the moon in either the J2000 FK5 or dynamical coordinate systems. ibody. SLP96 Lunar. Solar and Planetary Ephemeris This MATLAB function demonstrates how to read SLP96 binary ephemeris files created using the Fortran programs and ASCII data files provided by the Bureau of Longitudes (BDL.fr/pub/ephem/sun/slp96.5 (calendar date 12/14/1949) and Julian date 2469808. This binary file is valid between Julian date 2433264. ierr] = slp96 (tjd. A sample binary file for IBMPC compatible computers is included on the Celestial Computing with MATLAB CD ROM. 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. icent. mars jupiter saturn ibody=07 ibody=08 ibody=09 ibody=10 ibody=11 ibody=12 : : : : : : uranus neptune void moon sun earth frame center index icent=00 icent=01 icent=02 icent=03 icent=04 : : : : : barycenter of solar system mercury icent=07 : uranus venus icent=08 : neptune em baryc. The following statement in the main MATLAB script will accomplish this: islp96 = 1. Demoslp is a simple MATLAB driver script that demonstrates how to call the slp96 routine. This function was ported to MATLAB using the Fortran source code subroutine provided by the BDL.5 (calendar date 1/02/2050). These ASCII files can be found on the Internet at ftp. The slp96 function requires initialization the first time it is called. The following is a summary of the inputs and outputs for this MATLAB function: function [result. icoord) % solar. lunar and planetary coordinates j2000 % input % % % % % % % % % % % % % % icent tjd ibody julian date tdb body index ibody=01 ibody=02 ibody=03 ibody=04 ibody=05 ibody=06 : : : : : : mercury venus em baryc.Celestial Computing with MATLAB 14. ipv. Paris).bdl. icent=09 : void mars icent=10 : moon Page 65 .
ipv=2 : position and velocity. frame index iframe=1 : equinox and equator j2000 (fk5) iframe=2 : equinox and ecliptic j2000 (dynamical) coordinates index icoord=1 : rectangular coordinates icoord=2 : spherical coordinates name of the slp96 data file note: passed via global icent=11 : sun icent=12 : earth % output % % % % % % % % % % % % % % % % % % % % % % % % % % % % ierr result results table rectangular coordinates (icoord = 1) position result(1) : equatorial or ecliptic component x (au) result(2) : equatorial or ecliptic component y (au) result(3) : equatorial or ecliptic component z (au) velocity result(4) : equatorial or ecliptic component x (au/day) result(5) : equatorial or ecliptic component y (au/day) result(6) : equatorial or ecliptic component z (au/day) spherical coordinates (icoord = 2) position result(1) : right ascension or longitude (radians) result(2) : declination or latitude (radians) result(3) : geometric distance (au) velocity result(4) : right ascension or longitude (rad/day) result(5) : declination or latitude (rad/day) result(6) : geometric distance (au/day) error index ierr=0 ierr=10 ierr=11 ierr=12 ierr=13 ierr=14 ierr=15 ierr=16 : : : : : : : : no error file error date error (tjd) body error (ibody) frame center error (icent) positionvelocity error (ipv) frame error (iframe) coordinates error (icoord) Page 66 .Celestial Computing with MATLAB % % % % % % % % % % % % % fname icoord iframe ipv icent=05 : jupiter icent=06 : saturn positionvelocity index ipv=1 : position.
year = all digits!) ? 10.1998 target body menu <1> Mercury <2> Venus <3> EarthMoon barycenter <4> Mars <5> Jupiter <6> Saturn <7> Uranus <8> Neptune <9> void <10> Moon <11> Sun <12> Earth please select the target body ? 10 central body menu <0> <1> <2> <3> <4> <5> <6> solar system barycenter Mercury Venus EarthMoon barycenter Mars Jupiter Saturn Page 67 .demonstrates how to use the slp96.m function please input a UTC calendar date please input the calendar date (1 <= month <= 12.21. 1 <= day <= 31. demoslp .Celestial Computing with MATLAB The processing steps used in this script are as follows: (1) input a calendar date on the UTC time scale (2) compute the UTC Julian date (3) compute the TDT Julian date (4) compute the TDB Julian date (5) select the target body (6) select the central body (7) define type of coordinate system (8) define type of coordinate calculations (9) specify the name of the SLP96 binary data file (10) evaluate the ephemeris The following is a typical user interaction with this script.
5000 state vector rx (km) 3.7111913078e001 Page 68 .8617931903e001 rmag (km) +4.5535382805e001 rz (km) 5.Celestial Computing with MATLAB <7> Uranus <8> Neptune <9> void <10> Moon <11> Sun <12> Earth please select the central body ? 12 coordinate system menu <1> equinox and equator j2000 (fk5) <2> equinox and ecliptic j2000 (dynamical) please select the coordinate system type ? 1 coordinate type menu <1> rectangular coordinates <2> spherical coordinates please select the coordinate type ? 1 The following is the program output created for this example.9818049020e+004 vz (kps) 2.3736588697e+005 vx (kps) +5.0665241115e+005 vmag (kps) +9. program demoslp equinox and equator j2000 (fk5) target body central body 'Moon' 'Earth' UTC calendar date UTC Julian date 21Oct1998 2451107.3908659599e001 ry (km) 2.1902566702e+005 vy (kps) 7.
00445036173t G4 0. The Astrophysical Journal Supplement Series.00145561327t G5 0. Page 69 . 41:391411. Pulkkinen. ecliptic position vector of the planet is determined from cos cos r r cos sin sin sun.993126 0. T.849694 0. Each MATLAB function uses fundamental trigonometric arguments (in revolutions) of the following form: Gs 0.00145569465t L4 0.0066cos 2G4 where the unit of r is Astronomical Units. Solar and Planetary Ephemeris Algorithms The next ten MATLAB functions are based on the algorithms described in “LowPrecision Formulae for Planetary Positions”. To the precision of this algorithm (one arc minute) these coordinates can be considered to be trueofdate. declination and position vector of the Sun. Each algorithm uses time arguments given by t JD 2451545 T t / 36525 1 where JD is the Julian date on the UT1 time scale. Other Lunar. C.00023080893t F4 0. latitude and distance r are computed from series involving these arguments. The heliocentric.00145575328t The heliocentric.987353 0.056531 0. Van Flandern and K.53031 0.053856 0. These series are of the form L4 38451sin G4 2238sin 2G4 181sin 3G4 6603sin F4 622sin G4 F4 615sin G4 F4 r 1.m – solar ephemeris This function calculates the trueofdate geocentric right ascension. ecliptic longitude .1417 cos G4 0. November 1979.00273777850t G2 0.140023 0. F.Celestial Computing with MATLAB 15.
The syntax of this MATLAB function is function rmercury = mercury (jdate) % trueofdate heliocentric. rsun] = sun (jdate) % solar ephemeris % input % jdate = Julian date % output % % % % % rasc = right ascension of the sun (radians) (0 <= rasc <= 2 pi) decl = declination of the sun (radians) (pi/2 <= decl <= pi/2) rsun = eci position vector of the sun (km) moon. declination and position vector of the Moon.m – lunar ephemeris This function calculates the trueofdate geocentric right ascension.Celestial Computing with MATLAB The syntax of this MATLAB function is function [rasc.m – Mercury ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Mercury. ecliptic % position vector of Mercury % input % jdate = julian date Page 70 . decl. rmoon] = moon (jdate) % lunar ephemeris % input % jdate = julian date % output % % % % % rasc = right ascension of the moon (radians) (0 <= rasc <= 2 pi) decl = declination of the moon (radians) (pi/2 <= decl <= pi/2) rmoon = eci position vector of the moon (km) mercury. The syntax of this MATLAB function is function [rasc. decl.
ecliptic % position vector of Mars % input % jdate = Julian date Page 71 . ecliptic % position vector of venus % input % jdate = Julian date % output % rvenus = position vector of Venus (km) earth.Celestial Computing with MATLAB % output % rmercury = position vector of Mercury (km) venus. The syntax of this MATLAB function is function rvenus = venus (jdate) % trueofdate heliocentric. ecliptic % position vector of the Earth % input % jdate = Julian date % output % rearth = position vector of the Earth (km) mars.m – Earth ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of the Earth.m – Venus ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Venus. The syntax of this MATLAB function is function rmars = mars (jdate) % trueofdate heliocentric. The syntax of this MATLAB function is function rearth = earth (jdate) % trueofdate heliocentric.m – Mars ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Mars.
Celestial Computing with MATLAB % output % rmars = position vector of Mars (km) jupiter.m – Saturn ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Saturn. ecliptic % position vector of Jupiter % input % jdate = Julian date % output % rjupiter = position vector of Jupiter (km) saturn.m – Jupiter ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Jupiter. The syntax of this MATLAB function is function rjupiter = jupiter (jdate) % trueofdate heliocentric. ecliptic % position vector of Uranus % input Page 72 . ecliptic % position vector of Saturn % input % jdate = Julian date % output % rsaturn = position vector of Saturn (km) uranus. The syntax of this MATLAB function is function rsaturn = saturn (jdate) % trueofdate heliocentric.m – Uranus ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Uranus. The syntax of this MATLAB function is function ruranus = uranus (jdate) % trueofdate heliocentric.
S . 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 A sin B cos m i 1 43 where m coordinate mean value iJ jS kP J .m – Pluto ephemeris This function calculates the heliocentric position vector of Pluto relative to the ecliptic and equinox of J2000. The syntax of this MATLAB function is function rneptune = neptune (jdate) % trueofdate heliocentric. ecliptic % position vector of Neptune % input % jdate = Julian date % output % rneptune = position vector of Neptune (km) pluto.m – Neptune ephemeris This function calculates the trueofdate heliocentric ecliptic position vector of Neptune. Saturn and Pluto i. B coefficients of periodic term The syntax of this MATLAB function is Page 73 . P mean longitudes of Jupiter. j.Celestial Computing with MATLAB % jdate = Julian date % output % ruranus = position vector of Uranus (km) neptune. k integer constants A.
Celestial Computing with MATLAB
function rpluto = pluto(jdate) % heliocentric coordinates of pluto % heliocentric position vector of Pluto % ecliptic and equinox of J2000 % input % jdate = Julian date
% output % rpluto = position vector of Pluto (km)
sun1.m – precision Sun ephemeris
This MATLAB function computes a trueofdate geocentric ephemeris of the Sun based on the data and numerical methods described in the book, Planetary Programs and Tables by Pierre Bretagnon and JeanLouis 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 U JED 2451545 3652500
The geocentric, ecliptic mean longitude of the Sun is calculated with a trigonometric series of the form
sm 0 1 U li sin i i U
i 1
50
The geocentric distance of the Sun is calculated with another series of the form rs r0 r1 U ri cos i i U
i 1 50
The longitude of the Sun is corrected for the effect of aberration (in radians) with the following equation: sa 107 993 17 cos 3.10 62830.14 U
The nutation in longitude (in radians) is calculated from
107 834sin A1 64sin A2
where
Page 74
Celestial Computing with MATLAB
A1 2.18 3375.70U 0.36U 2 A2 3.51 125666.39 U 0.10U 2
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 y s rs sin s zs 0 The apparent geocentric, equatorial right ascension s and declination s of the Sun can be found from
s arctan cos s ,sin sin s s arcsin sin sin s
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 where r is the geocentric distance of the Sun. This function requires initialization the first time it is called. The following statement in the main MATLAB script will accomplish this:
suncoef = 1;
Page 75
Celestial Computing with MATLAB
This variable should also be placed in a global statement at the beginning of the main script that calls this function. The syntax of this MATLAB function is
function [rasc, decl, rsun] = sun1 (jdate) % precision ephemeris of the Sun % input % jdate = julian ephemeris date
% output % % % % % rasc = right ascension of the Sun (radians) (0 <= rasc <= 2 pi) decl = declination of the Sun (radians) (pi/2 <= decl <= pi/2) rsun = eci position vector of the Sun (km)
elp2000.m – osculating orbital elements of the moon
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 ChaprontTouze and Jean Chapront. This book and its optional companion software are available from WillmannBell (www.willbell.com). The fundamental time argument of this algorithm is t JED 2451545 36525
where JED is the Julian Ephemeris Date. The osculating orbital elements are calculated from series of the form a 383397.6 Sa tSa where
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
30
Sa an cos n n t
0 1 n 1
The first few multipliers and trigonometric arguments for this orbital element are
Page 76
7370 n1 890534. demoelp < orbital elements of the moon > please input the calendar date (1 <= month <= 12.2 103.6 n 0 235.664 10.55 0.601 122.223 0 413335. function oev = elp2000(tjd) % osculating orbital elements of the moon % mean ecliptic and mean equinox of date % input % tjd = tdt Julian date % output % % % % % % % % % % % oev(1) oev(2) oev(3) oev(4) oev(5) oev(6) = semimajor axis (kilometers) = orbital eccentricity (nondimensional) (0 <= eccentricity < 1) = orbital inclination (radians) (0 <= inclination <= pi) = argument of perigee (radians) (0 <= argument of perigee <= 2 pi) = right ascension of ascending node (radians) (0 <= raan <= 2 pi) = true anomaly (radians) (0 <= true anomaly <= 2 pi) A MATLAB script called demoelp.1999 please input the simulation period (days) ? 360 please input the graphics step size (days) Page 77 .m which demonstrates how to interact with this ephemeris function is included with this software.2 377336.3 238.355 4 n 2 32.769 5.Celestial Computing with MATLAB n 1 2 an 3400. year = all digits!) ? 1.1.2 The following is the syntax for this MATLAB function. The following is a typical user interaction with this script.7004 100.10 n 0 n1 854535. 1 <= day <= 31.4 635.571 n 3 3.028 n 1 2 an 0.684 n 4 1.
These calculations are based on the algorithm described in Chapter 30 of Astronomical Algorithms by Jean Meeus.06 Orbital Eccentricity 0. Each orbital element is represented by a cubic polynomial of the form a0 a1T a2T 2 a3T 3 where the fundamental time argument T is given by Page 78 .05 0.Celestial Computing with MATLAB ? . Orbital Eccentricity of the Moon 0.04 0.03 0.08 0.07 0.1 please select the orbital element to plot <1> <2> <3> <4> <5> <6> <7> <8> <9> ? 2 semimajor axis eccentricity orbital inclination argument of perigee right ascension of the ascending node true anomaly apogee radius perigee radius geocentric distance The following is the graphics display for this example.m – mean ecliptic and equinox of data planetary ephemeredes This MATLAB calculates the position and velocity vectors of the planets with respect to the mean ecliptic and equinox of date.02 01/01/99 04/01/99 07/01/99 10/01/99 01/01/00 Calendar Date planet1.
etc.) jdate = Julian date % output % % r = heliocentric position vector (kilometers) v = heliocentric velocity vector (kilometers/second) planet2. 2 = venus. v] = planet1(ip. v] = planet2(ip. 2 = venus. 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 a0 a1T a2T 2 a3T 3 where the fundamental time argument T is given by T JED 2451545 36525 In this expression JED is the Julian ephemeris date. jdate) % planetary ephemeris % input % % ip = planet index (1 = mercury.) jdate = Julian date % output Page 79 .m – mean ecliptic and equinox of J2000 planetary ephemerides This MATLAB calculates the position and velocity vectors of the planets with respect to the mean ecliptic and equinox of J2000. etc. The syntax of this MATLAB function is function [r. jdate) % planetary ephemeris % input % % ip = planet index (1 = mercury. The syntax of this MATLAB function is function [r.Celestial Computing with MATLAB T JED 2451545 36525 In this expression JED is the Julian ephemeris date.
The script is called demosen. 3) = transformation matrix A MATLAB script that demonstrates how to use this function is included in the Celestial Computing with MATLAB software suite.Celestial Computing with MATLAB % % r = heliocentric position vector (kilometers) v = heliocentric velocity vector (kilometers/second) seleno.8 of the classic text Methods of Orbit Determination. Page 80 . The transformation is based on the algorithms given in Section 4.m – selenographic coordinate transformation 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 syntax of this MATLAB function is function a = seleno(jd. it) % transformation matrix from eci mean of date to % selenographic mean of date or true of date % input % % % % % jd = julian date it = transformation flag = 0 transform to mean selenographic <> 0 transform to true selenographic (include physical librations) % output % a(3.m and it graphically displays the topocentric coordinates of the Sun relative to a selenographic location on the Moon.
4665 36000. gast.Celestial Computing with MATLAB 16.57 cos 2 L 0.001813T 3 The nutations in obliquity and longitude involve the following three trigonometric arguments (in degrees): L 280. Apparent Greenwich Sidereal Time This section describes three MATLAB functions that can be used to calculate apparent Greenwich sidereal time.000387933T 2 T 3 / 38710000 where T ( JD 2451545) / 36525 and JD is the Julian date on the UT1 time scale.770053608T 0.m – low precision This function calculates the apparent Greenwich sidereal time using the first few terms of the IAU 1980 nutation algorithm. Page 81 .448 46.136261T The calculation of the nutations use the following two equations: 17. The Greenwich apparent sidereal time is given by the expression m cos m where m is the Greenwich mean sidereal time.32sin 2 L 0.09 cos 2 where these corrections are in units of arc seconds.00059T 2 0.23sin 2 L 0.46061837 36000.21sin 2 9.8813T 125. is the nutation in longitude.20sin 1.10 cos 2 L 0.7698T L 218. m is the mean obliquity of the ecliptic and is the nutation in obliquity.20cos 0. The mean obliquity of the ecliptic is determined from m 2302621.3165 481267.8150T 0.04452 1934. The Greenwich mean sidereal time is calculated using the expression m 100.
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. Please note that the Julian date can be passed to this routine in a highorder and loworder part. The syntax of this MATLAB function is as follows: function gst = gast (jdate) % Greenwich apparent sidereal time % input % jdate = Julian date % output % % gst = Greenwich apparent sidereal time (radians) (0 <= gst <= 2 pi) gast1. This function was ported to MATLAB using the Fortran version of the NOVAS source code that was developed at the USNO.m – full precision This function calculates the mean or apparent Greenwich sidereal time. Page 82 . the obliquity in longitude and obliquity are determined using the nutation function which implements the full IAU 1980 nutation algorithm. In the input argument list k determines the type of Greenwich sidereal time calculation. For the apparent sidereal time calculation.
l . Page 83 .m – DE405 nutations This function calculates the mean or apparent Greenwich sidereal time. the obliquity in longitude and obliquity are determined by reading the nutation values contained on a JPL DE405 binary ephemeris file named jpleph. k) % this function computes the greenwich sidereal time % (either mean or apparent) at julian date tjdh + tjdl % input % % % % % % % % k tjdh = julian date. and set tjdl to be the fractional part = time selection code set k=0 for greenwich mean sidereal time set k=1 for greenwich apparent sidereal time % output % gst = greenwich (mean or apparent) sidereal time in hours gast2. loworder part julian date may be split at any point. Please note that the Julian date can be passed to this routine in a highorder and loworder part.Celestial Computing with MATLAB For this numerical method. highorder part tjdl = julian date. D and are fundamental arguments. In the input argument list k determines the type of Greenwich sidereal time calculation. the nutation in longitude is determined from Si sin Ai i 1 n and the nutation in obliquity is determined from Ci cos Ai i 1 n where Ai ai l bi l ci F d i D ei and l . 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. but for highest precision. F . tjdl. set tjdh to be the integral part of the julian date. For the apparent sidereal time calculation. The syntax of this MATLAB function is as follows: function gst = gast1 (tjdh.
but for highest precision. et al. k) % this function computes the greenwich sidereal time % (either mean or apparent) at julian date tjdh + tjdl % this version reads the nutation values from jpleph % reference % aoki. loworder part julian date may be split at any point. 359361 % input % % % % % % % % k tjdh = julian date. tjdl. set tjdh to be the integral part of the julian date. and set tjdl to be the fractional part = time selection code set k = 0 for greenwich mean sidereal time set k = 1 for greenwich apparent sidereal time % output % gst = greenwich (mean or apparent) sidereal time in hours Page 84 .Celestial Computing with MATLAB The syntax of this MATLAB function is as follows: function gst = gast2 (tjdh. (1982) astronomy and astropysics 105. highorder part tjdl = julian date.
8150T 0.0 / 36525 and JD is the Julian Date on the UT1 time scale. l .Celestial Computing with MATLAB 17. IAU 1980 Nutation in Longitude and Obliquity This MATLAB function (nutation. F . The nutation matrix defined by cos N sin cos sin sin sin cos 0 cos cos cos 0 sin sin 0 cos sin cos 0 cos sin 0 sin sin 0 cos cos cos 0 sin cos 0 cos sin sin 0 cos cos 0 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. Page 85 .001813T 3 where T JD 2451545.00059T 2 0. The nutation matrix can also be expressed as a combination of individual rotations according to N R1 R 3 R1 0 The mean obliquity of the ecliptic is calculated from 0 2302621.448 46. The number of terms in this nutation theory is 106. D and are fundamental arguments.m) calculates the nutation in longitude and obliquity using the coefficients defined by the IAU 1980 nutation theory. the nutation in obliquity is determined from Ci cos Ai i 1 n where Ai ai l bi l ci F d i D ei and l . The nutation in longitude is determined from Si sin Ai i 1 n Likewise.
Celestial Computing with MATLAB If secondorder terms are neglected. deps] = nutation (jdate) % nutation in longitude and obliquity % IAU 1980 version % input % jdate = julian date % output % % dpsi = nutation in longitude (arc seconds) deps = nutation in obliquity (arc seconds) Page 86 . a linearized nutation matrix can be calculated from 1 cos N sin cos 1 sin 1 Finally. mean equinox equatorial rectangular position coordinates can be converted to true equinox coordinates by adding the following corrections to the respective components: rx ry cos rz sin ry rx cos rz rz rx sin ry The syntax of this MATLAB function is as follows: function [dpsi.
to a position vector at epoch 2.42665 0.018203t 3 a 2004.017998t 3 za 2306. H. Lieske.Celestial Computing with MATLAB 18.041833t 3 where the unit of these angular arguments is arc seconds and the time arguments are T JED1 2451545 / 36525 t JED1 JED2 / 36525 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. r2 . According to J.000139T 2 t 0.2181 1. Naval Observatory. the fundamental precession matrix is defined by cos za cos a cos a sin za sin a P sin za cos a cos a cos za sin a sin a cos a cos za cos a sin a sin za cos a sin za cos a sin a cos za cos a sin a sin a cos za sin a sin za sin a cos a The precession transformation of a position vector at epoch 1. 282284 (1979). is determined from r r 2x 1x r2 r2 y P r1 P r1y r2z r1z The precession angles are given by a 2306.000217T 2 t 0. “Precession Matrix Based on IAU (1976) System of Astronomical Constants”. Precession Transformation This MATLAB function (precess.39656T 0.85330T 0.m) precesses equatorial rectangular coordinates from one epoch to another. 73.39656T 0.000344T t 2 0. 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. Page 87 . The coordinates are referred to the mean equator and equinox of the two respective epochs.3109 0. r1 .000139T 2 t 1.30188 0.09468 0.S.000217T t 2 0. Astronomy and Astrophysics.000066T t 2 0.2181 1.
Celestial Computing with MATLAB
The syntax of this MATLAB function is as follows:
function pos2 = precess (tjd1, pos1, tjd2) % % % % % % this function precesses equatorial rectangular coordinates from one epoch to another. the coordinates are referred to the mean equator and equinox of the two respective epochs. see pages 3034 of the explanatory supplement to the ae, lieske, et al. (1977) astronomy and astrophysics 58, 116, and lieske (1979) astronomy and astrophysics 73, 282284.
% input % % % % % tjd1 = tdb julian date of first epoch pos1 = position vector, geocentric equatorial rectangular coordinates, referred to mean equator and equinox of first epoch tjd2 = tdb julian date of second epoch
% output % % % pos2 = position vector, geocentric equatorial rectangular coordinates, referred to mean equator and equinox of second epoch
Page 88
Celestial Computing with MATLAB
19. Kepler’s Equation
This section describes three MATLAB functions that can be used to solve the elliptic form of Kepler’s equation given by M E e sin E 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.
kepler1.m – Danby’s method
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) 95107, 317328 and 40 (1987) 303312. 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
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 where is the convergence tolerance. This tolerance is hardwired in the software to =1.0e10. Finally, the true anomaly can be calculated with the following two equations sin 1 e 2 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 e 2 1 sinh 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
Page 90
The elliptic orbit initial guess for this method is given by the expression E0 M e 3s 4 s 3 where s s1 ds 2 5 0.m – Danby’s method with Mikkola’s initial guess This function solves the elliptic and hyperbolic form of Kepler’s equation using Danby’s method and Mikkola’s initial guess. 40 (1987) 329334. ecc) % solve Kepler's equation for circular. For hyperbolic orbits this method uses the following for the correction to s Page 91 . Celestial Mechanics. % elliptic and hyperbolic orbits % Danby's method % input % % manom = mean anomaly (radians) ecc = orbital eccentricity (nondimensional) % output % % eanom = eccentric anomaly (radians) tanom = true anomaly (radians) kepler2.078s1 ds 1 e z sign 2 2 s1 z 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. Additional information about this initial guess can be found in “A Cubic Approximation For Kepler’s Equation”.Celestial Computing with MATLAB function [eanom. tanom] = kepler1 (manom. This method uses a cubic approximation of Kepler's equation for the initial guess.
ecc) % solve Kepler's equation for circular.071s 5 e 1 0. Celestial Mechanics. The syntax of this MATLAB function is function [eanom.45s 2 1 4 s 2 and the following initial guess for the hyperbolic anomaly: H 0 3log s 1 s 2 The syntax for this MATLAB function is function [eanom.Celestial Computing with MATLAB ds 0. % elliptic and hyperbolic orbits % Danby's method with Mikkola's initial guess % input % % manom = mean anomaly (radians) ecc = orbital eccentricity (nondimensional) % output % % eanom = eccentric anomaly (radians) tanom = true anomaly (radians) kepler3. and only two iterations when solving Kepler’s equation.m – Gooding’s two iteration method This MATLAB function solves the elliptic form of Kepler’s equation using Gooding’s two iteration method. tanom] = kepler3 (manom. This algorithm always performs two. tanom] = kepler2 (manom. 38 (1986) 307334. ecc) % solve Kepler's equation for elliptic orbits % Gooding's two iteration method % input % % manom = mean anomaly (radians) ecc = orbital eccentricity (nondimensional) % output % % eanom = eccentric anomaly (radians) tanom = true anomaly (radians) Page 92 . Additional information about this technique can be found in “Procedures For Solving Kepler’s Equation”.
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. The kepler4 function iteratively solves for U.Celestial Computing with MATLAB kepler4. The form of Kepler’s equation solved by this function is E t e sin E t a3 t t0 where E eccentric anomaly e a t t0 orbital eccentricity gravitational constant of the Sun semimajor axis time time of perihelion passage The relationship between semimajor axis a and perihelion radius q is as follows: a By introducing the variable U Kepler’s equation is now given by 3ec3 E E 1 e q 1 e 1 U U 3 6ec3 E t t0 3 2q3 where c3 E E e sin E E 3 . The heliocentric distance is determined from the expression 2c r q 1 2 U 2 6c3 Page 93 .m – parabolic and nearparabolic orbits This MATLAB function solves Kepler’s equation for heliocentric parabolic and nearparabolic orbits.
They are named after the German astronomer Karl Stumpff and defined by the series 1 x k cn x k 0 2k n ! k k 0.1. 2. 2. 1 ck x k! k 0.1. For x real and x 0 . the first few terms are given by the following expressions: c0 x 2 cos x sin x x 1 cos x c2 x 2 x c1 x 2 c0 x 2 cosh x c1 x 2 sinh x x cosh x 1 c2 x 2 x The Stumpff functions also satisfy the recursion relationship defined by xck 2 x 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: Page 94 .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 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.
Page 95 . ecc) % Kepler's equation for heliocentric % parabolic and nearparabolic orbits % input % % % t = time relative to perihelion passage (days) q = perihelion radius (AU) ecc = orbital eccentricity (nondimensional) % output % % r = heliocentric distance (AU) tanom = true anomaly (radians) Please note that the time relative to perihelion passage is in days and the perihelion radius is in astronomical units.Celestial Computing with MATLAB c0 x 1 xc2 c1 x 1 xc3 The following is the syntax for this MATLAB function. tanom] = kepler4(t. function [r. q.
Celestial Computing with MATLAB 20. For programming flexibility the input and output arguments for each routine are identical. Twobody Orbital Motion The following three MATLAB functions can be used to quickly and efficiently propagate two body or “unperturbed” orbits. 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 s0 1 2 2! 3! 2 4 3 6 4! 5! 6! 6! 7! 8! s1 s2 s3 3 2 5 3 7 2 2! 4 4! 2 6 3 8 2 7 7! 3 3! 5 5! 3 9 9! Page 96 . This change of variables is defined by 1/ r where r is the distance of the spacecraft or celestial body. hyperbolic and parabolic motion. Goodyear’s method uses a change of variables that allows one to use a single set of equations to predict elliptic. twobody1.m – Goodyear’s method This function is a MATLAB implementation of Goodyear’s two body propagation algorithm.
vf] = twobody1 (tau. This variable should also be placed in a global statement at the beginning of the main script that calls this function. The following statement in the main MATLAB script will accomplish this: tbcoef = 1. The position magnitude at the final time is given by r r0 s0 0 s2 s3 The f and g functions and their derivatives are calculated with the four equations given by f 1 s2 r0 g t t0 s3 g 1 s f 1 rr0 s2 r Finally. vi) Page 97 . ri. The syntax of this MATLAB function is function [rf.Celestial Computing with MATLAB can be obtained by solving the next equation t t0 r0 s1 0 s2 s3 for the value of which satisfies all these equations. 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 r gr 0 0 The twobody gravity acceleration vector at the final time is given by t r r r 3 This function requires initialization the first time it is called.
This algorithm uses a combination of universal variables and continued fractions to propagate twobody orbits. 35 (1985) 129144. The algorithm begins by computing an initial guess for s according to x s2 where Page 98 . This function is valid for elliptic and hyperbolic orbits.Celestial Computing with MATLAB % solve the two body initial value problem % Goodyear's method % input % % % tau = propagation time interval (seconds) ri = initial eci position vector (kilometers) vi = initial eci velocity vector (km/sec) % output % % rf = final eci position vector (kilometers) vf = final eci velocity vector (km/sec) twobody2.m – Stumpff/Danby method This function is a MATLAB implementation of the Stumpff/Danby two body propagation algorithm. vi) % solution of the two body initial value problem % Shepperd's method % input % % % tau = propagation time interval (seconds) ri = initial eci position vector (kilometers) vi = initial eci velocity vector (km/sec) % output % % rf = final eci position vector (kilometers) vf = final eci velocity vector (km/sec) twobody3.m – Sheppard’s method This function is a MATLAB implementation of Stanley Shepperd’s two body propagation algorithm. The derivation of this algorithm is described in “Universal Keplerian State Transition Matrix”. It is based on a universal variable technique and Stumpff functions. ri. The syntax of this MATLAB function is function [rf. The derivation of this algorithm can be found in Professor Danby’s classic text Fundamentals of Celestial Mechanics. Celestial Mechanics. vf] = twobody2 (tau.
for x real and x 0 c0 x 2 cos x sin x x 1 cos x c2 x 2 x c0 x 2 cosh x sinh x x cosh x 1 c2 x 2 x c1 x 2 c1 x 2 The Stumpff functions also satisfy the recursion relationship defined by xck 2 x For x 0 .1. 2. They are named after the German astronomer Karl Stumpff and are defined by the series 1 x k cn x k 0 2k n ! k k 0.1. 2.Celestial Computing with MATLAB r0 position vector at initial time t0 v 0 velocity vector at initial time t0 r0 r0 r02x r02y r02z 2 2 2 v0 v 0 v0 x v0 y v0z 2 2 v0 r0 This algorithm uses a universal variable form of Kepler’s equation defined by f s r0 sc1 s 2 r0 r0 s 2c2 s 2 s 3c3 s 2 t t0 0 The first three derivatives of this form of Kepler’s equation are given by f s r0c0 s 2 r0 r0 sc1 s 2 s 2c2 s 2 f s r0 sc1 s 2 r0 r0c0 s 2 f s r0 c0 s 2 r0 r0 sc1 s 2 The c functions used in these equations are called Stumpff functions. Page 99 . 1 ck x k! k 0.
vi) % solve the two body initial value problem % Danby/Stumpff method % input % % % tau = propagation time interval (seconds) ri = initial eci position vector (kilometers) vi = initial eci velocity vector (km/sec) % output % % rf = final eci position vector (kilometers) vf = final eci velocity vector (km/sec) Page 100 . ri. vf] = twobody3 (tau.Celestial Computing with MATLAB cn x 1 n! It is most efficient to compute c2 and c3 by series. 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 The syntax of this MATLAB function is function [rf. 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 syntax of this MATLAB function is function [cdstr. day.m – julian date to calendar date This MATLAB function converts a Julian date to its corresponding calendar date. The syntax of this MATLAB function is function [month.m – julian date to calendar date and universal time strings This function converts a Julian date to its equivalent calendar date and universal time strings. Be sure to pass this routine all digits of the calendar year. Time and Date Functions This section describes several MATLAB functions that can be used for time and date conversions and manipulations. day.12] day = calendar day [1 . The syntax of this MATLAB function is function jdate = julian (month.31] year = calendar year [yyyy] % Output % jdate = Julian date gdate.m – calendar date to Julian date This MATLAB function converts a calendar date to its corresponding Julian date. year) % Julian date subroutine % Input % % % month = calendar month [1 . year] = gdate (jdate) % convert Julian date to Gregorian (calendar) date % input % jdate = Julian date % output % % % month = calendar month [1 . julian. utstr] = jd2str(jdate) Page 101 .Celestial Computing with MATLAB 21.12] day = calendar day [1 .31] year = calendar year [yyyy] jd2str.
The following statement in the main MATLAB script will accomplish this: itime = 1. The syntax of this MATLAB function is function jdtdb = tdt2tdb(jdtdt) % convert terrestrial dynamic time julian Page 102 .m – convert TDT Julian date to TDB Julian date 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. The syntax of this MATLAB function is function jdtdt = utc2tdt(jdutc) % convert utc julian date to tdt julian date % input % jdutc = universal time julian date % output % jdtdt = terrestrial dynamic time julian date tdt2tdb. This difference is periodic with an average of zero. It is valid between January 1.m – convert UTC Julian date to TDT Julian date 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. The difference between these two time scales can be as much as 1. TDB is the fundamental time argument for the Jet Propulsion Laboratory (JPL) and Bureau of Longitudes (BDL) ephemerides. 1940 and the near future. This function requires initialization the first time it is called.6 milliseconds. This variable should also be placed in a global statement at the beginning of the main script that calls this function.Celestial Computing with MATLAB % convert Julian date to string equivalent % calendar date and universal time % input % jdate = Julian date % output % % cdstr = calendar date string utstr = universal time string utc2tdt.
m. and string representation. hmsstr] = hrs2hms (hrs) % convert decimal hours to hours.m – convert hours function This function can be used to convert a floating point argument in hours into its equivalent degrees. minutes. % minutes. The syntax of this MATLAB function is function [h. s. seconds and equivalent string % input % dd = angle in hours % output % % % % h m s hmsstr = = = = integer hours integer minutes seconds string equivalent of input Page 103 . seconds.Celestial Computing with MATLAB % date to barycentric dynamic time julian date % input % jdtdt = tdt julian date % output % jdtdb = tdb julian date hrs2hms.
Numerical Methods and Utility Routines This section describes several fundamental MATLAB functions that can be used to create custom applications. The syntax of this MATLAB function is function y = modulo (x) % modulo 2 pi function % input % x = argument (radians) % output % y = x modulo 2 pi uvector. 0 =< c <= 2 * pi) modulo. The syntax of this MATLAB function is function vhat = uvector(x) % unit vector Page 104 . b) % four quadrant inverse tangent % input % % a = sine of angle b = cosine of angle % output % y = angle (radians.m – modulo 2 pi This function will modulo an angle (in radians) between 0 and 2 .Celestial Computing with MATLAB 22. The syntax of this MATLAB function is function y = atan3 (a.m – four quadrant inverse tangent This function calculates the four quadrant inverse tangent. TRIGONOMETRY AND VECTOR ROUTINES atan3.m – unit vector This function calculates a unit vector from a user provided three component vector.
a f This function requires initialization the first time it is called. This variable should also be placed in a global statement at the beginning of the main script that calls this function. ti. tf. nonlinear vector differential equations of the form y f y . nonlinear vector differential equations of the form y f y. Page 105 . The following statement in the main MATLAB script will accomplish this: rkcoef = 1. It can be used to solve systems of first order.m – RungeKuttaFehlberg 4(5) method for firstorder systems This function is a MATLAB implementation of the 4(5) version of the RungeKuttaFehlberg algorithm. h. It can be used to solve systems of first order. t .Celestial Computing with MATLAB % input % x = 3component input vector % output % vhat = 3component unit vector DIFFERENTIAL EQUATIONS rkf45. the function will set this value to 0. After the first call. t .m – RungeKuttaFehlberg 7(8) method for firstorder systems This function is a MATLAB implementation of the 7(8) version of the RungeKuttaFehlberg algorithm. y) % solution of first order system of differential equations % RungeKuttaFehlberg 4(5) % fourthorder solution with fifthorder error control % input % % % % % % neq ti tf h tetol y = = = = = = number of equations in system initial simulation time final simulation time guess for step size truncation error tolerance initial integration vector % output % xout = final integration vector rkf78. tetol. neq. The syntax of this MATLAB function is function xout = rkf45 (deq.
ytbi(i) = ytrue(i). the following code performs the rectification required for Encke’s method. x = xwrk. a successful integration step has been completed and additional processing such as graphics or other calculations can be performed here. neq. h. The following statement in the main MATLAB script will accomplish this: rkcoef = 1. else % rectify and reinitialize ytbf = twobody4(dt. tetol. for i = 1:1:6 ytrue(i) = ytbf(i) + x(i). etc. end The following is the syntax for this MATLAB function. end tsaved = ti. at this point % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end When the processing reaches the else statement. Near the end of this function is the following code: if (xerr > 1) % reject current step ti = twrk. x) Page 106 .Celestial Computing with MATLAB This function requires initialization the first time it is called. else %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % accept current step % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % perform graphics. x(i) = 0. ti.7 * dt * (1 / xerr) ^ (1 / 8). if (xerr > 1) % reject current step ti = twrk. function xout = rkf78 (deq. 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. ytbi). x = xwrk. For example. additional % % calculations. the function will set this value to 0. % compute new step size dt = 0. tf.
m – Nystrom fourthorder method for secondorder systems This function is a MATLAB implementation of a fourthorder Nystrom algorithm. x. It can be x used to solve systems of second order differential equations of the form f x. vs) % solve a system of second order differential equations % fourth order Nystrom method (fixed step size) % input % % % % % % % % deq = function name of systems of differential equations n = number of equations in userdefined system of differential equations tp = current simulation time dt = integration step size rs = position vector at initial time vs = velocity vector at initial time % output % % rf = position vector at time = tp + dt vf = velocity vector at time = tp + dt Page 107 . tp. vf] = nym4(deq.Celestial Computing with MATLAB % solve first order system of differential equations % RungeKuttaFehlberg 7(8) method % input % % % % % % % % deq = name of function which defines the system of differential equations neq = number of differential equations ti = initial simulation time tf = final simulation time h = initial guess for integration step size tetol = truncation error tolerance (nondimensional) x = integration vector at time = ti % output % xout = integration vector at time = tf nym4. The following statement in the main MATLAB script will accomplish this: nycoef = 1. n. t . The syntax of this MATLAB function is function [rf. rs. This variable should also be placed in a global statement at the beginning of the main script that calls this function. b g This function requires initialization the first time it is called. dt.
It includes the pointmass gravity perturbations due to Venus. % Mars.m – firstorder heliocentric equations of orbital motion This MATLAB function evaluates the firstorder form of the heliocentric equations of orbital motion. t s r pi 3 3 3 dt rs b i 1 rpi r p b i where s gravitational constant of the Sun p gravitational constant of planet i i rp position vector from the Sun to planet rs b position vector from the Sun to the body rp b position vector from the planet to the body These position vectors are related according to rsb rp rpb Page 108 . y) % first order form of the heliocentric % equations of motion % includes point mass gravity % perturbations of Venus.Celestial Computing with MATLAB ceqm1. Jupiter and Saturn. Earth. The fundamental coordinate system used in this algorithm is the trueofdate ecliptic and equinox. Earth. Jupiter and Saturn % input % % time = current simulation time y = current state vector % output % yddot = equations of motion The secondorder heliocentric equations of motion of a satellite or celestial body subject to the pointmass gravitational attraction of the Sun and planets are given by 9 rpi rs b d 2r r p b i 2 r. Mars. The syntax of this MATLAB function is function yddot = ceqm1 (time.
y) % modified equinoctial equations of motion % input % % % % % % y(1) y(2) y(3) y(4) y(5) y(6) = = = = = = semilatus rectum of orbit (kilometers) f equinoctial element g equinoctial element h equinoctial element k equinoctial element true longitude (radians) % output % % ydot = first time derivatives of modified equinoctial elements The perturbation vector used in these calculations is computed in a MATLAB function called ceqm2.Celestial Computing with MATLAB meeeqm. r. v) % eci perturbation vector % support function for cowell4.m – modified equinoctial equations of motion This MATLAB function evaluates the modified equinoctial orbital elements form of the equations of heliocentric orbital motion.m. The syntax of this function is as follows: function ywrk = ceqm2 (t.m % includes perturbations due to: % % % % nonspherical earth gravity aerodynamic drag (us 76 model) solar radiation pressure sun and moon % input % % % t = current simulation time r = current eci position vector v = current eci velocity vector % output % ywrk = eci perturbation vector The equations of orbital motion expressed in terms of modified equinoctial orbital elements are as follows: Page 109 . The syntax for this MATLAB function is function ydot = meeeqm(t.
The basic idea is to find the endpoints of an interval x1 and x2 such that f x1 f x2 0 . 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.25 and the rectification interval is 300 seconds. tangential and orbit normal directions. n are external perturbations in the radial.m – bracket a single root of a nonlinear function This function can be used to bracket a single root of a single nonlinear equation of the form y f x . respectively. 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 increases the size of each step geometrically and the rectification interval monitors the length of the current bracketing interval. t . The process starts at the bottom left. The user must supply this function with an initial guess for x1 and x2 . The acceleration factor for this example is 0. which Page 110 . It uses a combination of geometric acceleration and rectification to bracket roots. labeled minimum.Celestial Computing with MATLAB dp 2 p dt w p p t df f dt t p gn r sin L w 1 cos L f w h sin L k cos L w t p gn r cos L w 1 sin L g w h sin L k cos L w g dg dt dh h dt dk k dt p s2n cos L 2w p s2n sin L 2w 2 dL p w 1 p h sin L k cos L L n dt p w where r . ROOTFINDING AND OPTIMIZATION broot.
The xaxis is the number of steps taken in the search for the bracketing interval and the yaxis is the elapsed simulation time. factor. The syntax of this MATLAB function is Page 111 . labeled root on this plot.m – solve for a single root of a nonlinear function This function uses Brent’s method to find a single root of a single nonlinear equation of the form y f x . x1in.247 0. The size of each step increases geometrically until the length of the current step reaches the value of the rectification interval.246 0. the user should ensure that a root is bracketed f x1 f x2 0 before calling this routine. Eventually.245 0. 0.248 Simulation Time (days) rectification 0. and the function will return the endpoints x1 and x2 of this bracketing interval. Derivatives are not required for this algorithm. dxmax) % bracket a single root of a nonlinear equation % input % % % % % f x1in x2in factor dxmax = = = = = objective function coded as y = f(x) initial guess for first bracketing x value initial guess for second bracketing x value acceleration factor (nondimensional) rectification interval % output % % x1out = final value for first bracketing x value x2out = final value for second bracketing x value brent.25 root 0.249 0. However.Celestial Computing with MATLAB is the time of the function minimum for this example. x2in.243 minimum 0 5 10 15 20 25 30 Number of Steps The syntax of this MATLAB function is function [x1out. the step size is reset and the process begins again. the process will bracket the root. x2out] = broot (f. At that point. labeled rectification on the plot.244 0.
x1. rtol) % solve for a single real root of a nonlinear equation % Brent's method % input % % % % f x1 x2 rtol = = = = objective function coded as y = f(x) lower bound of search interval upper bound of search interval algorithm convergence criterion % output % % xroot froot = real root of f(x) = 0 = function value at f(x) = 0 minima. fmin] = minima (f. a. The syntax of this MATLAB function is function oevent1 (objfunc. b.m – find minimization/root finding orbital event This MATLAB function is a combined onedimensional minimization and rootfinding algorithm. and then calculates the corresponding “reverse” and “forward” root.Celestial Computing with MATLAB function [xroot. The syntax of this MATLAB function is function [xmin. tf. dt. tolm) % onedimensional minimization subroutine % Brent's method % input % % % % f a b tolm = = = = objective function coded as y = f(x) initial x search value final x search value convergence criterion % output % % xmin = minimum x value fmin = minimum function value oevent1. prtfunc. froot] = brent (f. It first finds minima or maxima within a userdefined search interval. x2.m – onedimensional minimization This function uses Brent’s method to find a single minimum or maximum of a single userdefined nonlinear “objective” function. ti. dtsml) % predict minimization/rootfinding orbital events % input Page 112 .
Celestial Computing with MATLAB % % % % % % % objfunc prtfunc ti tf dt dtsml = = = = = = objective function display results function initial simulation time final simulation time step size used for bounding minima small step size used to determine whether the function is increasing or decreasing ATMOSPHERIC REFRACTION refract. p. The syntax of this MATLAB function is function refr = refract1 (height. it can be used for planning observations or telescope pointing. 144. 255259. The syntax of this MATLAB function is function elev2 = refract(elev1) % refraction correction % input % elev1 = uncorrected angle (radians) % output % elev2 = angle corrected for refraction (radians) refract1.m – NOVAS refraction correction function This MATLAB function determines the effect of atmospheric refraction using the algorithm included in the NOVAS software suite from the Naval Observatory. this version computes approximate refraction for optical wavelengths. journal of navigation (royal institute) 35. height = height of observer in meters (in) Page 113 .3 tan E E 5.02 E 10.m – refraction correction function This MATLAB function corrects a topocentric elevation angle for atmospheric refraction. basic algorithm is described in the explanatory supplement to the astronomical almanac. and is an adaptation of a formula in bennett (1982). The correction to be added to the “true” or calculated topocentric elevation angle is as follows: 1.11 where E is the true topocentric elevation angle in degrees. but should not be used for the reduction of precise observations. zdobs) % % % % % % % % % this subroutine computes atmospheric refraction in zenith distance.
Berman and S. The syntax of this MATLAB function is function elev2 = refract2(press. The syntax of this MATLAB function is function oeprint1(oev) % print six classical orbital elements % (orbital period in days) % input % % % % % % % % % % % oev(1) oev(2) oev(3) oev(4) oev(5) oev(6) = semimajor axis (kilometers) = orbital eccentricity (nondimensional) (0 <= eccentricity < 1) = orbital inclination (radians) (0 <= inclination <= pi) = argument of periapsis (radians) (0 <= argument of periapsis <= 2 pi) = right ascension of ascending node (radians) (0 <= raan <= 2 pi) = true anomaly (radians) (0 <= true anomaly <= 2 pi) Page 114 .m – formatted classical orbital elements screen display This function prints a formatted display of the six classical orbital elements with the orbital period displayed in days. Rockwell.Celestial Computing with MATLAB % % zdobs refr = observed zenith distance in degrees (in) = atmospheric refraction in degrees (out) refract2. There is also a version of this function called oeprint2. T. elev1) % optical refraction correction % input % % % press = atmospheric pressure (mm of Hg) temp = atmospheric temperature (degrees C) elev1 = uncorrected elevation angle (radians) % output % % elev2 = elevation angle corrected for refraction (radians) UTILITY ROUTINES oeprint1. The code is based on the numerical method described in “A New Angular Tropospheric Refraction Model”.m that prints the semimajor axis in astronomical units.m – refraction correction function including temperature/pressure effects This MATLAB function determines the effect of atmospheric refraction using an algorithm that includes the effects of ambient pressure and temperature. temp. by A. JPL Deep Space Network Progress Report 4224. L.
12345) produces the following screen output: +22d 07m 24.s.Celestial Computing with MATLAB svprint. the command [d. s.m. and string representation.m – formatted state vector screen display This function prints a formatted display of the components and scalar magnitudes of a state vector (position and velocity vectors and magnitudes).degstr]=deg2dms(22.42s The syntax of this MATLAB function is function [d.m – request calendar date This function interactively requests the calendar date. For example. Page 115 . dmsstr] = deg2dms (dd) % convert decimal degrees to degrees. seconds and equivalent string % input % dd = angle in decimal degrees % output % % % % d m s dmsstr = = = = integer degrees integer minutes seconds string equivalent of input INTERACTIVE REQUEST OF PROGRAM INPUTS getdate. m.m – convert degrees function This function can be used to convert a floating point argument in degrees into its equivalent degrees. Please note that all digits of the calendar year are required. minutes. The syntax of this MATLAB function is function svprint(r. v) % print position and velocity vectors and magnitudes % input % % r = position vector (kilometers) v = velocity vector (kilometers/second) deg2dms. seconds. % minutes.
0 <= seconds <= 60) (east longitude is positive. The syntax of this MATLAB function is function [obslat. Please note the valid range of inputs. 0 <= minutes <= 60. y] = getdate % interactive request and input of calendar date % output % % % m = calendar month d = calendar day y = calendar year The following is the screen display for this function. year = all digits!) ? The calendar date should be input with individual elements separated by commas. south latitude is negative) ? 40. d. Please note that geodetic latitude and longitude are returned in the units of radians. negative below sea level) ? 100 Page 116 .45 please input the altitude of the ground site (meters) (positive above sea level. obslong.Celestial Computing with MATLAB The syntax of this MATLAB function is function [m.10 please input the geographic longitude of the ground site (0 <= degrees <= 360.m – request observer coordinates This function interactively requests the geodetic coordinates of a ground site.35. obsalt] = getobs % interactive request of ground site coordinates % output % % % obslat = geographic latitude (radians) obslong = geographic longitude (radians) obsalt = geodetic altitude (kilometers) The following is a typical user interaction with this function. North latitudes are positive and south latitudes are negative. 0 <= seconds <= 60) (north latitude is positive. please input the geographic latitude of the ground site (90 <= degrees <= +90. getobs. East longitude is positive and west longitude is negative. 0 <= minutes <= 60. west longitude is negative) ? 105.30. please input the calendar date (1 <= month <= 12. 1 <= day <= 31. Please note the sign conventions and range of valid inputs.
utsec] = gettime % interactive request and input of universal time % output % % % uthr = universal time (hours) utmin = universal time (minutes) utsec = universal time (seconds) The following is the screen prompt displayed by this function. The user can control which orbital elements are requested by setting the corresponding value of the ioev vector. please input the universal time (0 <= hours <= 24. 0 <= seconds <= 60) ? Page 117 .m – request universal time This function interactively requests the universal time in hours.1. If invalid data is input the function will redisplay this request. Please note that all angular elements are returned from this function in the units of radians. the following statement will request all six orbital elements: oev = getoe([1. utmin. For example. 0 <= minutes <= 60.m – request classical orbital elements This function interactively requests six classical orbital elements. The syntax of this MATLAB function is function [uthr.1]) If the orbital eccentricity input by the user is 0.1. this function will bypass the prompt for argument of periapsis (if requested via ioev) and set its value to 0.1. minutes and seconds.1. The syntax of this MATLAB function is function oev = getoe(ioev) % interactive request of classical orbital elements % NOTE: all angular elements are returned in radians % input % ioev = request array (1 = yes. Please note the range of valid inputs.Celestial Computing with MATLAB getoe. 0 = no) % output % % % % % % oev(1) oev(2) oev(3) oev(4) oev(5) oev(6) = = = = = = semimajor orbital eccentricity orbital inclination argument of perigee right ascension of the ascending node true anomaly gettime.
The following is a typical plot created with this script.m that demonstrates how to interact with both the pltortho and pltrect mapping functions. The Celestial Computing with MATLAB CD ROM contains a script called demoplot. islands = 1. allfeatures = 0.dat. countries = 0. The syntax of this MATLAB function is Page 118 . coastlines = 1. 80 60 40 20 0 −20 −40 −60 −80 −150 −100 −50 0 50 100 150 pltortho. The map coordinates are contained in a file called xyzmap. states = 0. The map features that are plotted by this utility are defined in the code as follows: % define plot features % (set to 1 to activate). lakes = 0.m – MicroWorld Database map files 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 IBMPC compatible computers.Celestial Computing with MATLAB RECTANGULAR AND ORTHOGRAPHIC GRAPHICS demomwdb.m – plot orthographic view of the Earth This MATLAB function will plot an orthographic view of the Earth. rivers = 0.
west longitudes are negative The following is a typical plot created with this function. dlong) % plot orthographic world map % input % % % % % % % % vplat = viewpoint latitude (degrees) (90 <= vplat <= 90) vplong = viewpoint longitude (degrees) (180 <= vplong <= 180) dlat = latitude grid spacing (degrees) (0 <= dlat <= 90) dlong = longitude grid spacing (degrees) (0 <= dlong <= 360) % note % % east longitudes are positive. The viewpoint is 40 degrees north latitude and 105 degrees west longitude.Celestial Computing with MATLAB function pltortho(vplat. vplong. Page 119 . The latitude and longitude grid spacing for this example was 30 degrees. dlat.
Celestial Computing with MATLAB
pltrect.m – plot rectangular map of the Earth
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.
90
60
30
latitude
0
−30
−60
−90 −180
−120
−60
0
60
120
180
longitude
Page 120
Celestial Computing with MATLAB
23. Astronomical Coordinates
This section describes several MATLAB functions that can be used to calculate and convert different types of astronomical coordinates. In the following discussions
h H
right ascension declination ecliptic longitude ecliptic latitude A topocentric azimuth topocentric altitude 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.
rec2pol.m – rectangular to polar coordinate conversion
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 The latitudinal polar coordinate is calculated using the expression given by
tan 1
rx2 ry2 rz
The syntax of this MATLAB function is
function [rmag, lambda, phi] = rec2pol(r) % rectangular to polar coordinate conversion
Page 121
Celestial Computing with MATLAB
% input % r = rectangular position vector
% output % % % % % rmag = vector scalar magnitude lambda = longitudinal polar coordinate (radians) (0 <= lambda <= 2*pi) phi = latitudinal polar coordinate (radians) (pi/2 <= phi <= pi/2)
pol2rec.m – polar to rectangular coordinate conversion
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 The syntax of this MATLAB function is
function r = pol2rec(rmag, lambda, phi) % polar to rectangular coordinate conversion % input % % % % % rmag = vector scalar magnitude lambda = longitudinal polar coordinate (radians) (0 <= lambda <= 2*pi) phi = latitudinal polar coordinate (radians) (pi/2 <= phi <= pi/2)
% output % r = rectangular position vector
ecl2equ.m – ecliptic to equatorial coordinate conversion
The conversion from ecliptic to equatorial coordinates is given by the following two equations: tan 1 sin cos tan sin ,cos
sin 1 sin cos cos sin sin
The syntax of this MATLAB function is
function [rasc, decl] = ecl2equ(lat, lon, obliq) % ecliptic to equatorial coordinate conversion
Page 122
cos sin 1 sin cos cos sin sin The syntax of this MATLAB function is function [lat. rasc.Celestial Computing with MATLAB % input % % % lat = ecliptic latitude (radians) lon = ecliptic longitude (radians) obliq = obliquity of the ecliptic (radians) % output % % rasc = geocentric right ascension (radians) decl = geocentric declination (radians) equ2ecl. obslst.m – equatorial to local horizontal coordinate conversion The conversion from equatorial to local horizontal coordinates is given by the following two expressions: A tan 1 sin H . rasc) % equatorial to local horizontal coordinate conversion % input Page 123 . decl. long] = equ2ecl(decl. elevation] = equ2hor(obslat.m – equatorial to ecliptic coordinate conversion The following two equations convert equatorial coordinates to ecliptic coordinates: tan 1 sin cos tan sin . cos H sin tan cos h sin 1 sin sin cos cos cos H The syntax of this MATLAB function is function [azimuth. obliq) % equatorial to ecliptic coordinate conversion % input % % % rasc = geocentric right ascension (radians) decl = geocentric declination (radians) obliq = obliquity of the ecliptic (radians) % output % % lat = ecliptic latitude (radians) lon = ecliptic longitude (radians) equ2hor.
The orbital inclination i . azimuth. and 0 are the orbital inclination. and longitude of ascending node are the only orbital elements that depend on the position of the equinox. In the equations which follow. i0 . elevation) % local horizontal to equatorial coordinate conversion % input % % % % azimuth elevation obslat obslst = = = = object's topocentric azimuth angle (radians) object's topocentric elevation angle (radians) observer's geodetic latitude (radians) observer's local sidereal time (radians) % output % % decl = object's declination (radians) rasc = object's right ascension (radians) % notes % % (1) azimuth positive clockwise from north (2) elevation positive above the local horizontal oepreces. obslst. 0 . argument of periapsis . longitude of ascending node and argument of periapsis with respect to the initial equinox.m – local horizontal to equatorial coordinate conversion The conversion from local horizontal to equatorial coordinates is as follows: H tan 1 sin A.m – transform angular orbital elements from one equinox to another This MATLAB function can be used to transform angular orbital elements from one equinox to another. Orbital Page 124 .cos A cos tan h cos sin 1 sin sin h cos cosh cos A The syntax of this MATLAB function is function [decl.Celestial Computing with MATLAB % % % % obslat obslst decl rasc = = = = observer's geodetic latitude (radians) observer's local sidereal time (radians) object's declination (radians) object's right ascension (radians) % output % % azimuth = object's topocentric azimuth angle (radians) elevation = object's topocentric elevation angle (radians) % notes % % (1) azimuth positive clockwise from north (2) elevation positive above the local horizontal hor2equ. rasc] = hor2equ(obslat.
eqnx2. It is important to remember that these transformed orbital elements are still valid for the same epoch as the original orbital elements. Lieske. 282284 (1979) by J. The syntax of this MATLAB function is function oev2 = oepreces (eqnx1. A . Astronomy and Astrophysics. this MATLAB function performs a coordinate transformation. The spherical trigonometry relationships among these elements are summarized below: cos i cos i0 cos A sin i0 sin A cos A 0 sin i sin p A A sin i0 sin A 0 sin i cos p A A sin A cos i0 cos A sin i0 cos A 0 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 cos sin i sin i0 cos A cos i0 sin A cos A 0 The argument of periapsis corrected for precession is as follows: 0 In these expressions A . H. and p A are fundamental precessional quantities which are functions of time. They are described in “Precession Matrix Based on IAU (1976) System of Astronomical Constants”. These equinoxes should be passed to this function as strings. 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). In other words.Celestial Computing with MATLAB elements without a subscript are with respect to the final equinox. not an epoch transformation. 73. oev1) % transform angular orbital elements % from one equinox to another equinox % input % eqnx1 = initial equinox % eqnx2 = final equinox % oev1 = orbital elements referred to eqnx1 % oev1(1) = orbital inclination % oev1(2) = longitude of ascending node % oev1(3) = argument of periapsis % output Page 125 .
Celestial Computing with MATLAB % % % % oev2 = orbital oev2(1) oev2(2) oev2(3) elements referred to eqnx2 = orbital inclination = longitude of ascending node = argument of periapsis gsite. rx G1 cos cos ry G2 cos sin rz G2 sin For ECI site coordinates is equal to the local sidereal time. 0 <= angle <= 2*pi) Page 126 . angle) % ground site position vector % input % % % % % % lat = geodetic latitude (radians) (+north. In these equations is the geodetic latitude of the ground site.m – ground site position vector This MATLAB function calculates either the Earthcenteredinertial (ECI) or Earthcenteredfixed (ECF) position vector of a ground site located on an oblate Earth. pi/2 <= lat <= pi/2) alt = geodetic altitude (meters) (+ above sea level.below sea level) angle = local sidereal time or east longitude (radians. and for ECF coordinates is equal to the east longitude of the ground site. south. The geodetic constants G1 and G2 are calculated as follows: G1 G2 where 1 2 f f 2 sin 2 1 2 f f 2 sin 2 req 1 f 2 req h h f Earth flattening factor req Earth equatorial radius geodetic latitude h geodetic altitude The syntax of this MATLAB function is function rsite = gsite (lat. alt. . It is positive in the northern hemisphere and negative in the southern hemisphere.
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 where the geodetic constants c and s are given by 0 c 1 2 f f 2 sin 2 2 req s c 1 f and req is the Earth equatorial radius (6378.257). The geodetic latitude is determined using the following expression: Page 127 .Celestial Computing with MATLAB % output % rsite = ground site position vector (kilometers) geodet1. is the geodetic latitude.series solution This MATLAB function uses a series solution to convert geocentric distance and declination to geodetic altitude and latitude.m – convert geocentric coordinates to geodetic coordinates . and h is the geodetic altitude. In this diagram. is the geocentric declination. r is the geocentric distance. The following diagram illustrates the geometric relationship between geocentric and geodetic coordinates.14 kilometers) and f is the flattening factor for the Earth (1/298.
dec) % geodetic latitude and altitude % series solution % input % % % rmag = geocentric radius (kilometers) dec = geocentric declination (radians) (+north. Bullentin Geodesique.Celestial Computing with MATLAB 1 2 sin 2 1 f 2 4 sin 4 f The geodetic altitude is calculated from 1 cos 2 1 1 ˆ ˆ h r 1 1 cos 4 f 2 f 2 4 16 ˆ ˆ In these equations. south. 1. lat] = geodet1 (rmag. 63 No. is the geocentric distance of the object. The syntax of this MATLAB function is function [alt. Borkowski (“Accurate Algorithms to Transform Geocentric to Geodetic Coordinates”. pi/2 <= dec <= +pi/2) % output % % % alt = geodetic altitude (kilometers) lat = geodetic latitude (radians) (+north. south. h h / req and r / req .m – convert geocentric coordinates to geodetic coordinates – exact solution This MATLAB function uses the exact solution of K. M. 5056) to convert geocentric distance and declination to geodetic altitude and latitude. The calculation steps for this numerical method are as follows: brz a 2 b 2 E ar brz a 2 b2 F ar r rx2 ry2 where a is the equatorial radius of the Earth and b is determined from Page 128 . pi/2 <= lat <= +pi/2) geodet2.
The components of this vector are given by Page 129 .Celestial Computing with MATLAB a b sign rz a f The calculations continue with 4 EF 1 3 Q 2E2 F 2 P D P3 Q 2 v D1/ 2 Q G 1/ 3 1 2 E vE 2 F vG t G 2 2G E The geodetic latitude is determined from the expression arctan a and the geodetic altitude is calculated from 1 t2 2bt h r at cos rz b sin The syntax of this MATLAB function is function [xlat. alt] = geodet2(decl. longitude and altitude to an Earthcenteredfixed (ECF) position vector. 1989) % input % % decl = geocentric declination (radians) rmag = geocentric distance (kilometers) % output % % xlat = geodetic latitude (radians) alt = geodetic altitude (kilometers) geodet3.m – convert geodetic coordinates to ECF position vector This function converts geodetic latitude. rmag) % geocentric to geodetic coordinates % exact solution (Borkowski.
alt) % ecf position vector % input % % % % lat = geodetic (+north.Celestial Computing with MATLAB rgeocentric N h cos cos e N h cos sin e 2 N 1 e h sin req 1 e 2 sin 2 where N 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 The syntax of this MATLAB function is function r = geodet3 (lat.m – convert geodetic coordinates to geocentric coordinates This MATLAB function converts geodetic latitude and altitude to geocentric position magnitude and geocentric declination. pi/2 <= lat <= +pi/2) longitude (radians) altitude (kilometers) % output % r = ecf position vector (kilometers) geodet4. Page 130 . long = geodetic alt = geodetic latitude (radians) south. long.
m – geodetic altitude to a triaxial ellipsoid This MATLAB function calculates the geodetic altitude relative to a triaxial ellipsoidal planet. The Journal of the Astronautical Sciences. No. by Charles C. 3. Tang. respectively. This function solves for the real root of the following nonlinear equation: cy cx 2 f z p 1 z c2 0 2 2 p cz a 2 c 2 z p cz b 2 c 2 z p where Page 131 . Vol. eq eq The syntax of this MATLAB function is function [rmag. H. and r is the equatorial radius of the Earth. pi/2 <= dec <= +pi/2) triaxial. pp. south. south. The algorithm is based on the numerical method described in “Geodetic Altitude to a Triaxial Ellipsoidal Planet”. alt) % geodetic to geocentric coordinates % input % % % lat alt = geodetic latitude (radians) (+north. pi/2 <= lat <= +pi/2) = geodetic altitude (kilometers) % output % % % rmag = geocentric position magnitude (kilometers) dec = geocentric declination (radians) (+north.Celestial Computing with MATLAB The equations for this method are as follows: 1 sin 2 sin 2 f 2 ˆ ˆ ˆ h 1 2 h 1 4 h 1 1 sin 4 f 2 ˆ 4 h 1 2 and cos 2 1 ˆ ˆ h 1 f 2 1 1 1 cos 4 f 2 ˆ 1 16 4 h ˆ where the geocentric distance r and geodetic altitude h have been normalized by r / req ˆ and h h / r . dec] = geodet4 (lat. JulySeptember 1988. 36. 279283.
138 and b 6367 (kilometers). and the flattening factor is f 1/ 298.Celestial Computing with MATLAB cx acxs c y bcy s cz c 2 z s 2 2 a .257 .m – convert classical orbital elements to inertial state vector This MATLAB function converts the six classical orbital elements to an inertial state vector (position and velocity vectors). b. zs geocentric coordinates of satellite z p z coordinate of subpoint The bracketing interval used during the rootfinding is z p 0 10 z p z p 0 10 (kilometers) where z p0 zs xs / a 2 ys / b zs / c 2 2 The syntax of this MATLAB function is function alt = triaxial(rsc) % geodetic altitude relative % to a triaxial ellipsoid % input % rsc = geocentric position vector (km) % output % alt = geodetic altitude (km) The semiaxes in this function are “hardwired” to the values a 6378. c semiaxes a b c xs . The rectangular components of the object’s inertial position vector are determined from rx p cos cos sin cos i sin ry p sin cos cos cos i sin rz p sin i sin The components of the inertial velocity vector are computed using the following equations: Page 132 . orb2eci. y s . These are representative values for the Earth and can be easily changed for other planets or the Moon.
Page 133 . The following diagram illustrates the geometry of these orbital elements. v] = orb2eci(oev) % convert classical orbital elements to inertial state vector % input % % % % % % % % % % % oev(1) = semimajor axis (kilometers) oev(2) = orbital eccentricity (nondimensional) (0 <= eccentricity < 1) oev(3) = orbital inclination (radians) (0 <= inclination <= pi) oev(4) = argument of periapsis (radians) (0 <= argument of periapsis <= 2 pi) oev(5) = right ascension of ascending node (radians) (0 <= raan <= 2 pi) oev(6) = true anomaly (radians) (0 <= true anomaly <= 2 pi) % output % % r = eci position vector (kilometers) v = eci velocity vector (kilometers/second) eci2orb.Celestial Computing with MATLAB vx vy vz cos sin e sin sin cos i cos e cos p sin sin e sin cos cos i cos e cos p 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 The syntax of this MATLAB function is function [r.m – convert inertial state vector to six classical orbital elements This MATLAB function converts an inertial state vector (position and velocity vectors) to six classical orbital elements.
the vernal equinox. 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 xaxis (vernal equinox) eastward along the fundamental plane to the ascending node. measured along the orbit plane in the direction of Page 134 . The zaxis of this system is collinear with either the spin axis of the Earth or the north ecliptic pole. to the argument of perigee. and the yaxis completes a righthanded coordinate system. and a fundamental plane. measured along the orbit plane in the direction of increasing true anomaly. the ecliptic or the equator.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 argument of periapsis is the angle from the ascending node. The angular orbital elements are defined with respect to a fundamental xaxis. The true anomaly is the angle from the argument of perigee.
It is equal to u . 108 . The scalar orbital eccentricity is determined from h and k as follows: 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 . In the MATLAB code for these calculations. the true anomaly is found from the expression Page 135 . Finally. the orbit is circular or elliptic.Celestial Computing with MATLAB motion. the orbit is circular and there is no argument of periapsis. to the object’s location. u. the orbit is equatorial and there is no RAAN. If the value of orbital eccentricity is greater than . For values of 0 e 1 . measured in the orbit plane. The angular orbital elements are y calculated from the equinoctial orbital elements that are calculated from the ECI position and velocity vectors. The orbit is parabolic when e 1 and the orbit is hyperbolic if e 1 The semimajor axis is calculated using the following expression: a 1 2 v2 r 2 where r r rx2 ry2 rz2 and v v v x v 2 v z2 . to the object’s location in the orbit. which is the angle from the ascending node. The orbital eccentricity is an indication of the type of orbit. Also shown is the argument of latitude. the argument of perigapsis is determined from tan 1 h. k Otherwise. q Otherwise. the right ascension of the ascending node (RAAN) is given by tan 1 p.
modulo. The syntax of this MATLAB function is function oev = eci2orb (r.m.Celestial Computing with MATLAB In these equations.m – convert modified equinoctial orbital elements to classical orbital elements This MATLAB function can be used to convert modified equinoctial orbital elements to classical orbital elements.m and angular orbital elements which can range from 0 to 360 degrees are also processed with the modulo 2 function. v) % convert inertial state vector to six % classical orbital elements via % equinoctial elements % input % % r v = inertial position vector (kilometers) = inertial velocity vector (kilometers/second) % output % % % % % % % % % % % oev(1) oev(2) oev(3) oev(4) oev(5) oev(6) = semimajor axis (kilometers) = orbital eccentricity (nondimensional) (0 <= eccentricity < 1) = orbital inclination (radians) (0 <= inclination <= pi) = argument of periapsis (radians) (0 <= argument of periapsis <= 2 pi) = right ascension of ascending node (radians) (0 <= raan <= 2 pi) = true anomaly (radians) (0 <= true anomaly <= 2 pi) mee2coe. all two argument inverse tangent functions use the four quadrant function atan3. The syntax of this MATLAB function is function coev = mee2coe(mee) % convert modified equinoctial elements % to classical orbit elements % input % % % % % % mee(1) mee(2) mee(3) mee(4) mee(5) mee(6) = = = = = = semilatus rectum of orbit (kilometers) f equinoctial element g equinoctial element h equinoctial element k equinoctial element true longitude (radians) % output % % coev(1) = semimajor axis (kilometers) coev(2) = eccentricity Page 136 .
Celestial Computing with MATLAB % % % % coev(3) coev(4) coev(5) coev(6) = = = = inclination (radians) right ascension of ascending node (radians) argument of periapsis (radians) true anomaly (radians) 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 e i semimajor axis orbital eccentricity 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 a orbital eccentricity e orbital inclination i 2 tan 1 argument of periapsis f 2 g2 p 1 f 2 g2 h2 k 2 tan 1 g f tan 1 k h Page 137 .
v] = mee2eci(mee) % convert modified equinoctial orbital % elements to eci position and velocity vectors % input % % % % % % mee(1) mee(2) mee(3) mee(4) mee(5) mee(6) = = = = = = semilatus rectum of orbit (kilometers) f equinoctial element g equinoctial element h equinoctial element k equinoctial element true longitude (radians) % output % % r = eci position vector (kilometers) v = eci velocity vector (kilometers/second) The relationship between ECI position and velocity vectors and modified equinoctial elements is defined by the following series of equations: position vector r 2 s 2 cos L cos L 2hk sin L r sin L 2 sin L 2hk cos L r 2 s r h sin L k cos L s2 velocity vector Page 138 .m – convert modified equinoctial orbital elements to ECI state vector This MATLAB function can be used to convert modified equinoctial orbital elements to ECI position and velocity vectors. The syntax of this MATLAB function is function [r.Celestial Computing with MATLAB right ascension of the ascending node tan 1 k h true anomaly L L tan 1 g f mee2eci.
m – convert ECI state vector to modified equinoctial elements This MATLAB function can be used to convert an ECI state vector (position and velocity vectors) to modified equinoctial orbital elements. The syntax of this MATLAB function is function mee = eci2mee(reci. veci) % convert eci state vector to % modified equinoctial elements % input % % reci = eci position vector (kilometers) veci = eci velocity vector (kilometers/second) % output % % % % % % mee(1) mee(2) mee(3) mee(4) mee(5) mee(6) = = = = = = semiparameter of orbit (kilometers) f equinoctial element g equinoctial element h equinoctial element k equinoctial element true longitude (radians) Page 139 .Celestial Computing with MATLAB 1 sin L 2 sin L 2hk cos L g 2 f h k 2 g 2 s p 1 v 2 cos L 2 cos L 2hk sin L g f 2 gh k 2 f p s 2 h cos L k sin L f h gk 2 s p where 2 h2 k 2 s2 1 h2 k 2 r p w w 1 f cos L g sin L eci2mee.
. to transform a position vector between the ecliptic and equatorial coordinate systems. The matrixvector form of the transformation between the equatorial and local horizontal coordinate systems are as follows: Page 140 . x x y R y x z z .Celestial Computing with MATLAB rotmat. . y and z axes are defined by 0 1 Rx 0 cos 0 sin cos R y 0 sin cos Rz sin 0 0 sin cos 0 sin 1 0 0 cos sin cos 0 0 0 1 where is the rotation angle. Transformations between fundamental astronomical coordinate systems can also be accomplished using various combinations of these matrices. The three rotation matrices for the x.m – fundamental rotation matrix This MATLAB function computes the elementary rotation matrix for a userdefined rotation angle about a userdefined rotation axis. the following matrixvector relationships can be used: x x y R y x z z . All calculations follow the righthanded rule and counterclockwise rotation angles are positive. For example.
Celestial Computing with MATLAB x x y R 180 R 90 y y z z z A. a h . x x y R 90 R 180 y z y z z h . A.a The syntax of this MATLAB function is function rmatrix = rotmat(iaxis. theta) % rotation matrix % input % % % % iaxis = = = theta = 1 ==> xaxis 2 ==> yaxis 3 ==> zaxis rotation angle (radians) % output % rmatrix = rotation matrix Page 141 .
Hughes. P. Additional information about NOVAS can be found at the Naval Observatory web site located at http://aa. components in au etilt1. ve. aberat. Smith and B. deps] = etilt1 (tjd) % this function computes quantities related to the orientation % of the earth's rotation axis at julian date tjd % nutation parameters obtained from jpleph % input % tjd = tdb julian date for orientation parameters % output % oblm = mean obliquity of the ecliptic at date tjd (degrees) Page 142 . pages 11971210. Apparent. Kaplan. referred to origin at center of mass of the earth.html 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. % input % % % % % % % pos1 = position vector.mil/AA/software/novas/novas_info. Seidelmann. and Astrometric Places of Planets and Stars”.H. referred to origin at center of mass of the earth.m – orientation quantities based on DE405 function [oblm.K. components in au ve = velocity vector of center of mass of the earth. Vol. This section documents the purpose and calling arguments for these routines. Yallop. eqeq. C.navy.A. Topocentric. 639648. 1989.A. dpsi.Celestial Computing with MATLAB 24. referred to origin at solar system barycenter. NOVAS Routines The Celestial Computing with MATLAB software suite includes MATLAB versions of several of the Fortran subroutines contained in the NOVAS (Naval Observatory Vector Astrometry Subroutines) software package. J. components in au/day tlight = light time from body to earth in days if tlight = 0. society 195. III. see murray (1981) % mon. corrected for aberration. % algorithm includes relativistic terms. this function will compute tlight % output % % % pos2 = position vector. No. 4. oblt. 97. notices royal ast. G.m – correction for the aberration of light function pos2 = aberat (pos1.usno. The Astronomical Journal. tlight) % this function corrects position vector for aberration of light.D.
see pages 4145 of the explanatory supplement to the ae. oblt. eqeq. deps] = etilt2 (tjd) % this function computes quantities related to the orientation % of the earth's rotation axis at julian date tjd % nutation parameters obtained from function nutation % input % tjd = tdb julian date for orientation parameters % output % % % % % oblm oblt eqeq dpsi deps = = = = = mean obliquity of the ecliptic at true obliquity of the ecliptic at equation of the equinoxes at date nutation in longitude at date tjd nutation in obliquity at date tjd date tjd (degrees) date tjd (degrees) tjd (arc seconds) (arc seconds) (arc seconds) geocen. this function corrects for parallax. tlight] = geocen (pos1.m – orientation quantities based on IAU 1980 nutation function [oblm. pe) % this function moves the origin of coordinates from the % barycenter of the solar system to the center of mass of the % earth. i. referred to origin at solar system barycenter (au) pe = position vector of center of mass of the earth.Celestial Computing with MATLAB % % % % oblt eqeq dpsi deps = = = = true obliquity of the ecliptic at equation of the equinoxes at date nutation in longitude at date tjd nutation in obliquity at date tjd date tjd (degrees) tjd (arc seconds) (arc seconds) (arc seconds) etilt2.e.m – nutation transformation function pos2 = nutate (tjd. referred to origin at solar system barycenter (au) % output % % % pos2 = position vector. % source ephemeris is jpleph via etilt1 % input % tjd = tdb julian date of epoch Page 143 . pos1) % this function nutates equatorial rectangular coordinates from % mean equator and equinox of epoch to true equator and equinox of % epoch. referred to origin at center of mass of the earth (au) tlight = light time from body to earth in days nutate1.. dpsi.m – move coordinates origin to the Earth centerofmass function [pos2. % input % % % % pos1 = position vector.
it transforms a vector from earthfixed geographic system to spacefixed system based on mean equator and equinox of j2000.) specifically. pos1) % this function nutates equatorial rectangular coordinates from % mean equator and equinox of epoch to true equator and equinox of % epoch. geocentric equatorial rectangular coordinates. % uses nutation function via etilt2 % input % % % % tjd = tdb julian date of epoch pos1 = position vector. referred to geographic equator and greenwich meridian Page 144 . geocentric equatorial rectangular coordinates. referred to mean equator and equinox of epoch % output % % % pos2 = position vector. geocentric equatorial rectangular coordinates. referred to true equator and equinox of epoch (out) % note: % if tjd is negative.m – nutation transformation function pos2 = nutate2 (tjd. gast.Celestial Computing with MATLAB % % % pos1 = position vector. % input % % % % % % % % % tjd = tdt julian date gast = greenwich apparent sidereal time (hours) x = conventionallydefined x coordinate of rotational pole with respect to cio (arc seconds) y = conventionallydefined y coordinate of rotational pole with respect to cio (arc seconds) vece = vector in geocentric rectangular earthfixed system. see pages 4145 of the explanatory supplement to the ae. inverse nutation (true to mean) is applied pnsw. x. referred to true equator and equinox of epoch (out) % note: % if tjd is negative. y. and precession. (combined rotation is symbolized p n s w.0. spin. referred to mean equator and equinox of epoch % output % % % pos2 = position vector.m – Earthfixed to spacefixed transformation function vecs = pnsw (tjd. inverse nutation (true to mean) is applied nutate2. vece) % % % % % transforms a vector from earthfixed system to spacefixed system by applying rotations for wobble. nutation. geocentric equatorial rectangular coordinates.
including % foreshortening effects.. (1988). sun = 10.0 Page 145 .pluto = 9. and newhall. on the tdb time scale = body identification number for the solar system object of interest. center of mass of the sun = 1 % output % % % % pos = position vector of 'body' at tjd. pos1. x x (1988). vel1. % kaplan.0 note tjd = 0 means no precession/nutation transformation gast = 0 means no spin transformation x = y = 0 means no wobble transformation propmo.m. ierr] = solsys (tjd.. vel. usno document dated 20 october 1988 % input % % % % % % tjd body = julian date of the desired time. body. solar system barycenter = 0..h. moon = 11 origin = origin code. origin) % purpose % this is solsys version '2da'. tjd2) % this function applies proper motion. mercury = 1. it is intended to provide % an interface between the jpl directaccess solar system % ephemerides and the 'novas' astrometric function library % references % standish. % input % % % % tjd1 pos1 vel1 tjd2 = = = = tdb julian date position vector velocity vector tdb julian date of at at of first epoch first epoch first epoch second epoch % output % pos2 = position vector at second epoch solsys. g. "novas: naval observatory vector astrometry % subroutines"..Celestial Computing with MATLAB % output % % % % % % vecs = vector in geocentric rectangular spacefixed system. e. to a star's position. referred to mean equator and equinox of j2000. equatorial rectangular coordinates in au referred to the mean equator and equinox of j2000. "the jpl % export planetary ephemeris".m – interface to JPL ephemerides function [pos. jpl document dated 17 june 1988.m – apply proper motion correction function pos2 = propmo (tjd1.
components in au % output % % % pos2 = position vector.. 639648. components in au tdtimes. referred to rotational equator and orthogonal reference meridian % output % % pos2 = vector in geocentric rectangular nonrotating system. notices royal ast.... % input % % % % % pos1 = position vector. everything ok . referred to origin at center of mass of the earth. corrected for gravitational deflection. society 195. = 1 . secdif] = tdtimes (tdbjd) % this function computes the terrestrial dynamical % time (tdt) julian date corresponding to a barycentric % dynamical time (tdb) julian date.m – correct for the deflection of light function pos2 = sunfld (pos1.0.m – compute TDT julian date function [tdtjd. pe) % % % % this function corrects position vector for the deflection of light in the gravitational field of the sun. tjd out of range spin. invalid value of 'origin' = 3 . this function valid for bodies within the solar system as well as for stars. components in au pe = position vector of center of mass of the earth.. referred to origin at center of mass of the earth. referred to origin at center of mass of the sun.Celestial Computing with MATLAB % % % % % % % % % vel = velocity vector of 'body' at tjd.. pos1) % % % % this subroutine transforms geocentric rectangular coordinates from rotating system based on rotational equator and orthogonal reference meridian to nonrotating system based on true equator and equinox of date. in au/day ierr = 0 . % input % % % st = local apparent sidereal time at reference meridian (hours) pos1 = vector in geocentric rectangular rotating system. see murray (1981) mon. expressions used in Page 146 .. invalid value of 'body' = 2 . referred to true equator and equinox of date sunfld.m – rotating to nonrotating transformation function pos2 = spin (st. error detected by jpl software. equatorial rectangular system referred to the mean equator and equinox of j2000..
vel] = terra (glon. pmra. dec. parllx. rv) % this function converts angular quantities to vectors % input % % % % % % ra dec pmra pmdec parllx rv = = = = = = right ascension (hours) declination (degrees) proper motion in ra (seconds of time per julian century) proper motion in dec per julian century (seconds of arc) parallax (seconds of arc) radial velocity (kilometers per second) % output % pos = position vector. referred to true equator and equinox of date. glat.Celestial Computing with MATLAB % this version are approximations resulting in accuracies % of about 20 microseconds. % input % % % % % % glon = longitude of observer with respect to reference meridian (east +) in degrees glat = geodetic latitude (north +) of observer in degrees ht = height of observer in meters st = local apparent sidereal time at reference meridian in hours % output % % % % % % % % % % pos = position vector of observer with respect to center of earth. vel] = vectrs (ra.m – position and velocity vectors of a terrestrial observer function [pos. % input % tdbjd = tdb julian date % output % % tdtjd = tdt julian date secdif = difference tdbjdtdtjd. ht. st) % this functions computes the position and velocity vectors of % a terrestrial observer with respect to the center of the earth. equatorial rectangular coordinates. pmdec. referred to true equator and equinox of date.m – convert angular quantities to vectors function [pos. components in au vel = velocity vector of observer with respect to center of earth. equatorial rectangular coordinates. pos is effectively referred to equator and greenwich vectrs. in seconds (out) terra. components in au/day note: if reference meridian is greenwich and st=0. equatorial rectangular coordinates (au) Page 147 .
it transforms a vector from earthfixed geographic system to rotating system based on rotational equator and orthogonal greenwich meridian through axis of rotation. y. referred to geographic equator and greenwich meridian % output % % pos2 = vector in geocentric rectangular rotating system.Celestial Computing with MATLAB % vel = velocity vector. pos1) % % % % % this subroutine corrects earthfixed geocentric rectangular coordinates for polar motion. % input % % % % % % x = conventionallydefined x coordinate of rotational pole with respect to cio (arc seconds) y = conventionallydefined y coordinate of rotational pole with respect to cio (arc seconds) pos1 = vector in geocentric rectangular earthfixed system.m – polar motion correction function pos2 = wobble (x. equatorial rectangular coordinates (au/day) wobble. referred to rotational equator and orthogonal greenwich meridian Page 148 .
Astronomical Algorithms. 1979.Celestial Computing with MATLAB 25. 1994. Danby. J. 1991.. 1995. E. Meeus.. and Clemence. J.. Page 149 . 1989. WillmannBell. 1970. J.. WillmannBell. WillmannBell. Fundamentals of Celestial Mechanics.. Mathematical Astronomy Morsels. A. Chapront. Planetary Programs and Tables from –4000 to +2800. 1999. F. A. CRC Press... Meeus.... 1977. J. WillmannBell. V. G. M. Dover. to A. D. 1997. PrenticeHall. and Simon. J. P.... Tables of the Sun. 1996.. A. Astronomy on the Personal Computer... Heafner. P. The Macmillian Company. Krieger Publishing. D. L. P. Escobal. Krieger Publishing. O.. G. SpringerVerlag. 1976. Robert E. Brumberg.. Malcolm. Brouwer. R. M. Chebotarev. and Der. Analytical and Numerical Methods of Celestial Mechanics.C. Meeus. Computer Methods for Mathematical Computations. 1995. and Pfleger.. WillmannBell. J. J. 1967. 8000. R. J. Escobal. C. Bretagnon. G.. Volume 177. B. Methods of Orbit Determination. Robert E. AIAA Progress in Astronautics and Aeronautics. 1988. J. Dubyago. A.. Forsythe. Lunar Tables and Programs from 4000 B. Dormand. and ChaprontTouze.. P. Moon and Planets. Montenbruck. Moulton. Academic Press. M. SpringerVerlag. and Moler.D. Methods of Celestial Mechanics. R. Transits. Numerical Methods for Differential Equations. 1961. Methods of Astrodynamics. The Determination of Orbits.. WillmannBell. 1986. N. 1961. J. Analytical Techniques of Celestial Mechanics... An Introduction to Celestial Mechanics. R. American Elsevier Publishing Company. G. Bibliography and References Bonavito. T. WillmannBell. 1991. A. Orbital and Celestial Mechanics. Fundamental Ephemeris Computations. WillmannBell. 1998. Meeus.
Szebehely. Explanatory Supplement to the Astronomical Alamanac. V. Adventures in Celestial Mechanics.Celestial Computing with MATLAB Seidelmann. (Editor). K. 1989. P. University Science Books. 1992. Page 150 .. G. University of Texas Press.