Numerical Methods for Singular systems
Afficher commentaires plus anciens
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]);
%
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 21 Avr 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.
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

