Errors In User Defined Function for Solving ODE System

25 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 3 Apr 2023
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
.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!