hw5: work

This commit is contained in:
Claudio Maggioni 2021-06-01 22:38:06 +02:00
parent 95b094f8b0
commit 1b092ab91c
5 changed files with 110 additions and 32 deletions

View file

@ -0,0 +1,46 @@
<!-- vim: set ts=2 sw=2 et tw=80: -->
---
title: Homework 5 -- Optimization Methods
author: Claudio Maggioni
header-includes:
- \usepackage{amsmath}
- \usepackage{hyperref}
- \usepackage[utf8]{inputenc}
- \usepackage[margin=2.5cm]{geometry}
- \usepackage[ruled,vlined]{algorithm2e}
- \usepackage{float}
- \floatplacement{figure}{H}
- \hypersetup{colorlinks=true,linkcolor=blue}
---
\maketitle
# Exercise 2
## Exercise 2.1
The resulting MATLAB plot of each constraint and of the feasible region is shown
below:
![Plot of feasible region and constraints](./ex2-1.png)
## Exercise 2.3
We then compute the objective function value for each basic feasible point
found, The smallest objective value will correspond with the constrained
minimizer problem solution.
$$
x_1 = \begin{bmatrix}0\\0\end{bmatrix} \;\;\; f(x_1) = 4 \cdot 0 + 3 \cdot 0 =
0$$$$
x_2 = \frac12 \cdot \begin{bmatrix}0\\3\end{bmatrix} \;\;\;
f(x_2) = 4 \cdot 0 + 3 \cdot \frac32 = \frac92$$$$
x_3 = \frac{1}{13} \cdot \begin{bmatrix}3\\24\end{bmatrix} \;\;\; f(x_3) = 4
\cdot \frac{3}{13} + 3 \cdot \frac{24}{13} = \frac{84}{13}$$$$
x_4 = \frac12 \cdot \begin{bmatrix}3\\2\end{bmatrix} \;\;\; f(x_4) = 4 \cdot
frac32 + 3 \cdot 1 = 9$$$$
x_5 = \begin{bmatrix}2\\0\end{bmatrix} \;\;\; 4 \cdot 2 + 1 \cdot 0 = 8$$
Therefore, $x^* = x_1$ is the global constrained minimizer with $\lambda^* = \lambda_1 = NaN$ as
the slack variable value.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View file

@ -20,36 +20,52 @@ i2 = solve(c1 == c4, x1, 'Real', true);
i3 = solve(c4 == 0, x1, 'Real', true); i3 = solve(c4 == 0, x1, 'Real', true);
px = double([0 0 i1 i2 i3]); 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)]); pysym = [0 subs(c2, x1, 0) subs(c1, x1, i1) subs(c4, x1, i2) subs(c4, x1, i3)];
py = double(pysym);
xl = -0.05; xl = -0.05;
xh = 2.05; xh = 2.05;
colors = [1 0 1; 0 0 1; 1 0 0; 0 1 0]; orange = [232/255 128/255 18/255];
grey = [0.5 0.5 0.5];
colors = [orange; 0 0 1; 1 0 0; 0 1 0];
dirs = [30 30 30 30];
axis([-0.05 2.05 -0.15 5.15]) axis([-0.05 2.05 -0.15 5.15])
i = 1; i = 1;
hold on hold on
for c = [c1 c2 c3 c4] for c = [c1 c2 c3 c4]
%plot([xl, xh], [subs(c, x1, xl), subs(c, x1, xh)]); pl = patch([xl, xl, xh, xh], ...
hatchfill(patch([xl, xl, xh, xh], ... double([-0.15, subs(c, x1, xl), subs(c, x1, xh), -0.15]), ...
double([0, subs(c, x1, xl), subs(c, x1, xh), 0]), ... colors(i, :));
colors(i, :)), ... pl.EdgeColor = colors(i, :);
'HatchColor', colors(i, :), 'HatchOffset', (i-1)/5); pl.FaceAlpha = .2;
pl.EdgeAlpha = .2;
i = i + 1; i = i + 1;
end end
xline(0);
hatchfill(patch([0, 0, xh, xh], ... pl = patch([0, 0, xh, xh], ...
double([0, 5.15, 5.15, 0]), ... double([0, 5.15, 5.15, 0]), ...
'white'), ... grey);
'HatchColor', [1 0.5 0], 'HatchOffset', 4/5); pl.EdgeColor = grey;
plot([xl, xh], [0, 0]); pl.FaceAlpha = .2;
patch(px, py, 'black'); pl.EdgeAlpha = .2;
alpha(.05)
legend('','2x1 + 3x2 <= 6', '', '-3x1 + 2x2 <= 3', '', '2x2 <= 5', ... pl = patch(px, py, 'green');
'', '2x1 + x2 <= 4', '', 'x1 > 0 and x2 > 0', 'feasible region'); pl.EdgeColor = 'green';
legend('2x1 + 3x2 <= 6', '-3x1 + 2x2 <= 3', '2x2 <= 5', ...
'2x1 + x2 <= 4', 'x1 > 0 and x2 > 0', 'feasible region');
hold off hold off
%% gsppn
for i=1:5
obj = 4 * px(i) + 3 * py(i);
fprintf("x1=%g x2=%g y=%g\n", px(i), py(i), obj);
end
%% Exercise 3.2 %% Exercise 3.2
G = [6 2 1; 2 5 2; 1 2 4]; G = [6 2 1; 2 5 2; 1 2 4];

