source: proiecte/SolarSim/Matlab/CalcEA.m @ 152

Last change on this file since 152 was 152, checked in by (none), 14 years ago
File size: 1.4 KB
Line 
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
26function E = CalcEA(M,ecc,tol)
27
28%Checking for user inputed tolerance
29if nargin == 2
30    %using default value
31    tol = 10^-8;
32elseif nargin > 3
33    error('Too many inputs.  See help CalcEA')
34elseif nargin < 2
35    error('Too few inputs.  See help CalcEA')
36end
37
38if (M > -pi && M < 0) || M > pi
39    E = M - ecc;
40else
41    E = M + ecc;
42end
43
44Etemp  = E + (M - E + ecc*sin(E))/(1-ecc*cos(E));
45Etemp2 = E;
46
47while abs(Etemp - Etemp2) > tol
48    Etemp = Etemp2;
49    Etemp2 = Etemp + (M - Etemp + ecc*sin(Etemp))/(1-ecc*cos(Etemp));
50end
51
52E = Etemp2;
Note: See TracBrowser for help on using the repository browser.