Failure in initial objective function evaluation. FMINCON cannot continue. error in fmincon line(536)
显示 更早的评论
I am trying to optimize my Gibbs energy function for a mixture of gases with fmincon and I keep getting 3 errors. my function looks like this.
function G=myGfunc(nj)
Enj=sum(nj);
G=sum(nj.*(Gjo/R/T+ log(nj/Enj*(p/po))));
end
and I call the fmincon as follows:
options=optimset('Algorithm', 'interior-point');
x=fmincon(@myGfunc,x0,[],[],Aeq,beq,LB,[],[],options);
the errors I get are:
Undefined function or variable 'Gjo'.
Error in myGfunc (line 3)
G=sum(nj.*(Gjo/R/T+ log(nj/Enj*(p/po))));
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in myMeth (line 70)
x=fmincon(@myGfunc,x0,[],[],Aeq,beq,LB,[],[],options);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
It's weird since my Gjo is well defined and it gave solid values, before not defining the parameters needed for fmincon.
any help would by greatly appreciated
采纳的回答
更多回答(3 个)
Torsten
2017-10-5
0 个投票
I suspect there is an argument for the log-function which is negative or undefined.
Best wishes
Torsten.
Alan Weiss
2017-10-9
0 个投票
Almost certainly, you are not passing the value of Gjo that is in your workspace. See Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation
3 个评论
Sarv
2017-10-10
编辑:Walter Roberson
2017-10-10
Walter Roberson
2017-10-10
You did not initialize your global variables. All of those global variables are going to be [] because they have not been initialized. Your routine is going to be returning [] rather than a scalar.
Sarv
2017-10-10
Alan Weiss
2017-10-10
0 个投票
I suggest that you use the debugger and see what the size of the returned value G is from your objective function. I suspect that you are returning a vector, not a scalar.
Alan Weiss
MATLAB mathematical toolbox documentation
类别
在 帮助中心 和 File Exchange 中查找有关 Choose a Solver 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!