Using identical delay and length of integration domain for delay model (dde23)

2 views (last 30 days)
Marom Yossef
Marom Yossef on 15 Mar 2022
Edited: Marom Yossef on 15 Mar 2022
Hi,
I've been trying to contsruct a biological process that is influenced by a drug every week, and causes few components of the immune system to react only 7-14 days later. Thus, the model consists a for loop with index of the number of weeks, and lags array for the delay. The results do differ from the model without delay, but if I change delay of 7 days to 14 days I get the same solution.
Is there any problem with my code? I just can't think of another option to model treatment without using for loop, but to me it seems that in this code there is something wrong with "retrieving" the history 7 or 14 days back. Thank you.
clc
a=6;
b=10;
c=9;
lags = [7 ];
y0 = [ 200 9.5*5*10^3 0.5*5*10^3 10^3 100 100];
tspan =[0,6/24];
n_weeks =6;
opt = odeset('AbsTol',1e-9,'RelTol',1e-6);
for i=1:3
sol =dde23(@(t,y,Z)ddefun(t,y,Z,a,b,c),lags,y0,tspan,opt);
semilogy(sol.x,sol.y(1,:),'r',sol.x,sol.y(2,:),'k',sol.x,sol.y(3,:),'b',sol.x,sol.y(4,:),'m',sol.x,sol.y(5,:),'g',sol.x,sol.y(6,:),'y')
legend('1','2','3','4','5','6')
xlabel('Time t');
ylabel('Solution y');
hold on
y0=sol.y(:,end);
tspan = [7*(i-1)+6/24,7*(i-1)+22/24];
m1=0;
sol =dde23(@(t,y,Z)ddefun(t,y,Z,a,b,c),lags,y0,tspan,opt);
semilogy(sol.x,sol.y(1,:),'r',sol.x,sol.y(2,:),'k',sol.x,sol.y(3,:),'b',sol.x,sol.y(4,:),'m',sol.x,sol.y(5,:),'g',sol.x,sol.y(6,:),'y')
legend('1','2','3','4','5','6')
xlabel('Time t');
ylabel('Solution y');
hold on
y0=sol.y(:,end);
mu1=0;
m1=0;
tspan = [7*(i-1)+22/24,7*i];
sol =dde23(@(t,y,Z)ddefun(t,y,Z,a,b,c),lags,y0,tspan,opt);
semilogy(sol.x,sol.y(1,:),'r',sol.x,sol.y(2,:),'k',sol.x,sol.y(3,:),'b',sol.x,sol.y(4,:),'m',sol.x,sol.y(5,:),'g',sol.x,sol.y(6,:),'y')
legend('1','2','3','4','5','6')
xlabel('Time t');
ylabel('Solution y');
hold on
y0=sol.y(:,end);
tspan = [7*i,7*i+6/24];
end
hold off
%-------------------------------------------
function dydt = ddefun(t,y,Z,a,b,c) %equation being solved
ylag1 = Z(:,1);
dydt = [ a*y(1);
b*ylag1(2)*y(1);
c*y(1)+a*ylag1(3);%
y(4);
ylag1(5)*ylag1(6);
y(6)];%
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by