% fig1.m 96/08/13
%
% Figure showing constraint curve x^2+y^2=1 and level curves of
% function f(x,y)=3x+4y
% 

% Plot circle

    np=80;
    zi=sqrt(-1);
    theta=2*pi*(0:40)'/40;
    circ=exp(zi*theta);
    plot(circ,'w-')
    hold on;
    axis([-2 2 -2 2]);
    axis square;
    xlabel('x');
    ylabel('y');

% Plot level curves of f(x,y)

    x=(-2:.1:2);
    y=(-2:.1:2);
    [X,Y]=meshgrid(x,y);
    Z=6*X+8*Y;
    v=[-20 -15 -10 -5 0 5 10 15 20];
%    v=[-9 -7 -5 -3 -1 1 3 5 7 9];
    contour(x,y,Z,v,'w-');

% Write contour values

    text(-1.4,-1.6,'-20')
    text(-0.7,-1.55,'-15')
    text(0.03,-1.4,'-10')
    text(0.6,-1.2,'-5')
    text(1.1,-.85,'0');
    text(1.3,-.4,'5');
    text(1.4,.1,'10');
    text(1.5,.7,'15');
    text(1.6,1.25,'20');

% Create normal vectors 

    p1=[.6; .8];
    p2=1.5*p1;
    arrow(p1,p2,.2);

    pm1=-p1;
    pm2=-1.5*p1;
    arrow(pm1,pm2,.2);

    hold off;
