% Exempel 2:
%
% Hitta max/min för f(x,y)=xy under bivillkoret
% g(x,y)=5*x^2-6*x*y+5*y^2-16=0

F = @(x,y) x.*y;
G = @(x,y) 5*x.^2-6*x.*y+5*y.^2-16;

x = -2.5:0.1:2.5; 
y = -2.5:0.1:2.5;

[X,Y]=meshgrid(x,y);

figure(1);

hh=surf(X,Y,F(X,Y)); 
set(hh,'FaceAlpha',.8)
hold on;

th = 0:pi/20:2*pi;

u = 2*cos(th);
v = sin(th);

xc = u + v; % This is G=0
yc = u - v;

plot3(xc,yc,F(xc,yc),'-k','LineWidth',2);

view(-40,20)
hold off

figure(2)

plot3(xc,yc,F(xc,yc),'-k','LineWidth',2);
grid on
