fsolve error using trustnleqn (line 28)

5 次查看(过去 30 天)
Hello everyone,
I'm trying to solve non linear equations system using fsolve. I'm beginner in matlab I just have no idea what's going on with my program when I tried to run it, there's an error message in the command window:
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
Error in fsolve (line 408)
trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...
Error in singletray (line 10)
x = fsolve(fun,x0);
what does that mean? and what am I supposed to do to get it solved?
here is the function file:
function F = equilibrium(x)
rec_a=0.7;
rec_b=0.9;
HCOin=1.72e-8;
HSin=0.1128;
a=(1-rec_a)*HCOin;
b=(1-rec_b)*HSin;
F(1)=x(1)*a/(x(2)*x(3)) - 32.1421;
F(2)=x(1)*b/(x(2)*x(4)) - 16.7567;
F(3)=x(5)/(a*x(6)) - 3.508e-13;
F(4)=x(1)*x(6)/x(2) - .32134475;
F(5)=x(7)/(x(8)*x(9)) - 2.246e10;
F(6)=x(9)*x(6) - 7.573e-11;
F(7)=x(1)+x(9)+x(7)-b-a-2*x(5)-x(6);
F(8)=2.93-x(8)-x(7);
F(9)=28.27-x(2)-x(1);
end
I run it in :
%Reactive desorption modeling
%assumption: isothermal & only 1 tray
clc;
clear;
%solving 7 unknowns
options = optimoptions('fsolve','Display','iter');
[x,fval] = fsolve(@equilibrium,[0;0;0;0;0;0;0;0;0],options);
Any help would be appreciated. Thank you so much

采纳的回答

Matt J
Matt J 2019-5-10
编辑:Matt J 2019-5-10
The initial point is [0;0;0;0;0;0;0;0;0]. Calling your function at this point gives something with NaNs
>> equilibrium([0;0;0;0;0;0;0;0;0])
ans =
NaN NaN NaN NaN NaN -0.0000 -0.0113 2.9300 28.2700
because of divisions by zero. You must use a different initial point, where your function is actually defined.
  5 个评论
Walter Roberson
Walter Roberson 2019-5-11
The terms used in the variable names and comments are seldom associated with negative values, so you can probably impose a lower bound of 0 for all of you values.
You divide by several of your x values, so you can probably impose a lower bound of realmin() for those, or more likely sqrt(realmin)
Bertiningrum Devi
Bertiningrum Devi 2019-5-19
Thank you Matt, Thank you Walter, your information helps me so much.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Chemistry 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by