MATLAB script that predicts closest approach between the Earth and heliocentric objects.
cae2o(x)
function y = cae2o(x)
% Earth-to-object closest approach objective function
% required by cae2ho.m
% input
% x = simulation time argument (days)
% output
% y = Earth-to-object distance (au)
% Orbital Mechanics with MATLAB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global tisaved ysaved jdatei drsaved
% compute object's position vector
ttmp = tisaved;
for i = 1:1:6
ytmp(i) = ysaved(i);
end
% number of differential equations
neq = 6;
% step size guess (days)
h = 0.1;
% integrate from tisaved to requested time = x
tetol = 1.0e-15;
ysaved = rkf78('heqms', neq, ttmp, x, h, tetol, ytmp);
% compute object's position vector
for i = 1:1:3
robject(i) = ysaved(i);
end
% compute heliocentric position vector of the Earth
jdate = jdatei + x;
result = jplephem(jdate, 3, 11);
% vector from Earth to object
for i = 1:1:3
re2a(i) = robject(i) - result(i);
end
% Earth-to-object scalar distance (au)
srange = norm(re2a);
drsaved = srange;
% save objective function value and current time
y = srange;
tisaved = x;