File Exchange

image thumbnail

Ellipsoidal Gravity Vector

version (1.31 KB) by Michael Kleder
Computes the gravitational acceleration vector at a specified location using ...


Updated 26 Aug 2005

No License

XYZ2GRAV - computes the gravitational acceleration vector at a specified ECEF location using the JGM2 gravitational ellipsoid only. Higher-order gravity terms (the "gravity anomaly") are ingnored. Only the pure ellipsoid is used.

[gx,gy,gz] = XYZ2GRAV(x,y,z)

x, y, z = Earth-Centered-Eacrth-Fixed (ECEF) cartesian coordinates (meters)
gx,gy,gz = components of gravitational acceleration in ECF (meters/sec^2)

(1) x,y,z may be scalars, vectors, or matrices but must have the same size and shape
(2) gx,gy,gz will have the same size/shape as x,y,z
(3) Only the ellipsoidal portion of the JGM-2 gravity model is used here.
(4) Points inside the earth will return gravity vectors, but will be higher in magnitude than physical reality since mass "above" the point is not removed from consideration; i.e., the ellipsoidal gravitational field surrounds a point at the center of the earth. The strength of the field increases as one gets closer to that central point.
(5) If all inputs are zero, then NaN is returned.
(6) Source of initial formulas:
(7) The gx & gy formulas were written in a more explicit form to prevent divergence when the x-coordinate is zero.
(8) The calculation was accelerated by precomputing some values.
(9) No warranty; use at your own risk.

Version 1.0 - Initial writing. Michael Kleder, August 2005

Cite As

Michael Kleder (2021). Ellipsoidal Gravity Vector (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Yuchi Miao


The desciption is a little misleading. It actuall computes gravitional acceleration, including the J2 pertubution, given a satellite's coordinates in earth centered interial (ECI), and not ECF. If the position is in ECF, you need to also compute the effect of the coriolis and centripetal accelerations, due to the rotating frame. This requires both the satellite position and velocity vectors.

Mohamed Ali

It is very nice example

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!