How to set up two ODE functions in matlab

36 次查看(过去 30 天)
Hi,I am trying to set up two ode functions fot matlab to solve. The ODEs does not have any analytical solutions, but I want to get an numerical solution and plot in matlab. The equations are describing tumor growth, and are called the Gyllenberg-Webb model, being as follows:
dP/dt=(b-r_o(N))*P+r_i(N)*Q
dQ/dt=r_o(N)*P-(r_i(N)+my_q)*Q
with initial conditions P(0)=P_0>0 and Q(0)>or equal to 0.
So I am wondering if this ODE system is possible to set up, because of the three variables; P,Q and r_o and r_i being functions of N aswell. Also P, Q and N are functions of time, and N=P+Q (read: total cell population=cell pop.1 + cell pop.2 in the tumor).
Or if it would be better to use this system of only P and N variables:
dP/dt=(b-r_i(N)-r_o(N))*P+r_i(N)*N
dN/dt=(b+my_q)*P-my_q*N
I was thinking of setting it up with the Eulers method, but dont know exactly how, and by using the ode45 function in matlab.
Any help would be great appreciated.

回答(1 个)

Are Mjaavatten
Are Mjaavatten 2018-4-11
编辑:Are Mjaavatten 2018-4-11
You should collect your unknowns P and N in a vector x, and define a function for the right-hand side of your ODE system, something like this:
function dxdt = rhs(t,x,b,r_i,r_o,my_q)
P = x(1);
N = x(2);
dPdt = (b-r_i(N)-r_o(N))*P+r_i(N)*N;
dNdt = (b+my_q)*P-my_q*N;
dxdt = [dPdt;dNdt];
end
Save this as rhs.m.
Then create a script where you define all parameters and functions, as well as initial values. The ODE solvers do not take extra function parameters explicitly, so we define an inline function f of only t and x.
% Define parameters and functions going into your ODE system
b = 1;
r_i = @(N) sqrt(N) ;
r_o = @(N) exp(-N);
my_q = -4;
% Define an inline function f(t,x), where the extra parameters to rhs are
% "baked in":
f = @(t,x) rhs(t,x,b,r_i,r_o,my_q);
% Initialize:
P0 = 1;
N0 = 2;
x0 = [P0;N0];
% Solve:
[t,x] = ode45(f,x0,[0,100]);
P = x(:,1);
N = x(:,2);
plot(t,P);
If your system diverges very quickly, it may be useful to start with a very short time interval, to see what happens. For some parameter sets you system may be stiff, and ode45 may be very slow. If so, try e.g. ode15s.
  9 个评论
Are Mjaavatten
Are Mjaavatten 2018-4-11
编辑:Are Mjaavatten 2018-4-11
The error comes from your assignment of N and Q in pqn. It should be:
P = x(1);
Q = x(2);
N = x(3);
Now Q stays positive and the singularity disappears.
Kristoffer Ree
Kristoffer Ree 2018-4-11
Yes, well spotted, and now if i choose, dNdt = b*P-my_q*Q or if I choose dNdt = (b+my_q)*P-my_q*N or simply dNdt = dPdt+dQdt I get the same plots for all.
Now all the plots starts to look more like they should.

请先登录,再进行评论。

类别

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