what's wrong my code about ode model
1 次查看(过去 30 天)
显示 更早的评论
I wirte this code 'ode_fun'
function dydt = ode_fun(t, y, params)
% Unpack the input variables
C = y(1);
A = y(2);
I = y(3);
E = y(4);
S = y(5);
% Unpack the parameter values
k = params(1);
r_C = params(2);
r_max = params(3);
r_A = params(4);
delta_A = params(5);
r_I = params(6);
delta_I = params(7);
r_E = params(8);
Eprime = params(9);
beta = params(10);
gamma = params(11);
r_S = params(12);
Sprime = params(13);
% Compute f(C)
f_C = min(r_C * (1 - C / Cprime), r_max);
% Compute the derivatives
dCdt = f_C * C - k * C * E;
dAdt = r_A * C - delta_A * A;
dIdt = r_I * C * E - delta_I * I;
dEdt = -r_E * (E - Eprime) + beta * A * I * E * S - gamma * E * S;
dSdt = -r_S * (S - Sprime) - beta * A * I * E * S + gamma * E * S;
% Pack the output variables into dydt
dydt = [dCdt; dAdt; dIdt; dEdt; dSdt];
end
but this code doesn't work
This code has problem about line4
And say that Insufficient input arguments.
So, I don't use next code..
% Define the parameter values
k = 1.2; %killing rate of cancer cells by T cells
r_C = 1/1.0; % Logistic growth rate of cancer
r_max = 1/0.09; % Maximum growth rate of cancer
r_A = 0.5; % Antigen presentatation source rate
delta_A = 1/0.8; % Antigen presentatation degradation rate
r_I = 0.4; % Inflammation source rate
delta_I = 1/3.0; % Inflammation degradation rate
r_E = 1/1.0; % Effector T cell growth coefficient
Eprime = 5.0; % Effector T cell base steady state
beta = 0.009; % Effector T cell recruitment coefficient
gamma = 37.414; % Non-effector T cell recruitment coefficient
r_S = 1/1.0; % Non-effector T cell growth coefficient
Sprime = 5.0; % Non-effector T cell base steady state
% Define the initial conditions
C0 = 1.0;
A0 = 0.0;
I0 = 0.0;
E0 = 0.5;
S0 = 4.5;
% Define the time span
tspan = [0 50];
% Solve the ODE system
[t,y] = ode45(@(t,y) ode_fun(t,y,k,r_C,r_max,r_A,delta_A,r_I,delta_I,r_E,Eprime,beta,gamma,r_S,Sprime),tspan,[C0 A0 I0 E0 S0]);
% Plot the results
figure
plot(t,y(:,1),'LineWidth',2)
xlabel('Time')
ylabel('Cancer Cells')
title('Cancer Growth Over Time')
I want to run this code but I don't know how to write it. Any help please?
1 个评论
Dyuman Joshi
2023-4-21
1 - The ODE function goes at the bottom of the code if your code is a script.
2 - You are passing all the variables from k to S_prime to the ODE function, but your syntax is incorrect. Either define the array params using the variables or pass each variable directly.
3 - You have not defined the variable C_prime.
采纳的回答
Torsten
2023-4-21
编辑:Torsten
2023-4-21
What is Cprime ?
% Define the parameter values
k = 1.2; %killing rate of cancer cells by T cells
r_C = 1/1.0; % Logistic growth rate of cancer
r_max = 1/0.09; % Maximum growth rate of cancer
r_A = 0.5; % Antigen presentatation source rate
delta_A = 1/0.8; % Antigen presentatation degradation rate
r_I = 0.4; % Inflammation source rate
delta_I = 1/3.0; % Inflammation degradation rate
r_E = 1/1.0; % Effector T cell growth coefficient
Eprime = 5.0; % Effector T cell base steady state
beta = 0.009; % Effector T cell recruitment coefficient
gamma = 37.414; % Non-effector T cell recruitment coefficient
r_S = 1/1.0; % Non-effector T cell growth coefficient
Sprime = 5.0; % Non-effector T cell base steady state
% Define the initial conditions
C0 = 1.0;
A0 = 0.0;
I0 = 0.0;
E0 = 0.5;
S0 = 4.5;
% Define the time span
tspan = [0 50];
% Solve the ODE system
[t,y] = ode45(@(t,y) ode_fun(t,y,[k,r_C,r_max,r_A,delta_A,r_I,delta_I,r_E,Eprime,beta,gamma,r_S,Sprime]),tspan,[C0 A0 I0 E0 S0]);
% Plot the results
figure
plot(t,y(:,1),'LineWidth',2)
xlabel('Time')
ylabel('Cancer Cells')
title('Cancer Growth Over Time')
function dydt = ode_fun(t, y, params)
% Unpack the input variables
C = y(1);
A = y(2);
I = y(3);
E = y(4);
S = y(5);
% Unpack the parameter values
k = params(1);
r_C = params(2);
r_max = params(3);
r_A = params(4);
delta_A = params(5);
r_I = params(6);
delta_I = params(7);
r_E = params(8);
Eprime = params(9);
beta = params(10);
gamma = params(11);
r_S = params(12);
Sprime = params(13);
% Compute f(C)
f_C = min(r_C * (1 - C / Cprime), r_max);
% Compute the derivatives
dCdt = f_C * C - k * C * E;
dAdt = r_A * C - delta_A * A;
dIdt = r_I * C * E - delta_I * I;
dEdt = -r_E * (E - Eprime) + beta * A * I * E * S - gamma * E * S;
dSdt = -r_S * (S - Sprime) - beta * A * I * E * S + gamma * E * S;
% Pack the output variables into dydt
dydt = [dCdt; dAdt; dIdt; dEdt; dSdt];
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!