%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                            Michael Pokojovy                             % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function main()
figure(1);

set(gcf, 'PaperUnits', 'centimeters');
xSize = 20; ySize = 15;
xLeft = (21 - xSize)/2; yTop = (30 - ySize)/2;
set(gcf,'PaperPosition', [xLeft yTop xSize ySize]);
set(gcf,'Position',[0 0 xSize*50 ySize*50]);

hold on;

t = title(['H\"ohen- und Falllinien der Funktion ', '$f_{1}(x, y) = \frac{1}{2} x^{2} + y^{2}$'], 'interpreter', 'latex');
set(t, 'FontSize', 16);
 
xlabel('x');
ylabel('y');

c = 0:0.2:2;

for i = 1:length(c)
    plot_ellipse(sqrt(2*c(i)), sqrt(c(i)));
end

x0 = linspace(-2, 2, 10);
y0 = linspace(-1.5, 1.5, 10);

x = -2:0.05:2;

for i = 1:length(x0)
for j = 1:length(y0)
    y = y0(j)/x0(i)^2*x.^2;
    
    plot(x, y, 'r');
end
end

text(1.2, 1.4, 'H\"ohenlinien', 'interpreter', 'latex', 'FontSize', 16, 'color', 'blue');
text(1.2, 1.2, 'Falllinien',  'interpreter', 'latex', 'FontSize', 16, 'color', 'red');

axis([-2 2 -1.5 1.5]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2);

set(gcf, 'PaperUnits', 'centimeters');
xSize = 15; ySize = 15;
xLeft = (21 - xSize)/2; yTop = (30 - ySize)/2;
set(gcf,'PaperPosition', [xLeft yTop xSize ySize]);
set(gcf,'Position',[0 0 xSize*50 ySize*50]);

hold on;

t = title(['H\"ohen- und Falllinien der Funktion ', '$f_{2}(x, y) = x^{2}$'], 'interpreter', 'latex');
set(t, 'FontSize', 16);
 
xlabel('x');
ylabel('y');

c = linspace(-1.5, 1.5, 10);

for i = 1:length(c)
    plot([-1.5 1.5], [c(i), c(i)], 'r');
end

c = linspace(-1.5, 1.5, 10);

for i = 1:length(c)
    plot([c(i), c(i)], [-1.5 1.5], 'b');
end

text(0.9, 1.4, 'H\"ohenlinien', 'interpreter', 'latex', 'FontSize', 16, 'color', 'blue');
text(0.9, 1.2, 'Falllinien',  'interpreter', 'latex', 'FontSize', 16, 'color', 'red');

axis([-1.5 1.5 -1.5 1.5]);

end

function plot_ellipse(a, b)
    N = 50;
    
    phi = linspace(0, 2*pi, N);
    x = a*cos(phi);
    y = b*sin(phi);
    plot(x, y, 'b');
end