
Trouble with time delay differential equation
1 回表示 (過去 30 日間)
古いコメントを表示
%% ddex1_func
function dYdt = ddex1_func(t,Y,Z)
a=8.5; b=-9.5; c=-1; d=4.55;
y1=Y(1);y2=Y(2);
y1_tau1 = Z(1,4.9);
y2_tau1 = Z(2,4.9);
dy1dt = a*y1*(1-y1) + b*y1*y2;
dy2dt = c*y2 + d*y1_tau1*y2_tau1;
dYdt = [dy1dt; dy2dt];
%% ddex1
clc;close all;clear all;
lags = [4.9];
tspan = [0 200];
sol = dde23(@ddex1_func,lags,@history,tspan)
y1 = sol.y(1,:); % note the y-solution is a row-wise matrix.
y2 = sol.y(2,:);
plot(y1,y2)
xlabel('y_1')
ylabel('y_2')
%% history
function y = history(t)
y = [0.5;0.4];
end
>> The error that shows is: Attempted to access Z(1,4.9); index must be a positive integer or logical.
>>Error in ddex1_func (line 5)
>>y1_tau1 = Z(1,4.9);
Can anyone help me rectify my mistake? The moment I replace 4.9 with 1 (wherever required i.e Z(:,4.9), lags=[4.9]), it provides a periodic graph, whereas 4.9 (which should have given aperiodic graph) yields error. I couldn't understand the logic behind the error.
0 件のコメント
回答 (1 件)
David Wilson
2019 年 6 月 4 日
I've only made one small change to your function. You have tried to index a non-integer number back, but the "Z" variable holds the values.
function dYdt = ddex1_func(t,Y,Z)
a=8.5; b=-9.5; c=-1; d=4.55;
y1=Y(1);y2=Y(2);
%y1_tau1 = Z(1,4.9);
%y2_tau1 = Z(2,4.9);
y1_tau1 = Z(1,1);
y2_tau1 = Z(2,1);
dy1dt = a*y1*(1-y1) + b*y1*y2;
dy2dt = c*y2 + d*y1_tau1*y2_tau1;
dYdt = [dy1dt; dy2dt];
return
Does this look like something you are expecting?

2 件のコメント
Torsten
2019 年 6 月 4 日
Query: The equation demands a lag of 4.9. Shouldn't I place it in the code?
You implemented it in your code by setting
lags = [4.9];
and calling dde23 as
sol = dde23(@ddex1_func,lags,@history,tspan)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!