Error: using fmincon and integral: Failure in initial objective function evaluation. FMINCON cannot continue

조회 수: 1 (최근 30일)
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);

채택된 답변

Star Strider
Star Strider 2023년 11월 14일
편집: Star Strider 2023년 11월 14일
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개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by