Errors In User Defined Function for Solving ODE System

조회 수: 22 (최근 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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by