Why does my nonlinear constraint return "not enough input arguments"?

TranchesVIL takes a 1x4 input, fun3 takes a 1x3 input. par0 is 1x3.
fun3=@(X)sum(sum((TranchesVIL(phi,X0,sigma,[alpha,X],r,R,L(2:6),U(2:6),T,n,s)-CDO(2:6,:)).^2));
nonlcon2=@(X)nonlcon(sigma,X);
[X_j(k,:),SSE_CDO(k)]=fmincon(fun3,par0,[],[],[],[],lb_alpha(2:4),ub_alpha(2:4),@nonlcon,optionsT);
nonlcon is defined as follows:
function [c,ceq] = nonlcon(sigma,x)
ceq=0;
c=sigma+x(3)*(x(1)^2+x(2)^2)-0.7;
end
sigma is a 1x115 vector of variables.
The entire error I recieve is:
Not enough input arguments.
Error in nonlcon (line 3)
c=sigma+x(3)*(x(1)^2+x(2)^2)-0.7;
Error in fmincon (line 622)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in main (line 68)
[X_j(k,:),SSE_CDO(k)]=fmincon(fun3,par0,[],[],[],[],lb_alpha(2:4),ub_alpha(2:4),@nonlcon,optionsT);
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
Why do I recieve this error? If the x inserted in the objective function is a 1x3, then is it not the same 1x3 that is inserted into the nonlcon and hence there are sufficient input arguments?

 采纳的回答

How do you call your objective function? What is passed into it?
Answer: X
Note that nonlcon takes two arguments, yet fmincon is pretty sure it takes only one argument, because fmincon passes the same thing to the constraint function that it passes to the objective. You pass in nonlcon into fmincon.
Perhaps you think that you called fmincon with nonlcon2, which is indeed a function only of X. You did not. In fact, it appears that you never use nonlcon2.
I'd suggest you are being sloppy with your function names. This is what causes bugs. Be more careful with your names, and your code will improve. It might even run. :)

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by