fmincon optimization with nonlinear constraint

조회 수: 1 (최근 30일)
mohammed hussein
mohammed hussein 2020년 9월 20일
댓글: mohammed hussein 2020년 9월 20일
Dear All
I am using the fmincon in matlab to minimize the objective value as
F=-(x(1)^2+x(2)^2+x(3)^2-x(4)^2) .
i have the nonlinear constrain that
x(1)-x(3)=x(2)-x(4)
How can the nonlinear constraint functions to be written as a .m file?
THX very much for your help!

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 20일
nonlcon = @(x) deal([], x(1)-x(3)-(x(2)-x(4)))
However, you should consider rewriting with one fewer variable.
x(1)-x(3)=x(2)-x(4)
implies x(4) = x(2) + x(3) - x(1) .
Substituting in F=-(x(1)^2+x(2)^2+x(3)^2-x(4)^2) we get
F = -(x(1).^2 + x(2).^2 + x(3).^2 - (x(2) + x(3) - x(1)).^2)
This simplifies to
F = 2*(x2*x3 - x1*x3 - x1*x2)
and since this is an optimization task, the linear scale is not relevant, so you can use
F = x2*x3 - x1*x3 - x1*x2;
No non-linear constraint would be needed.

추가 답변 (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