Failure in initial objective function evaluation. FMINCON cannot continue. error in fmincon line(536)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sarv
el 5 de Oct. de 2017
Comentada: Sarv
el 11 de Oct. de 2017
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 10 de Oct. de 2017
Your Gjo is initialized to 8 x 1, but in your function you use Gjo' which makes that into 1 x 8. You did not happen to notice that because you are using R2016b or later, which has "implicit expansion", and treated the addition of an 8x1 with a 1x8 by doing the equivalent of bsxfun(@plus, 8x1, 1x8) giving an 8 x 8 result.
Files attached. The one to run is abs_entrop
Más respuestas (3)
Torsten
el 5 de Oct. de 2017
I suspect there is an argument for the log-function which is negative or undefined.
Best wishes
Torsten.
Alan Weiss
el 9 de Oct. de 2017
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 comentarios
Walter Roberson
el 10 de Oct. de 2017
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.
Alan Weiss
el 10 de Oct. de 2017
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
0 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!