function []=code2;
% Draws a cylinder in 3-space
% The cylinder equation may be in terms of xy,xz,or yz.
% In each case, a different meshgrid needs to be created
% The meshgrid sets up a grid of coordinates for plotting the function
% For more information, type >> help meshgrid
% Uncomment the lines below for each example
%=========================================================

% Example 1: xy, to plot y=x^2
% Set up a domain for x and the missing z
[x,z]=meshgrid(-2:0.1:2,[-2,2]);
y=x.^2;
surf(x,y,z);

% -----------------------------------------------------------
% Example 2: yz, to plot a vertical plane x+2y=3
% Set up a domain for y and the missing z
%[y,z]=meshgrid(-1:0.1:2,[-1,1]);
%x=3-2*y;
%surf(x,y,z);

% -----------------------------------------------------------
% Example 3: xz, to plot z=4-x^2
% Set up a domain for x and the missing y
%[x,y]=meshgrid(-2:0.1:2,[0,4]);
%z=4-x.^2;
%surf(x,y,z);

%------------------------------------------------------------
% Add labels and titles
xlabel('x'); ylabel('y'); zlabel('z');
title('Cylinder');
view(120,20);

% Draw a set of axes
xmax=max(max(x)); ymax=max(max(y)); zmax=max(max(z));  
line([0,xmax],[0,0],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,ymax],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,0],[0,zmax],'LineWidth',2,'Color','r');
text(xmax+0.1,0,0,'X','Color','r','FontSize',15);
text(0,ymax+0.1,0,'Y','Color','r','FontSize',15);
text(0,0,zmax+0.01,'Z','Color','r','FontSize',15);
xlabel('x'); ylabel('y'); zlabel('z');
title('Surface');
