Error using 'constraints' Too many output arguments - Please advise

I created two .m files (1) fm (2) eqcst
function y = fm(x)
y=(x(3)^2*(x(3)^2/2 + x(1)^2)) +( x(4)^2*(x(4)^2/2 + x(2)^2));
end
function c=eqcst(x)
c=(x(1)*x(3)*x(3))-(x(2)*x(4)*x(4));
end
Using fmincon
[xfinal,fval,exitflag,output]=fmincon(@fm,[0.1,0.1,0.1,0.1],[],[],[],[],[],[],@eqcst,options)
gives the error
Error using eqcst
Too many output arguments.
Error in fmincon (line 623)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 30일

0 개 추천

Non-linear constraint function must always return two output variables, one for non-linear inequality and one for non-linear equalities. If you do not have any non-linear equalities, then return [] for the second output. (Though your use of "eq" suggests that perhaps that is the nonlinear equalities, so perhaps it should be the first output that should be set to [])

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2018년 6월 30일

댓글:

2018년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by