File size: 2,030 Bytes
5ab75a9 | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | function J = JacobianCartesian2EphoffsetFast(t,Xt,AuxEt,MeanXt,eph)
%
% Calculate the Jacobian, J = dE/dX, between the ephemeris-offset elements
% and the cartesian state
%
% INPUT:
%
% t = Ephemeris time
% Xt = Cartesian state at time t; Xt = (rt',vt')' [ km & km/s ]
% Et = Ephemeris-offset elements at time t [ km & km/s ]
% AuxEt = Auxiliary Et quantities
% (i.e., the 'out' structure produced by the function
% convert_cartesian_to_ephoffset.m)
% MeanXt = mean Cartesian state at time t [ km & km/s ]
% eph = Ephemeris table structure
%
% OUTPUT:
%
% J = dE/dX [6x6] = Jacobian matrix
%
% Persistent variable for warning
persistent warning_issued
if isempty(warning_issued)
warning_string = ['Calculating JacobianCartesian2EphoffsetFast is ' ...
'usually less efficient than calculating the inverse of ' ...
'JacobianEphoffset2CartesianFast'];
warning(warning_string);
warning_issued = true;
end
% Initialize Jacobian Matrix
J = zeros(6,6);
% Ensure that AuxEt is not empty
if isempty(AuxEt)
[~,AuxEt] = convert_cartesian_to_ephoffset(t,Xt,MeanXt,eph);
end
% Velocity-velocity part of Jacobian matrix
J(4:6,4:6) = [AuxEt.Xhat_tau; ...
AuxEt.Yhat_tau; ...
AuxEt.Zhat_tau]';
% Perturbations for first three eph.offset elements, E(1:3), in km
epsX13 = 1e-4; twoepsX13 = 2*epsX13;
% Numerically calculate the required derivatives
for i = 1:3
% Re-set/initialize perturbed states
Xminus = Xt;
Xplus = Xt;
% Perturb state
Xminus(i) = Xt(i) - epsX13;
Xplus (i) = Xt(i) + epsX13;
% Convert the perturbed Cartesian states into Equinoctial states
[Eminus,~] = convert_cartesian_to_ephoffset(t,Xminus,MeanXt,eph);
[Eplus ,~] = convert_cartesian_to_ephoffset(t,Xplus ,MeanXt,eph);
% Partial derivatives based on central differences
J(:,i) = (Eplus(1:6) - Eminus(1:6)) / twoepsX13;
end
return
end |