- Variable history should be 1X2 vector, you have created 1X3.
- In function ddefun/ ddefunn you have defined ylag1 as a scalar value, but you are using as a vector.
- Function dde23 returns structure not an array. So, update the parameters as per your formula by taking the variables from struct.
switched system with time delay
19 ビュー (過去 30 日間)
古いコメントを表示
please to help me. plot the switched system with time delay in matlab, but code is error???

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
0 件のコメント
回答 (2 件)
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.
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!