필터 지우기
필터 지우기

Trouble with time delay differential equation

조회 수: 1 (최근 30일)
Debanita Das
Debanita Das 2019년 6월 3일
댓글: Torsten 2019년 6월 4일
%% 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.

답변 (1개)

David Wilson
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?
tmp.png
  댓글 수: 2
Debanita Das
Debanita Das 2019년 6월 4일
Thank you so much for your help.
Yes the graph should look like this.
Query: The equation demands a lag of 4.9. Shouldn't I place it in the code?
Torsten
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by