## Solving a differential equation

### Mangesh KAle (view profile)

on 18 Nov 2019 at 11:54
Latest activity Edited by Mangesh KAle

### Mangesh KAle (view profile)

on 18 Nov 2019 at 21:28

### Stephan (view profile)

I am looking for a reproducible code and I am trying my best to find the results but I am stuck after a stage!! Would be helpful if you can help me
I have a function given below which consist of 5 functions provided
I want to reproduce above equations in the below differential equations:
I need to graph the solution of these differential equations:
f1(G)=209/(1+e^(-G/300V3 +6.6)
f2(G)=72(1-e^(-G/144V3))
f3(G)=0.01G/V3
f4(I)=[90/(1+e^(-1.772log(I/V1) + 7.76))] +4
f5(I)=180/(1+e^(0.29I/V1 -7.5))
dG(t)/dt= Gin-f2(G(t))-f3(G(t))f4(I(t))+f5(I(t-T2))
d(I)/dt=f1(G(t))-I(t)/t1
d(I1(t))/dt= Qf1(G(t))-I(t)/t1 +(1-Q)f1(G(t-T1)
clear all;
clc;
V1=3;Gin=216;alpha=0.5;t1=6;V3=10;tau2=50;Eg=180;tau1=5;tau=[10,50];
sol = dde23(@eq24,[10,50],[210;1;80],[0, 50]);
figure(1)
plot(sol(1).x,sol(1).dy(1,:),sol(1).x,sol(1).dy(2,:),
sol(1).x,sol(1).dy(3,:))
function dy=eq24(~,y,Z)
V1=3; V3=10;
t1=6;
G=y(1);
I=y(2);
I1=y(3);
Glag1=Z(:,1); %Tau1%
Ilag2=Z(:,2); %Tau2%
f1=@(G) 209/(1+exp(-G/300*V3 +6.6));
f2=@(G) 72*(1-exp(-G/144*V3));
f3=@(G) 0.01*G/V3;
f4=@(I) 90/(1+exp(-1.772*log(I/V1) + 7.76)) +4;
f5= 180/(1+exp(0.29*I/V1 -7.5));
dy = zeros(3,1);
dy(1) = 216 - f2(G)-f3(G)*f4(I)+f5(Ilag2);
dy(2)=f1-(I/t1);
dy(3) = alpha*f1(G)-I1/t1 +(1-alpha)*f1(Glag1);
end

### Stephan (view profile)

on 18 Nov 2019 at 13:03
Edited by Stephan

### Stephan (view profile)

on 18 Nov 2019 at 13:07

Hi there were some bugs in this code - see my comments
V1=3;
Gin=216;
alpha=0.5;
t1=6;
V3=10;
tau2=50;
Eg=180;
tau1=5;
tau=[10,50];
sol = dde23(@(t,y,Z)eq24(t,y,Z,alpha),[10,50],[210;1;80],[0, 50]); % Added alpha in function call
% Plotting the solution works by using deval
tint = linspace(0,50);
yint = deval(sol,tint);
figure(1)
plot(tint,yint);
%plot(sol(1).x,sol(1).dy(1,:),sol(1).x,sol(1).dy(2,:),sol(1).x,sol(1).dy(3,:))
function dy=eq24(~,y,Z,alpha) ´% I added alpha as input argument
V1=3;
V3=10;
t1=6;
G=y(1);
I=y(2);
I1=y(3);
Glag1=Z(:,1); %Tau1%
Ilag2=Z(:,2); %Tau2%
f1=@(G) 209/(1+exp(-G/300*V3 +6.6));
f2=@(G) 72*(1-exp(-G/144*V3));
f3=@(G) 0.01*G/V3;
f4=@(I) 90/(1+exp(-1.772*log(I/V1) + 7.76)) +4;
f5=@(I) 180/(1+exp(0.29*I/V1 -7.5)); % I changed f5=180... to f5=@(I) 180...
dy = zeros(3,1);
dy(1) = 216 - f2(G)-f3(G)*f4(I)+f5(Ilag2(1)); % I changed f5(Ilag2) to f5(Ilag2(1))
dy(2)= f1(G)-(I/t1);
dy(3) = alpha*f1(G)-I1/t1 +(1-alpha)*f1(Glag1(3)); % I changed f1(Glag1) to f1(Glag1(3))
end
The most fixes i made are just simple syntax problems - except the last two changes. The problem is that Ilag2 and Glag1 are of size 1x3 so that no scalar values result by using them the way you did it. Ensure that especially the last two changes can be correct, because i have no insight in your problem. But this is a working code, which has only to be checked for the correct usage of the lag variables.
BTW: You deleted all the content of your other question related to the glucose insuline model. Why? Did you notice that you can accept and/or vote for useful answers?