hw5: work
This commit is contained in:
parent
95b094f8b0
commit
1b092ab91c
5 changed files with 110 additions and 32 deletions
46
Claudio_Maggioni_5/Claudio_Maggioni_5.md
Normal file
46
Claudio_Maggioni_5/Claudio_Maggioni_5.md
Normal 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.
|
BIN
Claudio_Maggioni_5/Claudio_Maggioni_5.pdf
Normal file
BIN
Claudio_Maggioni_5/Claudio_Maggioni_5.pdf
Normal file
Binary file not shown.
BIN
Claudio_Maggioni_5/ex2-1.png
Normal file
BIN
Claudio_Maggioni_5/ex2-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
|
@ -20,36 +20,52 @@ 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)]);
|
||||
pysym = [0 subs(c2, x1, 0) subs(c1, x1, i1) subs(c4, x1, i2) subs(c4, x1, i3)];
|
||||
py = double(pysym);
|
||||
|
||||
xl = -0.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])
|
||||
i = 1;
|
||||
hold on
|
||||
for c = [c1 c2 c3 c4]
|
||||
%plot([xl, xh], [subs(c, x1, xl), subs(c, x1, xh)]);
|
||||
hatchfill(patch([xl, xl, xh, xh], ...
|
||||
double([0, subs(c, x1, xl), subs(c, x1, xh), 0]), ...
|
||||
colors(i, :)), ...
|
||||
'HatchColor', colors(i, :), 'HatchOffset', (i-1)/5);
|
||||
pl = patch([xl, xl, xh, xh], ...
|
||||
double([-0.15, subs(c, x1, xl), subs(c, x1, xh), -0.15]), ...
|
||||
colors(i, :));
|
||||
pl.EdgeColor = colors(i, :);
|
||||
pl.FaceAlpha = .2;
|
||||
pl.EdgeAlpha = .2;
|
||||
i = i + 1;
|
||||
end
|
||||
xline(0);
|
||||
hatchfill(patch([0, 0, xh, xh], ...
|
||||
|
||||
pl = patch([0, 0, xh, xh], ...
|
||||
double([0, 5.15, 5.15, 0]), ...
|
||||
'white'), ...
|
||||
'HatchColor', [1 0.5 0], 'HatchOffset', 4/5);
|
||||
plot([xl, xh], [0, 0]);
|
||||
patch(px, py, 'black');
|
||||
alpha(.05)
|
||||
legend('','2x1 + 3x2 <= 6', '', '-3x1 + 2x2 <= 3', '', '2x2 <= 5', ...
|
||||
'', '2x1 + x2 <= 4', '', 'x1 > 0 and x2 > 0', 'feasible region');
|
||||
grey);
|
||||
pl.EdgeColor = grey;
|
||||
pl.FaceAlpha = .2;
|
||||
pl.EdgeAlpha = .2;
|
||||
|
||||
pl = patch(px, py, 'green');
|
||||
pl.EdgeColor = 'green';
|
||||
|
||||
legend('2x1 + 3x2 <= 6', '-3x1 + 2x2 <= 3', '2x2 <= 5', ...
|
||||
'2x1 + x2 <= 4', 'x1 > 0 and x2 > 0', 'feasible region');
|
||||
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
|
||||
|
||||
G = [6 2 1; 2 5 2; 1 2 4];
|
||||
|
|
|
@ -20,36 +20,52 @@ 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)]);
|
||||
pysym = [0 subs(c2, x1, 0) subs(c1, x1, i1) subs(c4, x1, i2) subs(c4, x1, i3)];
|
||||
py = double(pysym);
|
||||
|
||||
xl = -0.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])
|
||||
i = 1;
|
||||
hold on
|
||||
for c = [c1 c2 c3 c4]
|
||||
%plot([xl, xh], [subs(c, x1, xl), subs(c, x1, xh)]);
|
||||
hatchfill(patch([xl, xl, xh, xh], ...
|
||||
pl = patch([xl, xl, xh, xh], ...
|
||||
double([-0.15, subs(c, x1, xl), subs(c, x1, xh), -0.15]), ...
|
||||
colors(i, :)), ...
|
||||
'HatchColor', colors(i, :), 'HatchOffset', (i-1)/5, 'HatchAngle', 45);
|
||||
colors(i, :));
|
||||
pl.EdgeColor = colors(i, :);
|
||||
pl.FaceAlpha = .2;
|
||||
pl.EdgeAlpha = .2;
|
||||
i = i + 1;
|
||||
end
|
||||
%xline(0);
|
||||
hatchfill(patch([0, 0, xh, xh], ...
|
||||
|
||||
pl = patch([0, 0, xh, xh], ...
|
||||
double([0, 5.15, 5.15, 0]), ...
|
||||
'white'), ...
|
||||
'HatchColor', [249/255 216/255 49/255], 'HatchOffset', 4/5, 'HatchAngle', 45);
|
||||
%plot([xl, xh], [0, 0]);
|
||||
hatchfill(patch(px, py, 'black'),'HatchColor', 'black', 'HatchAngle', 90);
|
||||
alpha(.02)
|
||||
legend('','2x1 + 3x2 <= 6', '', '-3x1 + 2x2 <= 3', '', '2x2 <= 5', ...
|
||||
'', '2x1 + x2 <= 4', '', 'x1 > 0 and x2 > 0', '', 'feasible region');
|
||||
grey);
|
||||
pl.EdgeColor = grey;
|
||||
pl.FaceAlpha = .2;
|
||||
pl.EdgeAlpha = .2;
|
||||
|
||||
pl = patch(px, py, 'green');
|
||||
pl.EdgeColor = 'green';
|
||||
|
||||
legend('2x1 + 3x2 <= 6', '-3x1 + 2x2 <= 3', '2x2 <= 5', ...
|
||||
'2x1 + x2 <= 4', 'x1 > 0 and x2 > 0', 'feasible region');
|
||||
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
|
||||
|
||||
G = [6 2 1; 2 5 2; 1 2 4];
|
||||
|
|
Reference in a new issue