Use of fmincon to minimise function with varying parameters, but receives 'Not enough input arguments'
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sofie
am 3 Mär. 2024
Kommentiert: Sofie
am 3 Mär. 2024
I'm trying to use fmincon to minimise an objective function, which contains parameters that vary with time.
For context, I have defined a cost-function (minCostFunction_a) in a separate m-file as shown below, which is to be minimised by determining values of F, T, kla, X, S, & DO. The minimisation is done using fmincon, where the initials values and upper- and lower boundaries have been defined in the call function, while the equalities are defined in a function in another m-file. When running this, I get no errors.
function costFunction=minCostFunction_a(x)
% Variable identification
F = x(1);
T = x(2);
kla = x(3);
X = x(4);
S = x(5);
DO = x(6);
C = 86.7;
V = 12000 ;
%Cost function: operating profit
costFunction = -(V*F*X-C*kla);
options=optimset('MaxFunEvals',1e5,'MaxIter ',1e4,'Display','on','TolFun',1e-8,'TolX',1e-8);
[xOpt,fval,exitflag,output,lambda,grad,hessian] = fmincon(@minCostFunction_a,xInitial,[],[],[],[],xMin,xMax,@nonlinearcon,options); %Optimisation of
I want to minimise the same cost-function, except C and V now varies with time, modifying the cost-function to include another set of parameters (parb). But when I run fmincon, I get the following error:
Not enough input arguments.
Error in minCostFunction_b (line 15)
C = parb(1,1);
function costFunction=minCostFunction_b(x,parb)
F = x(1);
T = x(2);
kla = x(3);
X = x(4);
S = x(5);
DO = x(6);
C = parb(1,1);
Vp = parb(2,1);
costFunction = -(Vp*F*X-C*kla);
end
[xOpt,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(x) @minCostFunction_b(x,parb),xInitial,[],[],[],[],xMin,xMax,@nonlinearcon,options);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Mär. 2024
[xOpt,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(x) minCostFunction_b(x,parb),xInitial,[],[],[],[],xMin,xMax,@nonlinearcon,options);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!