How to correctly specify fmincon nonlinear constraints

조회 수: 3 (최근 30일)
Christopher
Christopher 2020년 4월 8일
댓글: Christopher 2020년 4월 9일
Since the fmincon cin(x) and ceq(x) nonlinear function constraints have to return vectors, what happens when thse functions return a scalar value? Is the scalar used to create a correctly sized vector filled with the scalar value? See example code below:
function [cin, ceq] = nonlcon(x)
cin = -1;
ceq = x'*H*x - sd.^2; % where H and sd are global.
end
  댓글 수: 1
Matt J
Matt J 2020년 4월 8일
Note that this constraint
cin = -1;
is independent of x, as you have written it. It corresponds to the inequality -1<=0, which is always satisfied independently of x.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 4월 8일
편집: Matt J 2020년 4월 8일
The lengths of the vectors cin and ceq tell fmincon how many inequality and equality constraints you have. So, if they are scalars (i.e., vectors of length 1) then fmincon will assume that you have only 1 inequality and equality constraint. Moreover, those constraints will be considered satisfied if and only if x results in cin<=0 and ceq==0 (up to the ConstraintTolerance parameter you have set).
  댓글 수: 4
Matt J
Matt J 2020년 4월 8일
편집: Matt J 2020년 4월 8일
Maybe it will help to point out that the lengths of x, cin, and ceq are all unrelated to one another. The length of cin is simply the number of nonlinear inequality constraints that you have, and analogously for ceq. There is no link between the number of any of the constraints and length(x).
Christopher
Christopher 2020년 4월 9일
Got it and thanks for the clarification, it is much appreciated...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by