Error: using fmincon and integral: Failure in initial objective function evaluation. FMINCON cannot continue
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Manoj Manoj
el 14 de Nov. de 2023
Editada: Star Strider
el 14 de Nov. de 2023
I am using fmincon and integral function simultaneously but I am getting an error. This is the error I am getting.
Unrecognized function or variable 'rhog'.
Error in optimization9>@(p)q(p,d,rhog) (line 39)
[s,fval] = fmincon(@(d,rhog)integral(@(p)q(p,d,rhog),2*pi,20*pi),d0,A,b,Aeq,beq,lb,ub,nonlcon,options); %minimize
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in optimization9>@(d,rhog)integral(@(p)q(p,d,rhog),2*pi,20*pi) (line 39)
[s,fval] = fmincon(@(d,rhog)integral(@(p)q(p,d,rhog),2*pi,20*pi),d0,A,b,Aeq,beq,lb,ub,nonlcon,options); %minimize
Error in fmincon (line 568)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in optimization9 (line 39)
[s,fval] = fmincon(@(d,rhog)integral(@(p)q(p,d,rhog),2*pi,20*pi),d0,A,b,Aeq,beq,lb,ub,nonlcon,options); %minimize
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
And this is my code. I am trying to optimize d and rhog. I am using matlabFunction to convert symbolic expression into function which has three variables p, d and rhog. I am numerically integrating wrt p then optimizing wrt d and rhog.
q = matlabFunction(answer,"Vars",[p,d,rhog]);
options = optimset('PlotFcns',@optimplotfval);
d0 = [0.5,30];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0,0];
ub = [1,2000];
nonlcon = [];
[s,fval] = fmincon(@(d,rhog)integral(@(p)q(p,d,rhog),2*pi,20*pi),d0,A,b,Aeq,beq,lb,ub,nonlcon,options);
Respuesta aceptada
Star Strider
el 14 de Nov. de 2023
Editada: Star Strider
el 14 de Nov. de 2023
The ‘rhog’ variable must be defined in your workspace prior to using it as a function argument in ‘q’.
EDIT — (14 Nov 2023 at 17:20)
Please understand that ‘q’ is invisible to us.
q = matlabFunction(answer,"Vars",[p,d,rhog]);
options = optimset('PlotFcns',@optimplotfval);
d0 = [0.5,30];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0,0];
ub = [1,2000];
nonlcon = [];
% b(1) = d, b(2) = rhog
[s,fval] = fmincon(@(b)integral(@(p)q(p,b(1),b(2)),2*pi,20*pi),d0,A,b,Aeq,beq,lb,ub,nonlcon,options);
To optimise two (or more) different variables, create them as members of one parameter vextor, then optimise that parameter vector.
.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Mathematics and Optimization 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!