switched system with time delay

조회 수: 3 (최근 30일)
amani alsulami
amani alsulami 2019년 11월 12일
답변: amani alsulami 2019년 11월 22일
please to help me. plot the switched system with time delay in matlab, but code is error???
error_.jpg
function ddestat
tau=[0.2];
tspan = [0 400];
history = [0.333,0,083];
T = [];
Y = [];
Z=[];
IE = 1;
ti=6;
while IE == 1
options = ddeset('Events',@switched);
[Thelp,Yhelp,Zhelp,TE,YE,ZE,IE]= dde23(@ddefun ,tau,history,tspan,options,ti);
history=YE;
tau=ZE;
t0=TE;
ti=TE+9;
plot(Thelp(:),Yhelp(:,1),'g','LineWidth',1)
hold on
% plot(Thelp(:),Yhelp(:,2),'g','LineWidth',1)
% hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Thelp,Yhelp,Zhelp,TE,YE,ZE,IE]= dde23(@ddefunn , tau, history,tspan,options,ti);
history=YE;
tau=ZE;
t0=TE;
ti=TE+9;
plot(Thelp(:),Yhelp(:,1),'k','LineWidth',1)
hold on
%plot(Thelp(:),Yhelp(:,2),'k','LineWidth',1)
%hold on
end
end
function v = ddefun(t,y,ti,Z) % equation being solved
ylag1 = Z(:,1);
v=zeros(2,1);
v(1) = y(2)+0.08*ylag1(1)+0.02*ylag1(2)+0.125*ylag1(1)^2+0.12*ylag1(2)^2;
v(2)= y(1)+0.04*ylag1(1)+0.05*ylag1(2)+0.25*sin(y(1));
end
function v = ddefunn(t,y,ti,Z) % equation being solved
ylag1=Z(:,1);
v=zeros(2,1);
v(1) = -3*y(1)+2*y(2)+0.05*ylag1(1)+0.02*ylag1(2)+0.25*y(1)*y(2);
v(2)= 2*y(1)-3*y(2)+0.03*ylag1(1)+0.07*ylag1(2)+0.125*ylag1(2)^2+0.25*y(2);
end
%-------------------------------------------
function [value,isterminal,direction] = events(t,y,ti,Z)
value = t-ti; isterminal = 1;
direction = 1;
end

답변 (2개)

Mahesh Taparia
Mahesh Taparia 2019년 11월 22일
Hi Amani,
There are some bugs in your code which needs to be fixed in order to run the script.
  1. Variable history should be 1X2 vector, you have created 1X3.
  2. In function ddefun/ ddefunn you have defined ylag1 as a scalar value, but you are using as a vector.
  3. Function dde23 returns structure not an array. So, update the parameters as per your formula by taking the variables from struct.
For your reference you can see a modified version of your code, it may not be correct because you have to update the parameters which are stored in ‘vb’.
Run this script by putting break points in the code and update the parameters.
function vc= ddestat
tau=[0.2];
tspan = [0 400];
history = [0.333,0.083];
T = [];
Y = [];
Z=[];
IE = 1;
ti=6;
while IE == 1
options = ddeset('Events',@switched);
vb= dde23(@ddefun ,tau,history,tspan,ti);
%[Thelp,Yhelp,Zhelp,TE,YE,ZE,IE]= dde23(@ddefun ,tau,history,tspan,options,ti);
history=vb.history;
% tau=ZE; %%%%%%%% UPDATE the new parameters
% t0=TE;
% ti=TE+9;
% plot(Thelp(:),Yhelp(:,1),'g','LineWidth',1)
% hold on
% % plot(Thelp(:),Yhelp(:,2),'g','LineWidth',1)
% hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%[Thelp,Yhelp,Zhelp,TE,YE,ZE,IE]= dde23(@ddefunn , tau, history,tspan,options,ti);
vc= dde23(@ddefunn , tau, history,tspan,ti);
% history=YE;
% tau=ZE;
% t0=TE;
% ti=TE+9;
% plot(Thelp(:),Yhelp(:,1),'k','LineWidth',1)
% hold on
%plot(Thelp(:),Yhelp(:,2),'k','LineWidth',1)
%hold on
end
end
function v = ddefun(t,y,ti,Z) % equation being solved
ylag1 =[6 6]; %%%taken as example put correct value
v=zeros(2,1);
v(1) = y(2)+0.08*ylag1(1)+0.02*ylag1(2)+0.125*ylag1(1)^2+0.12*ylag1(2)^2;
v(2)= y(1)+0.04*ylag1(1)+0.05*ylag1(2)+0.25*sin(y(1));
end
function v = ddefunn(t,y,ti,Z) % equation being solved
ylag1=[6 6];%%%%taken as example put correct value
v=zeros(2,1);
v(1) = -3*y(1)+2*y(2)+0.05*ylag1(1)+0.02*ylag1(2)+0.25*y(1)*y(2);
v(2)= 2*y(1)-3*y(2)+0.03*ylag1(1)+0.07*ylag1(2)+0.125*ylag1(2)^2+0.25*y(2);
end
%-------------------------------------------
function [value,isterminal,direction] = events(t,y,ti,Z)
value = t-ti; isterminal = 1;
direction = 1;
end
Hope it will helps.

amani alsulami
amani alsulami 2019년 11월 22일
Thanks

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by