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

1 Ansicht (letzte 30 Tage)
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);

Akzeptierte Antwort

Star Strider
Star Strider am 14 Nov. 2023
Bearbeitet: Star Strider am 14 Nov. 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.
.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by