Undefined function or variable 'z' and error with ode45.

I need help, I don't know why this error occurred. Someone can explain me what I'm doing wrong and how can I solve it, please.
function dYfuncvecdz = ODEfun(z,Yfuncvec)
X= Yfuncvec(1);
% Explicit equations
cao = 8;
k = .01;
z = 200 - lam;
lam = 200 - z;
ca = cao*(1-X);
E1 = 4.44658e-10*lam^4-1.1802e-7*lam^3+1.35358e-5*lam^2-.000865652*lam+.028004;
E2 = -2.64e-9*lam^3+1.3618e-6*lam^2-.00024069*lam+.015011;
F1 = 4.44658e-10/5*lam^5-1.1802e-7/4*lam^4+1.35358e-5/3*lam^3-.000865652/2*lam^2+.028004*lam;
F2 = -(-9.30769e-8*lam^3+5.02846e-5*lam^2-.00941*lam+.618231-1);
ra = -k*ca^2;
if lam<=70
E=E1;
F=F1;
else
E=E2;
F=F2;
end
EF=E/(1-F);
% Differential equations
dXdz = -(ra/cao+EF*X);
dYfuncvecdz=[dXdz];
clc
zspan = [0 200]; % Range for the independent variable
y0 = [0]; % Initial values for the dependent variables
[t,y] = ode45(@ODEfun,tspan,y0);
z=size(y);
X=round(y(z(1,1),1),2);
a=['Conversion, X, predicted by Maximum Mixedness Model is ', num2str(X)];
disp(a)
plot(t,y,'LineWidth',1)
xlabel('time(mins)')
ylabel('X_m_m')
legend('X_m_m','Location','NorthWest')
title('Plot of conversion vs time predicted by Maximum Mixedness Model')
axis([0 200 0 1])

 采纳的回答

You defined:
zspan = [0 200]; % Range for the independent variable
so your ode45 call needs to be:
[t,y] = ode45(@ODEfun,zspan,y0);
Also, in ‘ODEfun’, these two statements should be in in this order:
lam = 200 - z;
z = 200 - lam;

4 个评论

I would suggest dropping the assignment to z as being unnecessary and confusing.
I would, as well, especially since those two lines together do nothing.
I assume something else may be intended, so I simply corrected their order for now.
Thank you, Matlab gave me the conversion, but now I think that I need to fix the polynomial expression, because the graph gave me a weird curve.
About the 'z' I use it, because my guidebook explain with that substitution the metod. I Attach picture of the model.
Captura de pantalla 2020-02-04 a la(s) 19.11.12.png
I have absolutely no idea what you are doing with that.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by