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
回答(1 个)
Alan Stevens
2020-10-21
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 个评论
Elliot Alderson
2020-10-21
Alan Stevens
2020-10-21
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!