Code covered by the BSD License  

Highlights from
A MATLAB Script for Predicting Lunar Eclipses

A MATLAB Script for Predicting Lunar Eclipses

by

 

06 Dec 2012 (Updated )

Predicting the local circumstances of lunar eclipses.

eclfunc(x)
function fx = eclfunc(x)

% lunar eclipse objective function

% input

%  x = elapsed simulation time (days)

% output

%  fx = objective function at x

% Celestial Computing with MATLAB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global dtr htr jdatei

global glon glat ht psi

global radsun radmoon req

global pmoon psun sdsun sdmoon

% current utc julian date

jdutc = jdatei + x;

% tdt julian date

jdtdt = utc2tdt(jdutc);

% calculate geocentric unit position vector of the moon

[ramoon, decmoon, rmmoon] = applan1(jdtdt, jdutc, 11, 3, 0, glon, glat, ht);

umoon(1) = cos(htr * ramoon) * cos(dtr * decmoon);
umoon(2) = sin(htr * ramoon) * cos(dtr * decmoon);
umoon(3) = sin(dtr * decmoon);

% compute semidiameter of the moon

sdmoon = asin(radmoon / rmmoon);

% calculate geocentric unit position vector of the sun

[rasun, decsun, rmsun] = applan1(jdtdt, jdutc, 10, 3, 0, glon, glat, ht);

usun(1) = cos(htr * rasun) * cos(dtr * decsun);
usun(2) = sin(htr * rasun) * cos(dtr * decsun);
usun(3) = sin(dtr * decsun);

% compute semidiameter of the moon

sdsun = asin(radsun / rmsun);

% calculate penumbra shadow angle

pmoon = asin(req / rmmoon);

psun = asin(req / rmsun);

pangle = 1.02 * (0.99834 * pmoon + psun + sdsun);

% compute umbra shadow angle

uangle = 1.02 * (0.99834 * pmoon + psun - sdsun);

% compute separation angle between anti-sun and moon vectors

cpsi = dot(umoon, usun);

psi = acos(-cpsi);

% compute objective function

fx = psi - pangle - sdmoon;

Contact us