getting rid of fzero error
1 view (last 30 days)
Show older comments
Error using fzero (line 257)
Function values at interval endpoints must be finite and real.
Error in interphase (line 24)
[z, fval, exitflag, output] = fzero(fun,x0);
function interphase
clear all
format long
% Given;
yAG=0.179066;% mole fraction of A component in a bulk gas
xAL = 7.2;% mole fraction of A component in a bulk liquid
ky = 0.02919;% film mass-transfer coefficient k'y
kx = 0.767108;% film mass-transfer coefficient k'x
% The equilibrium function should be entered below under
% function res=equilibrium(x)
% Finding the limits that includes the roots of the set of equations
x0=[0 1];
myfun1 = @find_initial_value;
fun1=@(x)myfun1(yAG, x);
[z, fval, exitflag, output] = fzero(fun1,x0);
xhigh = z;
xAstar=xhigh
%Solving the equations
x0=[xAL xhigh];
myfun = @intersect_equilibrium;
fun=@(x)myfun(yAG, xAL, kx, ky, x);
[z, fval, exitflag, output] = fzero(fun,x0);
xAi=z
yAi=equilibrium(xAi)
function res=equilibrium(x)
% Equilibrium relation; enter here the one that is used
res=29.412*x+160.41*x^2;
end
function res = find_initial_value(yAG,x)
res = yAG - equilibrium(x);
end
function res = intersect_equilibrium(yAG, xAL, kx, ky, x)
y = equilibrium(x);
if abs(x-xAL)<1e-12
aa=1;
else
aa=kx/(((1-xAL)-(1-x))/log((1-xAL)/(1-x)));
end
if abs(y-yAG)<1e-12
bb=1;
else
bb=ky/(((1-y)-(1-yAG))/log((1-y)/(1-yAG)));
end
res = y -(yAG + aa/bb*(xAL-x));
end
end
0 Comments
Answers (1)
Walter Roberson
on 30 Apr 2018
If you
fplot(@(x) [real(fun(x)),imag(fun(x)),0], [-2 10])
you can see that the function is complex valued except at a small number of points. You would need to test further to see if those points happened to be zeros on the real component (but my tests say they are not.)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!