ode arguments error in function
Afficher commentaires plus anciens
I am trying to solve 2 differential equations wrt W, but i am getting this error.
A0 = [0 1];
Wspan = [0 100];
[W, A] = ode45(@ODEfun, Wspan, A0);
plot(z, fb(:,1));
function dYfuncvecdW = ODEfun(W, Yfuncvec)
X = Yfuncvec(1);
y = Yfuncvec(2);
k = 6;
Cao = 0.2;
yao = 1/3;
Fao = 2;
Pao = 10;
epsilon = yao*(1-2-1);
ThetaB = 2;
alpha = 0.02;
Ca = Cao*(1-X)/(1+(epsilon*X))*y;
Cb = Cao*(ThetaB-(2*X))/(1+(epsilon*X))*y;
ra = -k*Ca*Cb^2;
dXdW = -(ra/Fao);
dydW = -alpha*(1+(epsilon*X))/2/y;
dYfuncvecdW = [dXdW dydW];
end
Réponses (1)
Alan Stevens
le 21 Oct 2020
For the last line in your function you need
dYfuncvecdW = [dXdW; dydW];
Notice the semicolon after dXdW
Also your plot command needs to be
plot(W, A(:,1));
2 commentaires
Elliot Alderson
le 21 Oct 2020
Alan Stevens
le 21 Oct 2020
You don't! Calculate CA outside of the function and then plot it against W. Where you have X inside the function use A(:,1) outside the function.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!