This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
OM/hw1/ex3.m

49 lines
885 B
Mathematica
Raw Normal View History

2021-03-21 21:54:15 +00:00
% Sources:
% https://www.youtube.com/watch?v=91RZYO1cv_o
2021-03-21 14:05:22 +00:00
%% Exercise 3.1
% f(x1, x2) = x1^2 + u * x2^2;
2021-03-21 21:54:15 +00:00
% 1/2 * [x1 x2] [2 0] [x1] + [0][x1]
% [0 2u] [x2] + [0][x2]
2021-03-21 14:05:22 +00:00
% A = [1 0; 0 u]; b = [0; 0]
%% Exercise 3.2
for u = 1:10
A = [1 0; 0 u];
xs = -10:1:10;
ys = xs;
Z = zeros(size(xs, 2), size(ys, 2));
for i = 1:size(xs, 2)
for j = 1:size(ys, 2)
vec = [xs(i); ys(j)];
Z(i, j) = vec' * A * vec;
end
end
if u <= 5
fig = u;
con = 5 + u;
else
fig = 10 + u - 5;
con = 15 + u - 5;
end
subplot(4, 5, fig);
h = surf(xs, ys, Z);
set(h,'LineStyle','none');
title(sprintf("Surf for u=%d", u));
subplot(4, 5, con);
contour(xs, ys, Z, 20);
title(sprintf("Contour for u=%d", u));
2021-03-21 21:54:15 +00:00
end
matlab2tikz('showInfo', false, './ex32.tex')