function []=code3;
% Plot a surface z=f(x,y) and contours
% Create a rectangular grid in the xy plane
minx=-3; maxx=3; dx=0.1;
miny=-3; maxy=3; dy=0.1;
[x,y]=meshgrid(minx:dx:maxx,miny:dy:maxy);

% Enter your function
z=3*sin(y)./(x.^2+1);
%z=3*cos(2*y)./(abs(y)+sin(3*x)+5);
%z=((x.^2+y.^2)<=4).*(x.^2+2*y.^2-4*y-2);
%z=(x.*y)./(x-y);

% Draw the surface
% -------------------------------------------------------
% NOTE: To draw both the surface and contours below the surface,
% use the surfc command, otherwise just use the surf command for
% the surface without contours.
% -------------------------------------------------------

surfc(x,y,z);
view(120,20);
% surf(x,y,z);
colorbar v:

% Draw a set of axes
z1=min(min(z)); z2=max(max(z));
line([0,maxx],[0,0],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,maxy],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,0],[0,z2],'LineWidth',2,'Color','r');
text(maxx+0.1,0,0,'X','Color','r','FontSize',15);
text(0,maxy+0.1,0,'Y','Color','r','FontSize',15);
text(0,0,z2+0.1,'Z','Color','r','FontSize',15);
xlabel('x'); ylabel('y'); zlabel('z');
title('Surface');
% --------------------------------------------------------
% Draw contours in a separate figure window

figure;   % create a new figure window
contour(x,y,z,10);

xlabel('x'); ylabel('y'); zlabel('z');
title('Contours');
