File size: 9,553 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | function [out] = MD2MinRefine(tmd,tsg,dtsg,ttol,itermax,findmin,Eb10,Qb10,Eb20,Qb20,HBR,POPPAR)
% MD2MinRefine - Iteratively refine the paramters of the min of effective
% MD2 curve
%
% Syntax: [out] = MD2MinRefine(tmd,tsg,dtsg,ttol,itermax,findmin,Eb10,Qb10,Eb20,Qb20,HBR,POPPAR)
%
% =========================================================================
%
% Copyright (c) 2022-2025 United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================
%
% DESCRIPTION:
%
% Refines key parameters to the minimum of the effective Mahalanobis
% distance squared (MD2) curve. The key parameters are:
% - The time of the minimum of the MD2 curve
% - The value of the MD2 curve at the minimum
% - The numerically derived first derivative of MD2 at the minimum time
% - The numerically derived second derivative of MD2 at the minimum
% time
% - The 1-sigma time width of the MD2 curve at the minimum time
% - The inertial-frame relative pos/vel state at the minimum time
% - The inertial-frame combined covariance at the minimum time
% - The determinant of the position 3x3 of the combined covariance at
% the minimum time
% - The inverse of the position 3x3 of the combined covariance at the
% minimum time
%
% The function can either calculate these values at the minimum time
% passed in, or it can search the n-sigma time span for a minimum of the
% MD2 curve (starting at the "tmd" time passed in) and calculate the
% values from that new minimum.
%
% =========================================================================
%
% INPUT:
%
% tmd = Time, in seconds from TCA, of the minimum of the Mahalanobis
% distance squared parabola
% tsg = The 1-sigma time width for numerically computing the output
% values. It is also defines the search interval when findmin is
% set to true.
% dtsg = Sigma multiplier applied to the tsg parameter.
% ttol = Convergence tolerance (in seconds)
% itermax = Maximum number of iterations performed by the function.
% findmin = When set to true, indicates that the function should search
% for the minimum of the MD2 curve. When false, assume that tmd
% is already the minimum of the MD2 curve.
% Eb10 = Equinoctial state of the primary object at TCA. [6x1]
% Qb10 = Equinoctial state covariance of the primary object at TCA. [6x6]
% Eb20 = Equinoctial state of the secondary object at TCA. [6x1]
% Qb20 = Equinoctial state covariance of the secondary object at TCA. [6x6]
% HBR = Combined HBR of the two objects (in m).
% POPPAR = Peak Overlap (PeakOveralapMD2.m) input parameters.
%
% =========================================================================
%
% OUTPUT:
%
% out = Structure containing results and other pertinent parameters
% calculated by the function. Values include:
% tmd - Time (in seconds from TCA) of the minimum of the MD2 curve
% ydot - First derivative of the MD2 curve at tmd
% ydotdot - Second derivative of the MD2 curve at tmd
% tsg - 1-sigma time width of the MD2 curve at tmd
% iter - Number of iterations performed by the function
% MD2converged - Indicates of MD2MinRefine converged
% POPconverged - Indicates if the calls to PeakOverlapMD2 converged
% ymd - Value of PeakOverlapMD2 at tmd
% delt - Delta time for numerical calculation
% tlo - Time (in sec relative to TCA) of the lower bracketing point
% thi - Time (in sec relative to TCA) of the upper bracketing point
% ylo - Value of PeakOverlapMD2 at tlo
% Xulo - Inertial-frame relative pos/vel state at tlo [6x1]
% Pslo - Inertial-frame combined covariance at tlo [6x6]
% Asdetlo - Determinant of the postion 3x3 of Pslo
% Asinvlo - Inverse of the position 3x3 of Pslo [3x3]
% Xu - Inertial-frame relative pos/vel state at tmd [6x1]
% Ps - Inertial-frame combined covariance at tmd [6x6]
% Asdet - Determinant of the position 3x3 of Ps
% Asinv - Inverse of the position 3x3 of Ps [3x3]
% yhi - Value of PeakOverlapMD2 at thi
% Xuhi - Inertial-frame relative pos/vel state at thi [6x1]
% Pshi - Inerital-frame combined covariance at thi [6x6]
% Asdethi - Determinant of the position 3x3 of Pshi
% Asinvhi - Inverse of the position 3x3 of Pshi [3x3]
%
% =========================================================================
%
% Initial version: Oct 2022; Latest update: Aug 2025
%
% ----------------- BEGIN CODE -----------------
% Iteratively refine minimum of the MD^2 curve in time
iterating = true; out.iter = 0;
itermin = min(2,itermax); itermed = min(4,itermax);
out.MD2converged = false; out.POPconverged = true;
out.tmd = tmd; out.tsg = tsg; out.ymd = NaN;
while iterating
% Increment iteration counter
out.iter = out.iter+1;
% Save old value of best MD^2 minimization time
tmdold = out.tmd; tsgold = out.tsg;
% Calculate 3 points to estimate numerical derivatives
% Point spacing
out.delt = out.tsg*dtsg; twodelt = 2*out.delt; delt2 = out.delt^2;
% Low and high bracketing points
out.tlo = out.tmd-out.delt;
out.thi = out.tmd+out.delt;
% Calculate y = MD^2 for the three points
[out.ylo,out.Xulo,out.Pslo,out.Asdetlo,out.Asinvlo,~,aulo] = ...
PeakOverlapMD2(out.tlo, ...
0,Eb10,Qb10, ...
0,Eb20,Qb20, ...
HBR,1,POPPAR);
if out.iter == 1 || findmin
[out.ymd,out.Xu,out.Ps,out.Asdet,out.Asinv,~,aumd] = ...
PeakOverlapMD2(out.tmd, ...
0,Eb10,Qb10, ...
0,Eb20,Qb20, ...
HBR,1,POPPAR);
end
[out.yhi,out.Xuhi,out.Pshi,out.Asdethi,out.Asinvhi,~,auhi] = ...
PeakOverlapMD2(out.thi,...
0,Eb10,Qb10, ...
0,Eb20,Qb20, ...
HBR,1,POPPAR);
if isnan(out.ylo) || isnan(out.ymd) || isnan(out.yhi)
% POP search unconverged for one or more of the three points
iterating = false; out.POPconverged = false;
else
% Calculate new value of SigmaT
out.ydot = (out.yhi-out.ylo)/twodelt;
out.ydotdot = (out.yhi-2*out.ymd+out.ylo)/delt2;
out.tsg = sqrt(2/max(0,out.ydotdot));
% Analyze convergence criteria
if findmin
% In this case, estimate the new time that minimizes the
% effective MD^2 curve before analyzing convergence
out.tmd = out.tmd - out.ydot/out.ydotdot;
cnvg = abs(out.tmd-tmdold) < ttol*out.tsg;
else
cnvg = abs(out.tsg-tsgold) < ttol*out.tsg;
end
% Check for Maha. distance convergence
if ~cnvg
if findmin
MD2check = out.iter >= itermed;
else
MD2check = out.iter >= itermin;
end
if MD2check
MD2conv = 1 - ...
[aulo.MD2actual auhi.MD2actual]/aumd.MD2actual;
if max(abs(MD2conv)) < ttol
cnvg = true;
end
end
end
if isinf(out.tsg)
% Second derivative not positive (i.e., ydotdot <= 0)
iterating = false; out.MD2converged = false;
elseif cnvg && out.iter >= itermin
iterating = false; out.MD2converged = true;
else
iterating = out.iter <= itermax;
end
% % For debugging
% if findmin
% cnvgfact = abs(out.tmd-tmdold)/out.tsg;
% else
% cnvgfact = abs(out.tsg-tsgold)/out.tsg;
% end
% disp(['Iter = ' num2str(out.iter,'%02i') ...
% ' tmd = ' num2str(out.tmd,'%0.8g') ...
% ' ymd = ' num2str(out.ymd,'%0.8g') ...
% ' tsg = ' num2str(out.tsg,'%0.8g') ...
% ' dmd = ' num2str(abs(out.tmd-tmdold)/out.tsg,'%0.8g') ...
% ' dsg = ' num2str(abs(out.tsg-tsgold)/out.tsg,'%0.8g') ...
% ' cnv = ' num2str(cnvgfact)]);
end
end
return;
end
% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history
% shown below:
%
% ----------------- CHANGE HISTORY ------------------
% Developer | Date | Description
% ---------------------------------------------------
% D. Hall | 2022-Oct-03 | Initial Development
% D. Hall | 2023-Mar-01 | Updated method for calculating ydot and
% ydotdot. Added convergence check for
% ydotdot <= 0.
% D. Hall | 2025-Jan-02 | Added checks for Mahalanobis distance
% convergence.
% L. Baars | 2025-Aug-06 | Updated documentation for public release.
% =========================================================================
%
% Copyright (c) 2022-2025 United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================
|