ode arguments error in function

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

Respuestas (1)

Alan Stevens
Alan Stevens el 21 de Oct. de 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 comentarios

Elliot Alderson
Elliot Alderson el 21 de Oct. de 2020
This works thanks, another thing can you tell me how do I plot Ca and W from within the function?
Alan Stevens
Alan Stevens el 21 de Oct. de 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.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 21 de Oct. de 2020

Comentada:

el 21 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by