what's wrong my code about ode model

조회 수: 2 (최근 30일)
기훈 강
기훈 강 2023년 4월 21일
편집: Torsten 2023년 4월 21일
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
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
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]);
Unrecognized function or variable 'Cprime'.

Error in solution>ode_fun (line 53)
f_C = min(r_C * (1 - C / Cprime), r_max);

Error in solution>@(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]) (line 24)
[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]);

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
% 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개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by