필터 지우기
필터 지우기

fmincon: too many input arguments

조회 수: 1 (최근 30일)
Roel
Roel 2017년 11월 6일
댓글: Roel 2017년 11월 6일
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