View file

@ -20,36 +20,52 @@ i2 = solve(c1 == c4, x1, 'Real', true);
i3 = solve(c4 == 0, x1, 'Real', true); i3 = solve(c4 == 0, x1, 'Real', true);
px = double([0 0 i1 i2 i3]); 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)]); pysym = [0 subs(c2, x1, 0) subs(c1, x1, i1) subs(c4, x1, i2) subs(c4, x1, i3)];
py = double(pysym);
xl = -0.05; xl = -0.05;
xh = 2.05; xh = 2.05;
colors = [224/255 6/255 191/255; 0 0 1; 1 0 0; 0 1 0]; orange = [232/255 128/255 18/255];
grey = [0.5 0.5 0.5];
colors = [orange; 0 0 1; 1 0 0; 0 1 0];
dirs = [30 30 30 30];
axis([-0.05 2.05 -0.15 5.15]) axis([-0.05 2.05 -0.15 5.15])
i = 1; i = 1;
hold on hold on
for c = [c1 c2 c3 c4] for c = [c1 c2 c3 c4]
%plot([xl, xh], [subs(c, x1, xl), subs(c, x1, xh)]); pl = patch([xl, xl, xh, xh], ...
hatchfill(patch([xl, xl, xh, xh], ... double([-0.15, subs(c, x1, xl), subs(c, x1, xh), -0.15]), ...
double([-0.15, subs(c, x1, xl), subs(c, x1, xh), -0.15]), ... colors(i, :));
colors(i, :)), ... pl.EdgeColor = colors(i, :);
'HatchColor', colors(i, :), 'HatchOffset', (i-1)/5, 'HatchAngle', 45); pl.FaceAlpha = .2;
pl.EdgeAlpha = .2;
i = i + 1; i = i + 1;
end end
%xline(0);
hatchfill(patch([0, 0, xh, xh], ... pl = patch([0, 0, xh, xh], ...
double([0, 5.15, 5.15, 0]), ... double([0, 5.15, 5.15, 0]), ...
'white'), ... grey);
'HatchColor', [249/255 216/255 49/255], 'HatchOffset', 4/5, 'HatchAngle', 45); pl.EdgeColor = grey;
%plot([xl, xh], [0, 0]); pl.FaceAlpha = .2;
hatchfill(patch(px, py, 'black'),'HatchColor', 'black', 'HatchAngle', 90); pl.EdgeAlpha = .2;
alpha(.02)
legend('','2x1 + 3x2 <= 6', '', '-3x1 + 2x2 <= 3', '', '2x2 <= 5', ... pl = patch(px, py, 'green');
'', '2x1 + x2 <= 4', '', 'x1 > 0 and x2 > 0', '', 'feasible region'); pl.EdgeColor = 'green';
legend('2x1 + 3x2 <= 6', '-3x1 + 2x2 <= 3', '2x2 <= 5', ...
'2x1 + x2 <= 4', 'x1 > 0 and x2 > 0', 'feasible region');
hold off hold off
%% gsppn
for i=1:5
obj = 4 * px(i) + 3 * py(i);
fprintf("x1=%g x2=%g y=%g\n", px(i), py(i), obj);
end
%% Exercise 3.2 %% Exercise 3.2
G = [6 2 1; 2 5 2; 1 2 4]; G = [6 2 1; 2 5 2; 1 2 4];