Errors In User Defined Function for Solving ODE System
27 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to create a function to solve a system of ode's using ode45.
With Initial Conditions:
, 
and where
,
,
,
,
,
, 
The functions u and v are column vectors with 101 entries
The errors I'm getting are:
Not enough input arguments.
dpdt = -Zeta*p*log(p/q)-Theta*p*v;
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
[tSol, XSol] = ode45(@ODEsystem,t,IC);
Code:
Code to run the function:
p0 = 1;
q0 = 1;
[tSol, XSol] = ODESolver(u,v,t,p0,q0);
Ode Function/Solver
function [tSol,XSol] = ODESolver(u,v,t,p0,q0)
IC = [p0,q0];
[tSol, XSol] = ode45(@ODEsystem,t,IC);
pTTumorEndVolume = XSol(end,1);
function dXdt = ODEsystem(t,X,u,v)
p = X(1);
q = X(2);
Theta = 0.1; %Theta
Gamma = 0.15; %Gamma
b = 5.85; %b
d = 0.00873; %d
Mu = 0.02; %Mu
Zeta = 0.084; %Zeta
Eta = 0; %Eta
dpdt = -Zeta*p*log(p/q)-Theta*p*v;
dqdt = (b*p)-(Mu*q)-(d*(p)^(2/3)*q)-(Gamma*u*q)-(Eta*q*v);
dXdt = [dpdt;dqdt];
end
end
0 件のコメント
採用された回答
Star Strider
2023 年 4 月 3 日
You need to tell ode45 what arguments it needs to use:
[tSol, XSol] = ode45(@(t,x)ODEsystem(t,x,u,v),t,IC);
It only needs to know about ‘t’ and ‘x’. The others are passed as extra parameters.
Try this —
u = rand % Not Otherwise Defined
v = rand % Not Otherwise Defined
t = linspace(0, 100,250); % Not Otherwise Defined
p0 = 1;
q0 = 1;
[tSol, XSol] = ODESolver(u,v,t,p0,q0);
figure
plot(tSol,XSol)
grid
xlabel('t')
ylable('X')
function [tSol,XSol] = ODESolver(u,v,t,p0,q0)
IC = [p0,q0];
[tSol, XSol] = ode45(@(t,x)ODEsystem(t,x,u,v),t,IC);
pTTumorEndVolume = XSol(end,1);
function dXdt = ODEsystem(t,X,u,v)
p = X(1);
q = X(2);
Theta = 0.1; %Theta
Gamma = 0.15; %Gamma
b = 5.85; %b
d = 0.00873; %d
Mu = 0.02; %Mu
Zeta = 0.084; %Zeta
Eta = 0; %Eta
dpdt = -Zeta*p*log(p/q)-Theta*p*v;
dqdt = (b*p)-(Mu*q)-(d*(p)^(2/3)*q)-(Gamma*u*q)-(Eta*q*v);
dXdt = [dpdt;dqdt];
end
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!


