-
Notifications
You must be signed in to change notification settings - Fork 3
/
MAtoEA.m
43 lines (36 loc) · 1 KB
/
MAtoEA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function EA = MAtoEA(e,MA) % mean anomaly to eccentric anomaly conversion
% MA to EA
% numerical method
if e == 0
EA = MA ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif e<1
% elipse case
if MA < pi
EA = MA + e/2;
else
EA = MA - e/2;
end
Tolerance = 1e-8;
Ratio = ones(size(MA));
while all(abs(Ratio)>Tolerance)
Ratio = (EA - e*sin(EA) - MA)./(1 - e*cos(EA));
EA = EA - Ratio;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif e == 1
e=e+(1e-20)
MAtoEA(e,MA)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif e>1
% hyperbolic case
EA = MA;
Tolerance = 1e-8;
Ratio = ones(size(MA));
while all(abs(Ratio)>Tolerance)
Ratio = (e*sinh(EA) - EA - MA)./(e*cosh(EA) - 1);
EA = EA - Ratio;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end