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일

0 개 추천

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

Matt J
Matt J 2019년 5월 10일
You might also want to consider using lsqnonlin instead of fsolve, so that you can put upper and lower bounds on the x(i) that need to be kept away from zero.
Bertiningrum Devi
Bertiningrum Devi 2019년 5월 11일
Thank you for your help
so the initial points influences the result. actually I have no idea of in what range my ans will be, any tips to choose the initial points?
Matt J
Matt J 2019년 5월 11일
It does influence the result, but the problem here is that your guess can't even be evaluated. Your objective function has no legitimate value there.
You must have some approximate idea on physical grounds of what the result should be. How else will you know if an answer given to you makes any sense?
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개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2019년 5월 10일

댓글:

2019년 5월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by