Numerical Methods for Singular systems
4 ビュー (過去 30 日間)
古いコメントを表示
Could you please take a look at the code I wrote for the delayed singular system class and let me know if it's correct? Thank you all in advance!

%% Phase plane
clear all
clc
%% conditions
A_x=[0.5 0.7 -0.5;0.8 1.5 0.2; 0.9 0.8 0.3];
A_d=[1.6 0.58 0.4;0.96 1.7 0.8;0.5 0.8 0.45];
B=[1.4;0.5; 0.7];
stime=0;
endtime=600;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0;
x2(:,i)=0;
x3(:,i)=0;
else
d_1=floor(1.5+sin(0.5*i*h));
if i<=3
x1(:,i)=x1(:,i-1)+h*(A_x(1,1)*x1(:,i-1)+A_x(1,2)*x2(:,i-1)+A_x(1,3)*x3(:,i-1)+B(1,1)*sin(0.5*i));
x2(:,i)=x2(:,i-1)+h*(A_x(2,1)*x1(:,i-1)+A_x(2,2)*x2(:,i-1)+A_x(2,3)*x3(:,i-1)+B(2,1)*sin(0.5*i));
x3(:,i)=-inv(A_x(3,3))*(A_x(3,1)*x1(:,i)+A_x(3,2)*x2(:,i)+B(3,1)*sin(0.5*i));
else
x1(:,i)=x1(:,i-1)+h*(A_x(1,1)*x1(:,i-1)+A_x(1,2)*x2(:,i-1)+A_x(1,3)*x3(:,i-1)+A_d(1,1)*x1(:,i-d_1-1)+A_d(1,2)*x2(:,i-d_1-1)+A_d(1,3)*x3(:,i-d_1-1)+B(1,1)*sin(0.5*i));
x2(:,i)=x2(:,i-1)+h*(A_x(2,1)*x1(:,i-1)+A_x(2,2)*x2(:,i-1)+A_x(2,3)*x3(:,i-1)+A_d(2,1)*x1(:,i-d_1-1)+A_d(2,2)*x2(:,i-d_1-1)+A_d(2,3)*x3(:,i-d_1-1)+B(2,1)*sin(0.5*i));
x3(:,i)=-inv(A_x(3,3))*(A_x(3,1)*x1(:,i)+A_x(3,2)*x2(:,i)+A_d(3,1)*x1(:,i-d_1)+A_d(3,2)*x2(:,i-d_1)+A_d(3,3)*x3(:,i-d_1)+B(3,1)*sin(0.5*i));
end
end
end
%% Plotting Graphs
figure(1)
% grid on
% hold on
% box on
plot(t,x1(1,:),'b-','linewidth',1)
hold on
plot(t,x2(1,:),'r:','linewidth',2)
plot(t,x3(1,:),'r:','linewidth',2)
xlabel('Time (t)')
%ylabel('Responses x(t)')
legend('x_{1}(t)','x_{2}(t)');
% xlim([0,1000]);
% %ylim([-0.2,0.8]);
%
0 件のコメント
採用された回答
Torsten
2025 年 4 月 21 日
編集済み: Torsten
2025 年 4 月 21 日
The loop index i does not equal time t. So expressions like
d_1=floor(1.5+sin(0.5*i*h));
x1(:,i-d_1-1)
x2(:,i-d_1-1)
x3(:,i-d_1-1)
sin(0.5*i)
in your code are clearly wrong.
Up to t ~ 2.43, the delay part is zero, and the results should be the same as with the code below. It can serve as validation code for your results after you've made the necessary corrections.
M = [1 0 0;0 1 0;0 0 0];
A = [0.5 0.7 -0.5;0.8 1.5 0.2; 0.9 0.8 0.3];
B = [1.4;0.5; 0.7];
tstart = 0;
tend = 2.43;
tspan = [tstart,tend];
f = @(t,y)A*y+B*sin(0.5*t);
y0 = [0;0;0];
options = odeset('Mass',M);
[T,Y] = ode15s(f,tspan,y0,options);
plot(T,Y)
grid on
7 件のコメント
Torsten
2025 年 4 月 24 日
You post your questions about code for delay differential equations for almost one year now, but it seems you don't make any progress (at least in the programming part). It's not possible to give solutions to obvious homework problems, but you should enhance your programming skills: try MATLAB Onramp - an introduction to MATLAB free of costs to learn the basics of the new language:
その他の回答 (1 件)
Walter Roberson
2025 年 4 月 21 日
if i<=N_0+1;
x1(:,i)=0;
x2(:,i)=0;
x3(:,i)=0;
else
d_1=floor(1.5+sin(0.5*i*h));
if i<=3
This smells like you forgot the "end" for the first "if". In MATLAB, nesting is not determined by indentation.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

