fmincon error message 'Too many input arguments'
2 views (last 30 days)
Show older comments
Daniel John
on 19 Jun 2015
Edited: Walter Roberson
on 20 Jun 2015
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.
0 Comments
Accepted Answer
Walter Roberson
on 19 Jun 2015
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.
More Answers (0)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!