% Do newton raphson for O13.

e = 0.97; % Eccentricity.

%MATLAB EXCLUSIVE %T  = years(76.1); % Orbital period.
T = 76.1 * 365.2425 * 24 * 60 *60 *1000
tp = datetime(1986, 2, 9);% Perihelion passage.

t = datetime(1986, 3, 14); % Our target time.

M = 2*pi*(t-tp)/T; % Mean anomaly -> this will be our inital guess.


%% AT2
M = 2*pi*15*60/(3*60*60)
e = 0.33

f       = @(E) E-e*sin(E)-M;
fprim   = @(E) 1-e*cos(E);

% Newton-Raphson Method
E = M;
Eprev = 0;
iterations = 0;
tol = 1e-6;
while (abs(E - Eprev) > tol)
    Eprev = E;
    E = E - f(E)/fprim(E)

    iterations = iterations + 1;
end
fprintf("Converged value: %f rad / %f deg\nConverged to within %f in %d iterations.\n", E, r2d(E), tol, iterations);


