% Exempel 1:
%
% Hitta max/min för f(x,y)=x^2+y^2-2x i halvcirkeln
% x^2+y^2<=2, x>=0.

F = @(x,y) x.^2 + y.^2-2*x;

R0 = sqrt(2);

r=0:0.1:R0;
th= -pi/2:pi/20:pi/2;
[R,TH]=meshgrid(r,th);

X = R.*cos(TH);
Y = R.*sin(TH);

hh=surfc(X,Y,F(X,Y)); axis equal
set(hh,'FaceAlpha',.8)

hold on;

a = 1; b = 0;

plot(R0*cos(th),R0*sin(th),'-k',[0 0],[-R0 R0],'-k','LineWidth',1.5);

h=surf(X,Y,0*X);
set(h,'EdgeColor','none')
set(h,'FaceColor',[1 1 1]*.9)
set(h,'FaceAlpha',.8)
view(-40,20)

hold off

