fsolve error using trustnleqn (line 28)

5 ビュー (過去 30 日間)
Bertiningrum Devi
Bertiningrum Devi 2019 年 5 月 10 日
コメント済み: Bertiningrum Devi 2019 年 5 月 19 日
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 Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by