MATLAB: Fmincon error message ‘Too many input arguments’

fminconnon-linear optimization

I have checked file names (no matching file names), plus all function return a scalar value;yet I still get the following error message:
Error using HourlyCost
Too many input arguments.
Error in fmincon (line 564)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in CostOpt (line 5)
MinCost=fmincon(@HourlyCost,x0,[],[],[],[],lb,[],[],options);
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
%Objective function
function Cost_h=HourlyCost()
a=0.3;
b=1;
c=2;
L_h=TtlEngh();
Cost_h=a*L_h^2+b*L_h+c*L_h;
end
%Optimizing the Objective function
function MinCost=CostOpt()
x0=0;
lb=0;
options=optimset('Algorithm','interior-point');
MinCost=fmincon(@HourlyCost,x0,[],[],[],[],lb,[],[],options);
end
Please, help.

Best Answer

fmincon(@HourlyCost,x0,[],[],[],[],lb,[],[],options) says that HourlyCost is to be the objective function. Objective functions are always passed the current x value (the parameter whose value is to produce the minimum result). But your HourlyCost function is defined to take no arguments.
Your objective function is not required to use the parameter that is passed in, but it is required to accept a parameter.
function Cost_h=HourlyCost(X)
I have to ask, though, why you are asking to minimize something whose value is fixed? If your HourlyCost is always going to return the same result for all arguments then there isn't anything to minimize.