![tmp.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/222629/tmp.png)
Trouble with time delay differential equation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
%% 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 comentarios
Respuestas (1)
David Wilson
el 4 de Jun. de 2019
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/222629/tmp.png)
2 comentarios
Torsten
el 4 de Jun. de 2019
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)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!