fmincon: too many input arguments

1 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2017-11-6
It is "jumphigh_obj" that is complaining about too many input arguments, not fmincon.
Roel
Roel 2017-11-6
编辑:Roel 2017-11-6
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.

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2017-11-6
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 个评论
Roel
Roel 2017-11-6
This has solved the issue. They are indeed nonstatic methods. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by