% Created by Dr. Nishant Malik for Math 233, Fall Semester 2012 at UNC-Chapel Hill.
% Helix inside a cylinder. Filename : prg1.m
% Example 4 pp. 818 in the textbook Calculus Early Transcendentals 6E by James Stewart.


% Generate 1-D array t with its value ranging from 0 to 20 in steps of 0.1.
t=[0:0.1:20];



% Defining the parametric equations for the curve.
x=cos(t); y=sin(t);z=t;

% plotting the curve in 3-D
plot3(x,y,z,'r-','linewidth',2)


% Hold the above plot on the figure before next is plotted.
hold on;

% Cylinder with 20 rulings and radius 1.
[x,y,z]=cylinder(1,20);

% Changing the height of this cylinder.
z(2,:)=20;

% Plotting the cylinder.
h2=surf(x,y,z);

% Making the cylinder transparent.
set(h2,'FaceAlpha',0.5);

% View angles for the figure
view(-110,30);
% Created by Dr. Nishant Malik for Math 233, Fall Semester 2012 at UNC-Chapel Hill.
% Intersection of a cylinder and plane. Filename : prg2.m
% Example 6 pp. 819 in the textbook Calculus Early Transcendentals 6E by James Stewart.


% Creating a 2-D grid to generate a surface plot.
[x,y]=meshgrid(-2.0:0.5:2.0);

% Equation of the plane.
z=2-y;

% Plotting the plane.
h1=surf(x,y,z);


% Hold the above plot on the figure before next is plotted.
hold on;

% Cylinder with 20 rulings and radius 1.
[x,y,z]=cylinder(1,20);

% Changing the height of this cylinder.
z(2,:)=4;

% Plotting the cylinder.
h2=surf(x,y,z);

% Making the cylinder transparent.
set(h2,'FaceAlpha',0.5);

% View angles for the figure
view(-110,30);
% Created by Dr. Nishant Malik for Math 233, Fall Semester 2012 at UNC-Chapel Hill.
% Toroidal Spiral. Filename : prg3.m
% Figure 7 pp. 820 in the textbook Calculus Early Transcendentals 6E by James Stewart.

% Defining vector of values of the parameter.
t=[0:0.01:20];

% Defining the parametric equations for the curve.
x=(4+sin(t.*20)).*cos(t);
y=(4+sin(t.*20)).*sin(t);
z=cos(t.*20);

% Plotting the curve in 3-D.
plot3(x,y,z,'r-','linewidth',2)

% Set the axis limits.
axis([-5.5,5.5,-5.5,5.5,-1.5,1.5])

% Show axis grid in the background.
grid on ;
% Created by Dr. Nishant Malik for Math 233, Fall Semester 2012 at UNC-Chapel Hill.
% Trefoil Knot. Filename : prg4.m
% Figure 8 pp. 820 in the textbook Calculus Early Transcendentals 6E by James Stewart.



% Curve :

% Defining vector of values of the parameter.
t=[0:0.01:20];

% Defening the parametric equations for the curve.
x=(2+sin(t.*1.5)).*cos(t);
y=(2+sin(t.*1.5)).*sin(t);
z=sin(t.*1.5);

% Plotting the curve in 3-D.
plot3(x,y,z,'r-','linewidth',2)

% Set the axis limits.
axis([-4.5,4.5,-4.5,4.5,-1.5,1.5])

% Show axis grid in the background.
grid on ;