Clear Filters
Clear Filters

fmincon: too many input arguments

1 view (last 30 days)
Roel
Roel on 6 Nov 2017
Commented: Roel on 6 Nov 2017
Optimizing in OOP with fmincon with:
size x0 = 1 8
A=[];
b=[];
Aeq=[];
beq=[];
size lb = 1 8
size ub = 1 8
options = optimoptions('fmincon','Algorithm','sqp','Maxiterations',3); % 3 iter for tests
[x, fval, exitflag, output, lambda] = fmincon(@(x)this.jumphigh_obj(x),x0,A,b,Aeq,beq,lb,ub,@(x)this.jumpcon(x),options);
With an objective function
function f = jumphigh_obj(x)
and a constraint function
function [g, geq] = jumpcon(x) %where geq = []
The following error occurs:
Error using Leg_3DoF_ACA_jumpref_optimizer/jumphigh_obj
Too many input arguments.
Error in Leg_3DoF_ACA_jumpref_optimizer>@(x)this.jumphigh_obj(x)
(line 132)
[x, fval, exitflag, output, lambda] =
fmincon(@(x)this.jumphigh_obj(x),x0,A,b,Aeq,beq,lb,ub,@(x)this.jumpcon(x),options);
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in Leg_3DoF_ACA_jumpref_optimizer/run (line 132)
[x, fval, exitflag, output, lambda] =
fmincon(@(x)this.jumphigh_obj(x),x0,A,b,Aeq,beq,lb,ub,@(x)this.jumpcon(x),options);
Caused by:
Failure in initial objective function evaluation. FMINCON
cannot continue.
I don't get it, I'm using the 10 fmincon input arguments as I'm supposed to so no extra arguments are passed as extra parameters to the obj function (right?). What am I missing here?
  2 Comments
Matt J
Matt J on 6 Nov 2017
It is "jumphigh_obj" that is complaining about too many input arguments, not fmincon.
Roel
Roel on 6 Nov 2017
Edited: Roel on 6 Nov 2017
I understand, I have read about this happening here , when fmincon is given more than ten input arguments and the additional arguments are passed onto the obj function. But as far as I can tell that is not the case here. Anyway, that's why I mentioned the number of fmincon input arguments.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 6 Nov 2017
I suspect jumphigh_obj is a method of some class and that it is not a Static method of a class named this. If I'm correct, you will need to specify it as a function accepting two inputs. From the documentation:
"Nonstatic methods must include an explicit object variable as a function argument. The MATLAB language does not support an implicit reference in the method function definition."
In the class definition, it must be defined like this (you may change the variable names, but you must specify at least two inputs and one output.)
function y = jumphigh_obj(this, x)
The same holds for jumpcon.
  1 Comment
Roel
Roel on 6 Nov 2017
This has solved the issue. They are indeed nonstatic methods. Thank you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!