Non-linear system of inequalities

19 ビュー (過去 30 日間)
Martin Androvich
Martin Androvich 2021 年 8 月 21 日
コメント済み: Martin Androvich 2021 年 8 月 22 日
I have a non-linear system of four inequalities (constraints) that I wish to solve for the two variables S and G, as follows:
I can solve this using WolframAlpha as shown here, but am curious how to solve this problem using MATLAB? Either a symbolic solution (like Wolfram provides) or a set of possible integer solutions (or something alike).

採用された回答

John D'Errico
John D'Errico 2021 年 8 月 21 日
Start with, what can we do in symbolic form?
syms S G real
Eq(1) = G > 21;
Eq(2) = S >= 15;
Eq(3) = S <= 18;
Eq(4) = 61 <= 2*S + G;
Eq(5) = 2*S + G <= 63;
Eq(6) = atand(S/G) >= 30;
Eq(7) = atand(S/G) <= 45;
solve(Eq,S,G,'returnconditions',true)
Warning: Unable to find explicit solution. For options, see help.
ans = struct with fields:
S: [0×1 sym] G: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]
There are infinitely many real solutions. So solve cannot handle the problem.
Those inequalities are all just linear though, linear in S and G. Even the case of the atan is linear, sicne over a limited region, the tangent function is monotonic. So we know that if
atand(S/G) <= 45
then by taking the tangent of both sides, we do not change the sign of the inequality. That tells us:
S/G <= 1
or
S <= G
Likewise, we can infer that
S/G >= sqrt(3/3)
So we have
S >= sqrt(3)/3*G
There is a nice utility called plotregion, that lives on the file exchange for free download. If we represent this linear sytem of inequalities by the matrix A and vector b, where A*x >= b, we might do:
LB = [15 21]; % lower bounds on S and G respectively
UB = [18 inf]; % upper bounds on S and G
A = [2 1;-2 -1;-1 1;1 -sqrt(3)/3]; % linear inequalities
b = [61;-63;0;0];
plotregion(A,b,LB,UB)
xlabel 'S'
ylabel 'G'
grid on
That region in the (S,G) plane is where your solutions live. There are infinintely many pairs of real solutions. It looks like Alpha was willing to generate some of them.
If you wish to show the integer solutions, a simple graphical way to do so is to overlay an integer lattice on top of that domain.
[s,g] = meshgrid(16:18,25:30);
hold on
plot(s,g,'ro')
Where you should see the six pairs of integer solutions that live in the solution locus. Five of them lie on the boundary, one is interior.
  1 件のコメント
Martin Androvich
Martin Androvich 2021 年 8 月 22 日
That's a very detailed explanation - thank you a lot!

サインインしてコメントする。

その他の回答 (1 件)

Alan Stevens
Alan Stevens 2021 年 8 月 21 日
First plot some lines that bound the inequalities
% G>21
% 15<=S<=18
% 61<=2S+G<=63
% 30<=atan(S/G)<=45 -> sqrt(3)/3 <= S/G <= 1 -> G<=sqrt(3)S and G>=S
% Define functions
G1 = @(S) 61 - 2*S; % G >= G1
G2 = @(S) 63 - 2*S; % G <= G2
G3 = @(S) sqrt(3)*S; % G <= G3
S = [15 18];
plot(S,G1(S),S,G2(S),S,G3(S)),grid
s1 = 61/(2+sqrt(3)); s2 = 63/(2+sqrt(3));
g1 = G1(s1); g2 = G2(s2);
patch([s1, 18, 18, s2], [g1, 25, 27, g2],'y')
xlabel('S'), ylabel('G')
% then find the intersection points.
% The solutions are in the yellow patch area.
  1 件のコメント
Martin Androvich
Martin Androvich 2021 年 8 月 21 日
That's pretty ingenious! Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by