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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!