Errors In User Defined Function for Solving ODE System
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lauren
le 3 Avr 2023
Réponse apportée : Star Strider
le 3 Avr 2023
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 commentaires
Réponse acceptée
Star Strider
le 3 Avr 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
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


