Non-linear system of inequalities

12 visualizaciones (últimos 30 días)
Martin Androvich
Martin Androvich el 21 de Ag. de 2021
Comentada: Martin Androvich el 22 de Ag. de 2021
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).

Respuesta aceptada

John D'Errico
John D'Errico el 21 de Ag. de 2021
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 comentario
Martin Androvich
Martin Androvich el 22 de Ag. de 2021
That's a very detailed explanation - thank you a lot!

Iniciar sesión para comentar.

Más respuestas (1)

Alan Stevens
Alan Stevens el 21 de Ag. de 2021
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.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by