fmincon: too many input arguments
2 次查看(过去 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
2017-11-6
It is "jumphigh_obj" that is complaining about too many input arguments, not fmincon.
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!