MATLAB: Fmincon: too many input arguments

fmincontoo many input arguments

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?

Best Answer

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.