Skip to content

Commit ce1f8de

Browse files
committed
Updated matrix ODE examples and documentation
1 parent 05a419d commit ce1f8de

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

INSTALL/ODE Solver Toolbox.mltbx

66 Bytes
Binary file not shown.

examples/example_matrix_ode.m

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% equation).
66
%
77
% Copyright © 2021 Tamas Kis
8-
% Last Update: 2021-12-22
8+
% Last Update: 2021-12-23
99
% Website: https://tamaskis.github.io
1010
% Contact: tamas.a.kis@outlook.com
1111

@@ -75,44 +75,25 @@
7575

7676

7777

78-
% %% SOLVING RICCATI DIFFERENTIAL EQUATION USING ONE-STEP PROPAGATION
79-
%
80-
% % time vector between t = 5 and t = 0 with a spacing of h = 0.001.
81-
% h = -0.001;
82-
% t = (5:h:0)';
83-
%
84-
% % preallocate vector to store solution
85-
% P = zeros(2,2,length(t));
86-
%
87-
% % store initial condition
88-
% P(:,:,1) = PT;
89-
%
90-
% % solving using "RK4_step"
91-
% for i = 1:(length(t)-1)
92-
% P(:,:,i+1) = RK4_step(F,t(i),P(:,:,i),h);
93-
% end
94-
%
95-
% % solution for P0 using one-step propagation
96-
% P0_step = P(:,:,end);
97-
%
98-
% % maximum absolute error between the two results (should be 0)
99-
% max(abs(P0-P0_step),[],'all')
100-
101-
102-
%% test
103-
Pinf = icare(A,B,Q,R);
104-
P_norm = zeros(size(t));
105-
for i = 1:length(t)
106-
P_norm(i) = norm(P(:,:,i),'fro');
78+
%% SOLVING RICCATI DIFFERENTIAL EQUATION USING ONE-STEP PROPAGATION
79+
80+
% time vector between t = 5 and t = 0 with a spacing of h = 0.001.
81+
h = -0.001;
82+
t = (5:h:0)';
83+
84+
% preallocate vector to store solution
85+
P = zeros(2,2,length(t));
86+
87+
% store initial condition
88+
P(:,:,1) = PT;
89+
90+
% solving using "RK4_step"
91+
for i = 1:(length(t)-1)
92+
P(:,:,i+1) = RK4_step(F,t(i),P(:,:,i),h);
10793
end
10894

109-
figure;
110-
hold on;
111-
plot(t,P_norm,'LineWidth',1.5);
112-
plot(t,norm(Pinf,'fro')*ones(size(t)),'k--','LineWidth',1.5);
113-
hold off;
114-
grid on;
115-
xlabel('$t$','interpreter','latex','fontsize',18);
116-
ylabel('$\|\mathbf{P}\|_{\mathrm{F}}$','interpreter','latex','fontsize',18);
117-
legend('$\mathbf{P}(t)$','$\mathbf{P}_{\infty}$','interpreter','latex','fontsize',14,'location','southeast');
118-
hold off;
95+
% solution for P0 using one-step propagation
96+
P0_step = P(:,:,end);
97+
98+
% maximum absolute error between the two results (should be 0)
99+
max(abs(P0-P0_step),[],'all')

0 commit comments

Comments
 (0)