function ue4_A1

% Uebung 4 Aufgabe 1


% a)
[X,Y]=meshgrid(-10:1:10);                   % Gitternetz

Z1=2.*X.^2-2.*X.*Y+Y.^2+5.*X+Y+3;           % Funktion f(x) fuer (i)
Z2=2.*X.^2-2.*X.*Y+0.5.*Y.^2+5.*X+Y+3;      %                    (ii)
Z3=2.*X.^2-2.*X.*Y-1.*Y.^2+5.*X+Y+3;        %                    (iii)
Z4=-2.*X.^2-2.*X.*Y-Y.^2+5.*X+Y+3;          %                    (iv)

figure(1)
subplot(2,2,1) 
meshc(X,Y,Z1)
title('(i) Q=[4 -2; -2 2]')
subplot(2,2,2)
contour(X,Y,Z1,[-100,-10, 0,10, 20, 30, 40, 50, 60, 70, 80, 90,100, 120, 130])

subplot(2,2,3)
meshc(X,Y,Z2)
title('(ii) Q=[4 -2; -2 1]')
subplot(2,2,4)
contour(X,Y,Z2,[-100,-10, 0,10, 20, 30, 40, 50, 60, 70, 80, 90,100, 120, 130])

figure(2)
subplot(2,2,1)
meshc(X,Y,Z3)
title('(iii) Q=[4 -2; -2 -2]')
subplot(2,2,2)
contour(X,Y,Z3,[-100,-10, 0,10, 20, 30, 40, 50, 60, 70, 80, 90,100, 120, 130])

subplot(2,2,3)
meshc(X,Y,Z4)
title('(iv) Q=[-4 -2; -2 -2]')
subplot(2,2,4)
contour(X,Y,Z4,[-300:50:-100, -90:10:-10, 0])

% b) Rosenbrockfunktion
[X,Y]=meshgrid(-2:0.1:2,-1:0.1:3);
Z5=100*(Y-X.^2).^2+(1-X).^2;

figure(3)
subplot(1,2,1)
meshc(X,Y,Z5)
title('Rosenbrockfunktion')
subplot(1,2,2)
contour(X,Y,Z5,[5,10:10:100, 150:50:550])
