How i use break in continues data in couple differential? it is possible?
Show older comments
Hello, this is my code for a diseases and I want to know the effect of drugs (blue line) if I stoped from days 30-60 and continue with microglia from days 60-180. It's use break code or anything else?
clc;clear;
%parameter
delta=50;
gamma=75;
K1=10^-4;
K2=5*10^-4;
K3=10^-3;
K4=5*10^-3;
K5=10^-2;
K6=5*10^-2;
Ko=0.1;
n=6;
Oa=10;
Pa=100;
mu_1=10^-3;
mu_2=10^-3;
mu_3=10^-3;
mu_4=10^-3;
mu_5=10^-3;
mu_6=10^-3;
mu_o=10^-4;
mu_p= 10^-5;
%input for time
t(1)=0;
dt=0.01; %time interval
t=0:dt:180; %time span
%component for microglia ---> This is component for microglia
Mg = 0.047;
lambdaMf = 5*10^-2;
Fo = 3.36*10^-11;
KFo = 2.58*10^-11;
lambdaMa = 2.23*10^-2;
Ao = 0.14;
KAo = 10^-7;
beta = 10;
epsilon1 = 0.3333;
epsilon2 = 0.8;
lambdaM1Tb = 6*10^-3;
Tb=10^-6;
KTb = 2.5*10^-7;
macro1 = 0.02;
macro2 = 0.02;
dM1= 0.015;
dM2= 0.015;
tmacro1 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon1*beta/beta*(epsilon1+epsilon2)))-(lambdaM1Tb*(Tb/(Tb+KTb)*macro1))-(dM1*macro1);
tmacro2 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon2/beta*(epsilon1+epsilon2)))+(lambdaM1Tb*(Tb/(Tb+KTb))*macro1)-(dM2*macro2);
%component drugs --> This is component for drugs
Abi = 10^-6;
lambdaN = 8*10^-4;
lambdaA = 8*10^-4;
daboM = 2*10^-3; %clearance rate by microglia
dabom = 10^-2; %clearance rate by macrophages
macrofag1 = 0;
macrofag2 = 0;
micro1 = 0.02;
micro2 = 0.02;
teta = 0.9;
h = 10;
Kaob = 7*10^-3;
AoB = 10^-8;
dtdab = Abi*(dt*(0.14*1.9*10^-4*exp(-1.9*10^-4)))+ (lambdaN*1)+(lambdaA*1)-(dabom*(macrofag1+(teta*macrofag2))+daboM*(micro1+(teta*micro2))*(1+h))*(AoB/(AoB+Kaob));
%macro for macrofag and micro for microglia and each other is not same
%initial condition with microglia --> Initial condition for microglia
M1(1)=10;
M2(1)=0;
M3(1)=0;
M4(1)=0;
M5(1)=0;
M6(1)=0;
O(1)=0;
P(1)=0;
%initial condition without drugs --> Initial condition for without drugs and microglia
M12(1)=10;
M22(1)=0;
M32(1)=0;
M42(1)=0;
M52(1)=0;
M62(1)=0;
O2(1)=0;
P2(1)=0;
%initial condition with drugs --> Intial condition with drugs
M14(1)=10;
M24(1)=0;
M34(1)=0;
M44(1)=0;
M54(1)=0;
M64(1)=0;
O4(1)=0;
P4(1)=0;
%empty array with microglia --> Array for Microglia
T=zeros(length(t)+1,1); %empty array for t
M1=zeros(length(t)+1,1); %empty array for M1
M2=zeros(length(t)+1,1); %empty array for M2
M3=zeros(length(t)+1,1); %empty array for M3
M4=zeros(length(t)+1,1); %empty array for M4
M5=zeros(length(t)+1,1); %empty array for M5
M6=zeros(length(t)+1,1); %empty array for M6
O=zeros(length(t)+1,1); %empty array for O
P=zeros(length(t)+1,1); %empty array for P
sumter=K2*M2+K3*M3+K4*M4+K5*M5;
%empty array without drugs --> Array for without Drugs and Microglia
M12=zeros(length(t)+1,1); %empty array for M1
M22=zeros(length(t)+1,1); %empty array for M2
M32=zeros(length(t)+1,1); %empty array for M3
M42=zeros(length(t)+1,1); %empty array for M4
M52=zeros(length(t)+1,1); %empty array for M5
M62=zeros(length(t)+1,1); %empty array for M6
O2=zeros(length(t)+1,1); %empty array for O
P2=zeros(length(t)+1,1); %empty array for P
sumter2=K2*M22+K3*M32+K4*M42+K5*M52;
%empty array with drugs --> Array for drugs
M14=zeros(length(t)+1,1); %empty array for M1
M24=zeros(length(t)+1,1); %empty array for M2
M34=zeros(length(t)+1,1); %empty array for M3
M44=zeros(length(t)+1,1); %empty array for M4
M54=zeros(length(t)+1,1); %empty array for M5
M64=zeros(length(t)+1,1); %empty array for M6
O4=zeros(length(t)+1,1); %empty array for O
P4=zeros(length(t)+1,1); %empty array for P
sumter2=K2*M24+K4*M34+K4*M44+K5*M54;
for j = 1:length(t)
%with microglia (This component give the black line)
T(j+1)=T(j)+dt;
M1(j+1)=M1(j)+1./(1+exp(-T(j)));
M1(j+1) = M1(j)+(dt*(delta*M1(j+1)*(1-(M1(j+1)/gamma))-2*K1*M1(j+1)*M1(j+1)-M1(j+1)*sumter(j+1))-((Oa-n)*K6*M1(j+1)*M6(j+1))-((Pa-Oa)*Ko*M1(j+1)*O(j+1))-(mu_1*M1(j+1)));
M2(j+1) = M2(j)+(dt*(K1*M1(j)*M1(j)-K2*M1(j)*M2(j))-(mu_2*M2(j+1))-tmacro1-tmacro2);
M3(j+1) = M3(j)+(dt*(K2*M1(j)*M2(j)-K3*M1(j)*M3(j))-mu_3*M3(j));
M4(j+1) = M4(j)+(dt*(K3*M1(j)*M3(j)-K4*M1(j)*M4(j))-mu_4*M4(j));
M5(j+1) = M5(j)+(dt*(K4*M1(j)*M4(j)-K5*M1(j)*M5(j))-mu_5*M5(j));
M6(j+1) = M6(j)+(dt*(K5*M1(j)*M5(j)-K6*M1(j)*M6(j))-mu_6*M6(j));
O(j+1) = O(j)+(dt*(K6*M1(j)*M6(j)-Ko*M1(j)*O(j)-mu_o*O(j)));
P(j+1) = P(j)+(dt*(Ko*M1(j)*O(j)-mu_p*P(j)));
%without drugs (This component give the red line)
T(j+1)=T(j)+dt;
M12(j+1) = M12(j)+1./(1+exp(-T(j)));
M12(j+1) = M12(j)+(dt*(delta*M12(j+1)*(1-(M12(j+1)/gamma))-2*K1*M12(j+1)*M12(j+1)-M12(j+1)*sumter2(j+1))-((Oa-n)*K6*M12(j+1)*M62(j+1))-((Pa-Oa)*Ko*M12(j+1)*O2(j+1))-(mu_1*M12(j+1)));
M22(j+1) = M22(j)+(dt*(K1*M12(j)*M12(j)-K2*M12(j)*M22(j))-(mu_2*M22(j+1)));
M32(j+1) = M32(j)+(dt*(K2*M12(j)*M22(j)-K3*M12(j)*M32(j))-mu_3*M32(j));
M42(j+1) = M42(j)+(dt*(K3*M12(j)*M32(j)-K4*M12(j)*M42(j))-mu_4*M42(j));
M52(j+1) = M52(j)+(dt*(K4*M12(j)*M42(j)-K5*M12(j)*M52(j))-mu_5*M52(j));
M62(j+1) = M62(j)+(dt*(K5*M12(j)*M52(j)-K6*M12(j)*M62(j))-mu_6*M62(j));
O2(j+1) = O2(j)+(dt*(K6*M12(j)*M62(j)-Ko*M12(j)*O2(j)-mu_o*O2(j)));
P2(j+1) = P2(j)+(dt*(Ko*M12(j)*O2(j)-mu_p*P2(j)));
%with drugs (This component give the blue line)
T(j+1)=T(j)+dt;
M14(j+1) = M14(j)+1./(1+exp(-T(j)));
M14(j+1) = M14(j)+(dt*(delta*M14(j+1)*(1-(M14(j+1)/gamma))-2*K1*M14(j+1)*M14(j+1)-M14(j+1)*sumter2(j+1))-((Oa-n)*K6*M14(j+1)*M64(j+1))-((Pa-Oa)*Ko*M14(j+1)*O4(j+1))-(mu_1*M14(j+1)));
M24(j+1) = M24(j)+(dt*(K1*M14(j)*M14(j)-K2*M14(j)*M24(j))-(mu_2*M24(j+1))-tmacro1-tmacro2-dtdab);
M34(j+1) = M34(j)+(dt*(K2*M14(j)*M24(j)-K3*M14(j)*M34(j))-mu_3*M34(j));
M44(j+1) = M44(j)+(dt*(K3*M14(j)*M34(j)-K4*M14(j)*M44(j))-mu_4*M44(j));
M54(j+1) = M54(j)+(dt*(K4*M14(j)*M44(j)-K5*M14(j)*M54(j))-mu_5*M54(j));
M64(j+1) = M64(j)+(dt*(K5*M14(j)*M54(j)-K6*M14(j)*M64(j))-mu_6*M64(j));
O4(j+1) = O4(j)+(dt*(K6*M14(j)*M64(j)-Ko*M14(j)*O4(j)-mu_o*O4(j)));
P4(j+1) = P4(j)+(dt*(Ko*M14(j)*O4(j)-mu_p*P4(j)));
end
figure
subplot (2,2,1)
plot( T,M12,'r',T,M1,'k',T,M14,'b','Linewidth',4) %M12 for without drugs, M1 for microglia, M14 for drugs
legend ('M1 without drugs','M1 with microglia', 'M1 with drugs');
%xticks ([60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080])
xticks ([30 60 90 120 150 180 ])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ('M1')
subplot (2,2,2)
plot(T,M22,'r',T,M2,'k',T,M24,'b','Linewidth',4) %M22 for without drugs, M2 for microglia, M24 for drugs
legend ('M2 without drugs','M2 with microglia','M2 with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([ 0 2 4 6 8 10 12 14 16])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ('M2')
subplot (2,2,3)
plot(T,M32,'r',T,M3,'k',T,M34,'b','Linewidth',4) %M32 for without drugs, M3 for microglia, M34 for drugs
legend ('M3 without drugs','M3 with microglia','M3 with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([0 0.5 1 1.5 2 2.5 3 3.5])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ('M3')
subplot (2,2,4)
plot(T,M42,'r',T,M4,'k',T,M44,'b','Linewidth',4) %M42 for without drugs, M4 for microglia, M44 for drugs
legend ('M4 without drugs','M4 with microglia', 'M4 with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([0 0.1 0.2 0.3 0.4 0.5])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ('M4')
figure
subplot (2,2,1)
plot(T,M52,'r',T,M5,'k',T,M54,'b','Linewidth',4) %M52 for without drugs, M1\5 for microglia, M54 for drugs
legend ('M5 without drugs','M5 with microglia', 'M5 with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([0 0.05 0.1 0.15 0.2])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ("M5")
subplot (2,2,2)
plot(T,M62,'r',T,M6,'k',T,M64,'b','Linewidth',4)%M62 for without drugs, M6 for microglia, M64 for drugs
legend ('M6 without drugs','M6 with microglia','M6 with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([0 0.01 0.02 0.03 0.04 ])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ("M6")
subplot (2,2,3)
plot(T,O2,'r',T,O,'k',T,O4,'b','Linewidth',4)%O2 for without drugs, O for microglia, O4 for drugs
legend ('O without drugs','O with microglia', 'O with drugs');
xticks ([30 60 90 120 150 180 ])
yticks ([0 0.005 0.01 0.015 0.02])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ("O")
subplot(2,2,4)
plot(T,P2,'r',T,P,'k',T,P4,'b','Linewidth',4)%P2 for without drugs, P for microglia, P4 for drugs
legend ('P without drugs','P microglia','P with drugs');
xticks ([30 60 90 120 150 180 ])
%yticks ([0 2 4 6 8 10 12])
xlabel('days','Fontsize',14,'FontWeight','bold')
ylabel('(g/mL)','Fontsize',14,'FontWeight','bold')
title ("P")
9 Comments
Sam Chak
on 18 May 2024
Because your code is rather lengthy, I suggest that you annotate sections of the code so that users can easily identify which section of the drug delivery dynamics produces the blue curve.
Additionally, please specify which parameters describe the introduction of the "drug" and "microglia" in the drug delivery system.
By the way, is ode45 solver allowed to solve drug delivery question?
cindyawati cindyawati
on 18 May 2024
Edited: cindyawati cindyawati
on 18 May 2024
cindyawati cindyawati
on 18 May 2024
Sam Chak
on 18 May 2024
Hi Cindy,
Can you provide the differential equations of the drug delivery system and the input variables for the drug and microglia?
It would be easier for me to read the math than the code. An image would be enough, no need to type it out in LaTeX format. Once the drug and microglia variables are identified, I can likely introduce a time-dependent state to specify when to cut off the drug intake and when to activate the microglia.
cindyawati cindyawati
on 18 May 2024
Edited: cindyawati cindyawati
on 18 May 2024
I have simulated the drug delivery system using the ode45 solver. However, I still cannot identify which input variables represent the drug and the microglia. I believe the system is incomplete, as I can see there are still 3 differential equations yet to be included in the system below. You have variables like tmacro1, tmacro2, dtdab, and I believe they are related to these 3 differential equations.
Can you please include them in the drugDeliverySystem(t, x) function?
dxdt(9) = ...
dxdt(10)= ...
dxdt(11)= ...
tspan = [0, 180]; % simulation time
M10 = 10;
M20 = 0;
M30 = 0;
M40 = 0;
M50 = 0;
M60 = 0;
O0 = 0;
P0 = 0;
x0 = [M10; M20; M30; M40; M50; M60; O0; P0]; % initial condition
[t, x] = ode45(@drugDeliverySystem, tspan, x0); % solve the system
plot(t, x), grid on, xlim([0, 180]) % plot results
xlabel('Days')
function dxdt = drugDeliverySystem(t, x)
dxdt = zeros(8, 1);
% definitions
M1 = x(1);
M2 = x(2);
M3 = x(3);
M4 = x(4);
M5 = x(5);
M6 = x(6);
O = x(7);
P = x(8);
% Parameters
delta = 50;
gamma = 75;
K1 = 10^-4;
K2 = 5*10^-4;
K3 = 10^-3;
K4 = 5*10^-3;
K5 = 10^-2;
K6 = 5*10^-2;
Ko = 0.1;
n = 6;
Oa = 10;
Pa = 100;
mu1 = 10^-3;
mu2 = 10^-3;
mu3 = 10^-3;
mu4 = 10^-3;
mu5 = 10^-3;
mu6 = 10^-3;
muo = 10^-4;
mup = 10^-5;
% ODEs
dxdt(1) = delta*M1*(1 - M1/gamma) - 2*K1*M1^2 - M1*(K2*M2 + K3*M3 + K4*M4 + K5*M5) - (Oa - n)*K6*M1*M6 - (Pa - Oa)*Ko*M1*O - mu1*M1;
dxdt(2) = K1*M1^2 - K2*M1*M2 - mu2*M2; % - tmacro1 - tmacro2 - dtdab
dxdt(3) = K2*M1*M2 - K3*M1*M3 - mu3*M3;
dxdt(4) = K3*M1*M3 - K4*M1*M4 - mu4*M4;
dxdt(5) = K4*M1*M4 - K5*M1*M5 - mu5*M5;
dxdt(6) = K5*M1*M5 - K6*M1*M6 - mu6*M6;
dxdt(7) = K6*M1*M6 - Ko*M1*O - muo*O;
dxdt(8) = Ko*M1*O - mup*P;
end
cindyawati cindyawati
on 18 May 2024
Thanks for your clarification.
Now, I understand you want the drug (dtdab) to be administered from Day 1 to 30, then stop the drug from Day 31 to 60, and bring it back from Day 61 to 180. As for the microglia (tmacro1 and tmacro2), they are only activated from Day 61 to 180. Please confirm if I have understood the requirements correctly.
tmacro1 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon1*beta/beta*(epsilon1+epsilon2)))-(lambdaM1Tb*(Tb/(Tb+KTb)*macro1))-(dM1*macro1)
tmacro2 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon2/beta*(epsilon1+epsilon2)))+(lambdaM1Tb*(Tb/(Tb+KTb))*macro1)-(dM2*macro2)
dtdab = Abi*(dt*(0.14*1.9*10^-4*exp(-1.9*10^-4)))+ (lambdaN*1)+(lambdaA*1)-(dabom*(macrofag1+(teta*macrofag2))+daboM*(micro1+(teta*micro2))*(1+h))*(AoB/(AoB+Kaob))
cindyawati cindyawati
on 18 May 2024
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







