[152] | 1 | % Orbit eccentric anomaly, Kepler's equation keplers equation
|
---|
| 2 | % Richard Rieber
|
---|
| 3 | % 1/23/2005
|
---|
| 4 | % rrieber@gmail.com
|
---|
| 5 | %
|
---|
| 6 | % Revision 8/21/07: Fixed typo in line 38 if statement
|
---|
| 7 | % Added H1 line for lookfor functionality
|
---|
| 8 | %
|
---|
| 9 | % function E = CalcEA(M,ecc,tol)
|
---|
| 10 | %
|
---|
| 11 | % Purpose: Solves for eccentric anomaly, E, from a given mean anomaly, M,
|
---|
| 12 | % and eccentricty, ecc. Performs a simple Newton-Raphson iteration
|
---|
| 13 | %
|
---|
| 14 | % Inputs: o M - Mean anomaly in radians.
|
---|
| 15 | % o ecc - Eccentricity of the orbit.
|
---|
| 16 | % o tol - a tolerance at which to terminate iterations; Default
|
---|
| 17 | % is 10^-8 radians. [OPTIONAL]
|
---|
| 18 | %
|
---|
| 19 | % Outputs: o E - The eccentric anomaly in radians.
|
---|
| 20 | %
|
---|
| 21 | % E = CalcEA(M,ecc) uses default tolerances
|
---|
| 22 | %
|
---|
| 23 | % E = CalcEA(M,ecc,tol) will use a user specified tolerance, tol
|
---|
| 24 | %
|
---|
| 25 |
|
---|
| 26 | function E = CalcEA(M,ecc,tol)
|
---|
| 27 |
|
---|
| 28 | %Checking for user inputed tolerance
|
---|
| 29 | if nargin == 2
|
---|
| 30 | %using default value
|
---|
| 31 | tol = 10^-8;
|
---|
| 32 | elseif nargin > 3
|
---|
| 33 | error('Too many inputs. See help CalcEA')
|
---|
| 34 | elseif nargin < 2
|
---|
| 35 | error('Too few inputs. See help CalcEA')
|
---|
| 36 | end
|
---|
| 37 |
|
---|
| 38 | if (M > -pi && M < 0) || M > pi
|
---|
| 39 | E = M - ecc;
|
---|
| 40 | else
|
---|
| 41 | E = M + ecc;
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | Etemp = E + (M - E + ecc*sin(E))/(1-ecc*cos(E));
|
---|
| 45 | Etemp2 = E;
|
---|
| 46 |
|
---|
| 47 | while abs(Etemp - Etemp2) > tol
|
---|
| 48 | Etemp = Etemp2;
|
---|
| 49 | Etemp2 = Etemp + (M - Etemp + ecc*sin(Etemp))/(1-ecc*cos(Etemp));
|
---|
| 50 | end
|
---|
| 51 |
|
---|
| 52 | E = Etemp2; |
---|