Numerical Methods for Singular systems

3 Ansichten (letzte 30 Tage)
Le
Le am 21 Apr. 2025
Kommentiert: Le am 25 Apr. 2025
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]);
%

Akzeptierte Antwort

Torsten
Torsten am 21 Apr. 2025
Bearbeitet: Torsten am 21 Apr. 2025
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 Kommentare
Torsten
Torsten am 24 Apr. 2025
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:
Le
Le am 25 Apr. 2025
ok, thank you @Torsten so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 21 Apr. 2025
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.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by