hw5: done 2.1

This commit is contained in:
Claudio Maggioni 2021-05-31 11:11:30 +02:00
parent cd83872124
commit 8922bce42f

32
Claudio_Maggioni_5/ex2.m Normal file
View file

@ -0,0 +1,32 @@
syms x1 x2
c1 = 2 * x1 + 3 * x2 - 6;
c2 = -3 * x1 + 2 * x2 - 3;
c3 = 2 * x2 - 5;
c4 = 2 * x1 + x2 - 4;
c1 = solve(c1 == 0, x2, 'Real', true);
c2 = solve(c2 == 0, x2, 'Real', true);
c3 = solve(c3 == 0, x2, 'Real', true);
c4 = solve(c4 == 0, x2, 'Real', true);
i1 = solve(c1 == c2, x1, 'Real', true);
i2 = solve(c1 == c4, x1, 'Real', true);
i3 = solve(c4 == 0, x1, 'Real', true);
px = double([0 0 i1 i2 i3]);
py = double([0 subs(c2, x1, 0) subs(c1, x1, i1) subs(c4, x1, i2) subs(c4, x1, i3)]);
xl = -0.05;
xh = 2.05;
axis([-0.05 2.05 -0.15 5.15])
hold on
for c = [c1 c2 c3 c4]
plot([xl, xh], [subs(c, x1, xl), subs(c, x1, xh)]);
end
xline(0);
plot([xl, xh], [0, 0]);
patch(px, py, [204/255 255/255 187/255]);
legend('2x1 + 3x2 = 6', '-3x1 + 2x2 = 3', '2x2 = 5', '2x1 + x2 = 4', 'x1 > 0', 'x2 > 0', 'feasible region');
hold off