How to write an inequality constraint to solve NLP problem by fmincon
10 次查看(过去 30 天)
显示 更早的评论
Dear all,
I am solving a non-linear optimization problem. My problem has following constraints:

I need your help in wtiting first two constraints. How to express first two constraints in fmincon?
0 个评论
采纳的回答
John D'Errico
2023-1-8
编辑:John D'Errico
2023-1-8
They are NOT TWO constraints. They are FOUR constraints. Just because you want to be efficient in how you write them in terms of the mathematics, the fact remains, they are four constraints. Just write them as 4 separate constraints. There is no additional charge. ;-)
How do you express them? Just use the linear constraints, so you will create a matrix of coefficients, just as you must do for the constraint x(1) + x(2) == 1. The inequality constraint array will be of size 4 by 6. So you have 4 constraints, and 6 unknowns.
5 个评论
John D'Errico
2023-1-8
编辑:John D'Errico
2023-1-8
Suppose you have the following run-on constraints:
x1 <= x2 <= x3
They are very simply written, and use a scheme that many use and understand in mathematics. But it is not one that MATLAB uses. What do they mean? Start with the first one. We understand that
x1 < x2
or
x1 - x2 <= 0
similarly, the second inequality is just another constraint, that involves ONLY x2 and x3.
x2 <= x3
or
x2 - x3 <= 0
Similarly, the set of constraints you have are just as easy to expand. Start with the first inequality. It reduces to (after re-arrangment)
-x1 -x3 <= -0.15
Th second constraint becomes
x1 - x4 <= 0.70
etc.
Now you write this in a matrix form, as
A = [-1 0 -1 0 0 0;
1 0 0 -1 0 0;
0 -1 0 0 -1 0;
0 1 0 0 0 -1];
b = [-0.15;0.7;-0.25;0.65];
If you multiply A by a vector of the unknowns, it will generate exactly those constraints. For example
syms x [6 1]
A*x<=b
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

