How to do 'less than but not equal to' nonlinear constraints in fmincon?
9 次查看(过去 30 天)
显示 更早的评论
How can I set the constraints for the solution (x1,x2,x3,x4) so that it has a non-linear constraint (x1*x2)/(x3*x4)<1 a.k.a. c = (x1*x2)/(x3*x4)-1?
I already have a separate time I test the non-linear constraint (ceq) (x1*x2)/(x3*x4)=1, and I do not want the solution of the less-than condition to necessarily overlap with the equals condition since it's usually c(x)<=0.
I am using Matlab r2019a or b.
0 个评论
回答(2 个)
Ameer Hamza
2020-9-16
Numerical optimization algorithms already satisfy constraints with a tolerance value, so the less than (<) or less than equal to (<=) constraints are not fundamentally different. If you want to avoid (x1*x2)/(x3*x4)=1, then you will need to manually set the other constraint like this (x1*x2)/(x3*x4)<=0.99.
Walter Roberson
2020-9-16
A/B < 1 implies A < B implies A - B < 0,
A-B < 0 implies A - B + epsilon <= 0 for positive epsilon and epsilon goes to 0.
So... we arrive at the constraint
x1*x2 - x3*x4 + eps(realmin)
with implied <= 0
But keep in mind that two different ways of calculating the same "algebraic" number do not necessarily give the same result in floating point.
For example let x1 = 25 and x2 = 1/3, and let x3 = 1 and x4 = 25/3 . Then algebraically 25 * 1/3 should equal 1 * 25/3 . But 25 * (1/3) - 25/3 = -1.77635683940025e-15 in double precision, because 1/3 cannot be exactly represented in binary floating point. The above calculation x1*x2 - x3*x4 + eps(realmin) is negative so the constraint would be satisfied, and yet "morally" the constraint should not be satisfied, since "morally" the two expressions should be equal. If you were to switch the variables then x1*x2 - x3*x4 would be positive instead of 0 so the constraint would fail, but "accidentally" so.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!