Quiz #6 Matlab Solutions

Contents

Exercise #1

% close all open figure window
close all

% create the mesh
[x,y]=meshgrid(linspace(-5,5,50));

% calculate z-values
z=sqrt(x.^2+y.^2);

% draw and label the contours
[c,h]=contour(x,y,z);
clabel(c,h,'manual')

% labels and title
xlabel('x-axis')
ylabel('y-axis')
title('Level curves of f(x,y) = sqrt(x^2 + y^2).')

axis equal
 
    Please wait a moment...
 
   Carefully select contours for labeling.
   When done, press RETURN while the Graph window is the active window.

Exercise #4

% close all open figure window
close all

% domain for x and y
x=linspace(0,4,40);
y=linspace(-1,3,40);

% create the mesh
[x,y]=meshgrid(linspace(-5,5,50));

% calculate z-values
z=9-x.^2+x.*y-2*y.^2;

% calculate linearization
L=13-3*x-2*y;

% draw the surface
shndl=surf(x,y,z);
set(shndl,...
    'FaceColor','Magenta');

% hold
hold on

% draw the tangent plan
thndl=surf(x,y,L);
set(thndl,...
    'FaceColor','Yellow',...
    'FaceAlpha',0.5)

% labels and title
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('Linearization of f(x,y) = 9 - x^2 + xy - 2y^2')

view(130,30)