Errors In User Defined Function for Solving ODE System

27 ビュー (過去 30 日間)
Lauren
Lauren 2023 年 4 月 3 日
回答済み: Star Strider 2023 年 4 月 3 日
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.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in ODESolver (line 5)
[tSol, XSol] = ode45(@ODEsystem,t,IC);
Code:
Code to run the function:
p0 = 1;
q0 = 1;
[tSol, XSol] = ODESolver(u,v,t,p0,q0);
Unrecognized function or variable 'u'.
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

採用された回答

Star Strider
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
u = 0.1650
v = rand % Not Otherwise Defined
v = 0.8246
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 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by