fmincon optimization with nonlinear constraint

1 次查看(过去 30 天)
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 中查找有关 Problem-Based Optimization Setup 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by