Use of fmincon to minimise function with varying parameters, but receives 'Not enough input arguments'
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2024-3-3
[xOpt,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(x) minCostFunction_b(x,parb),xInitial,[],[],[],[],xMin,xMax,@nonlinearcon,options);
更多回答(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!