File size: 4,452 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
function [r,v] = LagrangeStateInterp(T, time, Pos, Vel)
%
% LagrangeStateInterp - Interpolate position/velocity state using 
% a hybrid 5-point Hermit/Lagrange interpolation method.
%
% Syntax:   [r,v] = LagrangeInterp(T, time, Pos, Vel)
%
% Inputs:
%    T   -  Time to interpolate to in days, time
%             must be between the first and last epoch times
%    time  -  Times in days for the five state points (5x1 vector)
%    Pos   -  Position vectors in ECI coordinates (5x3 matrix)
%    Vel   -  Velocity vectors in ECI coordinates (5x3 matrix)
%
% Outputs:
%    r     -  Interpolated ECI T position in (1x3 vector)
%    v     -  Interpolated ECI T velocity in (1x3 vector)
%
% Other m-files required: None
% Subfunctions: None
% MAT-files required: None
% See also: None
%
% ----------------- BEGIN CODE -----------------

% Convert times from days to seconds, and make relative
T    = (T   -time(1))*86400;
time = (time-time(1))*86400;

% Initializing matrices for Lagragian Polynomials ZL and ZL'
% Create Divisor matrix D
D = [1 -1/(time(2)-time(1)) -1/(time(3)-time(1)) -1/(time(4)-time(1)) -1/(time(5)-time(1));...
    1/(time(2)-time(1)) 1 -1/(time(3)-time(2)) -1/(time(4)-time(2)) -1/(time(5)-time(2));...
    1/(time(3)-time(1)) 1/(time(3)-time(2)) 1 -1/(time(4)-time(3)) -1/(time(5)-time(3));...
    1/(time(4)-time(1)) 1/(time(4)-time(2)) 1/(time(4)-time(3)) 1 -1/(time(5)-time(4));...
    1/(time(5)-time(1)) 1/(time(5)-time(2)) 1/(time(5)-time(3)) 1/(time(5)-time(4)) 1];

% Create Ration matrix R
R = [1 (T-time(2))*D(1,2) (T-time(3))*D(1,3) (T-time(4))*D(1,4) (T-time(5))*D(1,5);...
    (T-time(1))*D(2,1) 1 (T-time(3))*D(2,3) (T-time(4))*D(2,4) (T-time(5))*D(2,5);...
    (T-time(1))*D(3,1) (T-time(2))*D(3,2) 1 (T-time(4))*D(3,4) (T-time(5))*D(3,5);...
    (T-time(1))*D(4,1) (T-time(2))*D(4,2) (T-time(3))*D(4,3) 1 (T-time(5))*D(4,5);...
    (T-time(1))*D(5,1) (T-time(2))*D(5,2) (T-time(3))*D(5,3) (T-time(4))*D(5,4) 1];

% Compute Lagrangian Polynomials ZL and ZL'
LZL = [R(1,1)*R(1,2)*R(1,3)*R(1,4)*R(1,5);...
       R(2,1)*R(2,2)*R(2,3)*R(2,4)*R(2,5);...
       R(3,1)*R(3,2)*R(3,3)*R(3,4)*R(3,5);...
       R(4,1)*R(4,2)*R(4,3)*R(4,4)*R(4,5);...
       R(5,1)*R(5,2)*R(5,3)*R(5,4)*R(5,5);];

LZLP = -1*ones(5,1) + D*ones(5,1);

% Compute Postion using Hermite Interpolation, Velocity with Lagrangian Interpolation
LHERFN = [(1-2*LZLP(1)*(T-time(1)))*(LZL(1)^2);...
          (1-2*LZLP(2)*(T-time(2)))*(LZL(2)^2);...
          (1-2*LZLP(3)*(T-time(3)))*(LZL(3)^2);...
          (1-2*LZLP(4)*(T-time(4)))*(LZL(4)^2);...
          (1-2*LZLP(5)*(T-time(5)))*(LZL(5)^2)];

LDHERF = [(T-time(1))*(LZL(1)^2);...
          (T-time(2))*(LZL(2)^2);...
          (T-time(3))*(LZL(3)^2);...
          (T-time(4))*(LZL(4)^2);...
          (T-time(5))*(LZL(5)^2)];

r(1) = LHERFN(1)*Pos(1,1)+LDHERF(1)*Vel(1,1)+...
       LHERFN(2)*Pos(2,1)+LDHERF(2)*Vel(2,1)+...
       LHERFN(3)*Pos(3,1)+LDHERF(3)*Vel(3,1)+...
       LHERFN(4)*Pos(4,1)+LDHERF(4)*Vel(4,1)+...
       LHERFN(5)*Pos(5,1)+LDHERF(5)*Vel(5,1);

r(2) = LHERFN(1)*Pos(1,2)+LDHERF(1)*Vel(1,2)+...
       LHERFN(2)*Pos(2,2)+LDHERF(2)*Vel(2,2)+...
       LHERFN(3)*Pos(3,2)+LDHERF(3)*Vel(3,2)+...
       LHERFN(4)*Pos(4,2)+LDHERF(4)*Vel(4,2)+...
       LHERFN(5)*Pos(5,2)+LDHERF(5)*Vel(5,2);

r(3) = LHERFN(1)*Pos(1,3)+LDHERF(1)*Vel(1,3)+...
       LHERFN(2)*Pos(2,3)+LDHERF(2)*Vel(2,3)+...
       LHERFN(3)*Pos(3,3)+LDHERF(3)*Vel(3,3)+...
       LHERFN(4)*Pos(4,3)+LDHERF(4)*Vel(4,3)+...
       LHERFN(5)*Pos(5,3)+LDHERF(5)*Vel(5,3);

v = [LZL(1)*Vel(1,1)+LZL(2)*Vel(2,1)+LZL(3)*Vel(3,1)+LZL(4)*Vel(4,1)+LZL(5)*Vel(5,1) ...
     LZL(1)*Vel(1,2)+LZL(2)*Vel(2,2)+LZL(3)*Vel(3,2)+LZL(4)*Vel(4,2)+LZL(5)*Vel(5,2) ...
     LZL(1)*Vel(1,3)+LZL(2)*Vel(2,3)+LZL(3)*Vel(3,3)+LZL(4)*Vel(4,3)+LZL(5)*Vel(5,3)];

return
end
    
% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history 
% shown below:
%
%---------------- CHANGE HISTORY ------------------
% Developer      |    Date    |     Description
%--------------------------------------------------
% B. Skrehart    | Sep - 2016  | Initial Development
% D. Hall        | 2020-APR-01 | Modified from function "LagrangeInterp"
%                                to only interpoate pos & vel vectors,
%                                eliminating cov matrix interpolation.