# ode arguments error in function

1 view (last 30 days)
Elliot Alderson on 21 Oct 2020
Commented: Alan Stevens on 21 Oct 2020
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

Alan Stevens on 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));

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