How to write an inequality constraint to solve NLP problem by fmincon
조회 수: 6 (최근 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!

