Get the analytical solution of inequalities in Matlab.
Show older comments
Hello,
x + 2 y + 3 c + 4 d == 3/2 && x + y + c + d == 2 && x >= 2 &&
y < 2 && c < 3 && d > 5
How to solve this inequations to get the solution of x, y, c, and d in Matlab?
Best regards.
Answers (2)
Walter Roberson
on 3 Sep 2023
1 vote
Most of the time, MATLAB is not able to solve systems of inequalities.
6 Comments
syms x y c d
eqns = [x + 2 * y + 3 * c + 4 * d == 3/2
x + y + c + d == 2
x >= 2
y < 2
c < 3
d > 5]
sol = solve(eqns, 'returnconditions', true)
%now try to find the boundaries
parts = children(sol.conditions)
sol2 = solve([lhs(parts{1})==rhs(parts{1}), lhs(parts{2})==rhs(parts{2})])
subs(sol, sol2)
After that you have to explore which side of the bounds the values need to be on
Note that z effectively stands in for x and z1 effectively stands in for y -- that once you have particular x and y values then the c and d are pinned down.
zhenyu zeng
on 3 Sep 2023
Sam Chak
on 3 Sep 2023
Can you describe your expectation of the results? There are 4 variables but only 2 equations.
zhenyu zeng
on 3 Sep 2023
zhenyu zeng
on 3 Sep 2023
Walter Roberson
on 3 Sep 2023
The Maple output looks like this
Bruno Luong
on 3 Sep 2023
Edited: Bruno Luong
on 3 Sep 2023
The real question is how would you get as formal decription of the so called "solution" of the equality linear system?
There is no mathematical semantic AFAIK to describe the solution beside what is similar to you question, a set S that satisfies
A*x <= b
Aeq*x = beq
lo <= x <= up
One can show to linear transform the variables x to y so as the above can be reduced to the so called canonical form of
C*y = d
y <= 0
but there is no way to express it shorter.
Another way is if the region S is bounded, it is a polytope and one can express as a "sub-convex" combination of a finite set of vertexes.
S = sum wi * Vi
sum wi <= 1
In other word a convex hull where the vetices are {Vi}. There is a numerical method in FEX made by Matt J. It works OK for toy dimension of 2-3, but I wouldn't trust it for dimension >= 10.
In short the most convenient to "solve" linear inequalitues is to let it as it is. You want to know a point is a solution? Just replace and check it.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!