|
7 | 7 | % [t,P] = odericcati(A,B,Q,R,S,PT,tspan) |
8 | 8 | % |
9 | 9 | % Copyright © 2021 Tamas Kis |
10 | | -% Last Update: 2021-12-23 |
| 10 | +% Last Update: 2022-06-07 |
11 | 11 | % Website: https://tamaskis.github.io |
12 | 12 | % Contact: tamas.a.kis@outlook.com |
13 | 13 | % |
14 | 14 | % TECHNICAL DOCUMENTATION: |
15 | 15 | % https://tamaskis.github.io/documentation/Riccati_Differential_Equation.pdf |
16 | 16 | % |
17 | | -% REFERENCES: |
18 | | -% [1] https://www.mathworks.com/help/control/ref/icare.html |
19 | | -% [2] https://tamaskis.github.io/documentation/Fixed_Step_ODE_Solvers.pdf |
20 | | -% [3] https://github.com/tamaskis/ODE_Solver_Toolbox-MATLAB |
21 | | -% [4] Lavretsky and Wise, "Robust and Adaptive Control with Aerospace |
22 | | -% Applications" (p. 35) |
23 | | -% [5] https://en.wikipedia.org/wiki/Linear-quadratic_regulator |
24 | | -% |
25 | | -% This function requires the ODE Solver Toolbox: |
26 | | -% https://www.mathworks.com/matlabcentral/fileexchange/103975-ode-solver-toolbox |
| 17 | +% DEPENDENCIES: |
| 18 | +% --> IVP Solver Toolbox (https://www.mathworks.com/matlabcentral/fileexchange/103975-ivp-solver-toolbox) |
27 | 19 | % |
28 | 20 | %-------------------------------------------------------------------------- |
29 | 21 | % |
|
72 | 64 | % ---------------------- |
73 | 65 | % Determines dimensions. |
74 | 66 | % ---------------------- |
75 | | - |
| 67 | + |
76 | 68 | % state dimension |
77 | 69 | n = size(A,1); |
78 | | - |
| 70 | + |
79 | 71 | % input dimension |
80 | 72 | m = size(B,2); |
81 | | - |
| 73 | + |
82 | 74 | % ---------------------------------------------------- |
83 | 75 | % Sets unspecified parameters to their default values. |
84 | 76 | % ---------------------------------------------------- |
85 | | - |
| 77 | + |
86 | 78 | % defaults cross-coupling matrix to 0 |
87 | 79 | if isempty(S) |
88 | 80 | S = zeros(n,m); |
89 | 81 | end |
90 | | - |
| 82 | + |
91 | 83 | % --------- |
92 | 84 | % Solution. |
93 | 85 | % --------- |
94 | | - |
| 86 | + |
95 | 87 | % flips tspan so the Riccati ODE is solved backwards in time |
96 | 88 | tspan = fliplr(tspan); |
97 | | - |
| 89 | + |
98 | 90 | % defines Riccati ODE has a matrix-valued ODE |
99 | 91 | dPdt = @(t,P) -(A.'*P+P*A-(P*B+S)/R*(B.'*P+S.')+Q); |
100 | | - |
| 92 | + |
101 | 93 | % converts matrix-valued ODE to vector-valued ODE |
102 | 94 | dydt = odefun_mat2vec(dPdt); |
103 | | - |
| 95 | + |
104 | 96 | % converts matrix initial condition to vector initial condition |
105 | | - yT = odeIC_mat2vec(PT); |
| 97 | + yT = ivpIC_mat2vec(PT); |
106 | 98 |
|
107 | 99 | % solves Riccati ODE |
108 | 100 | [t,y] = ode45(dydt,tspan,yT); |
109 | | - |
| 101 | + |
110 | 102 | % transforms solution matrix for vector-valued ODE into solution array |
111 | 103 | % for matrix-valued ODE |
112 | | - P = odesol_vec2mat(y); |
113 | | - |
| 104 | + P = ivpsol_vec2mat(y); |
| 105 | + |
114 | 106 | % reorders t so that time is increasing |
115 | 107 | t = flipud(t); |
116 | | - |
| 108 | + |
117 | 109 | % reorders solution for P |
118 | 110 | P_reordered = zeros(size(P)); |
119 | 111 | for k = 1:length(t) |
|
0 commit comments