Not Enough Input Arguments in a Function
Afficher commentaires plus anciens
Hi everyone. I download a code from a website to perform some calculations using the following ODE solver function:
function [dYfuncvecdW] = ODEfun(W,Yfuncvec);
Fa = Yfuncvec(1);
Fb = Yfuncvec(2);
Fc = Yfuncvec(3);
Fd = Yfuncvec(4);
p = Yfuncvec(5);
% Explicit equations
Ft = Fa + Fb + Fc + Fd;
k1a = 100;
k2c = 1500;
Cto = 0.2;
Ca = Cto * Fa / Ft * p;
Cb = Cto * Fb / Ft * p;
Cc = Cto * Fc / Ft * p;
r1a = 0 - (k1a * Ca * Cb ^ 2);
r1b = 2 * r1a;
rb = r1b;
r2c = 0 - (k2c * Ca ^ 2 * Cc ^ 3);
r2a = 2 / 3 * r2c;
r2d = -1 / 3 * r2c;
r1c = 0 - r1a;
rd = r2d;
ra = r1a + r2a;
rc = r1c + r2c;
v = 100;
Cd = Cto * Fd / Ft * p;
alpha = 0.0019;
Fto = 20;
if (W > 0.0001)
Scd = Fc / Fd;
else
Scd = 0;
end
% Differential equations
dFadW = ra;
dFbdW = rb;
dFcdW = rc;
dFddW = rd;
dpdW = 0 - (alpha / 2 / p * Ft / Fto);
dYfuncvecdW = [dFadW; dFbdW; dFcdW; dFddW; dpdW];
The problem is that is giving me the following error:
Not enough input arguments.
Error in ODEfun (line 2)
Fa = Yfuncvec(1);
At first, I thought that it was an error regarding a misspelled variable, but no. I do not what else to do. I would appreciate your help because I am a little bit rusty in Matlab.
Réponses (1)
Walter Roberson
le 28 Mar 2019
You appeared to have tried to run this function by clicking on the green Run button. You need to instead invoke it as part of an ode*() call such as a call to
ode45(@ODEfun, tspan, y_initial)
2 commentaires
Arturo Zelaya Gealdinno
le 28 Mar 2019
Walter Roberson
le 28 Mar 2019
Create a separate .m that contains
tspan = [0 20]; %adjust to your actual time span
y_initial = [0 0 0 0 0]; %vector of length 5, adjust to your actual initial conditions
[t, Y] = ode45(@ODEfun, tspan, y_initial);
plot(t, Y(:,1))
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!