How to write an inequality constraint to solve NLP problem by fmincon

2 views (last 30 days)
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?

Accepted Answer

John D'Errico
John D'Errico on 8 Jan 2023
Edited: John D'Errico on 8 Jan 2023
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 Comments
John D'Errico
John D'Errico on 8 Jan 2023
Edited: John D'Errico on 8 Jan 2023
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
ans = 

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!