Professional Documents
Culture Documents
Activity #5
Activity #5
LABORATORY ACTIVITY #5
3 – Dimensional Plots
I. Learning Objectives:
At the end of the laboratory activity, the students should be able to:
1. To implement three – dimensional plots in MATLAB
2. Use 3 – dimensional plot, mesh, and surf plotting commands available in MATLAB
II. Introduction:
Three – Dimensional Plots
MATLAB is capable of generating three – dimensional plots. These three – dimensional plots may be
plotted with the use of the command plot3, mesh, and/or surf, among many other plotting commands available
in MATLAB.
x = exp(-0.05*t).*sin(t);
z-axis
y = exp(-0.05*t).*cos(t);
20
z = t; 10
0 0.5
0
-0.5
-0.5
-1 -1
y-axis x-axis
1 2
-1
-1
-2 -2
y x
z
-0.5
2
1 2
0 1
0
-1
4. Contour Plot y -2 -2
-1
x
Contour plot or topographic plot is a plot of contour lines that shows the contour of the land by means of
constant elevation lines. Along a contour the elevation is the same. Contour plot can help visualize the shape of
2
−[(𝑥−𝑦2 ) +𝑦2 ]
a function. It can be created with the syntax contour(x, y, z). Consider the function 𝑧 = 𝑥 𝑒 , generate
the surface plot for −2 ≤ 𝑥 ≤ 2 and −2 ≤ 𝑦 ≤ 2, with a spacing of 0.1.
Contour Plot
%Contour Plot 2
clear 1.5
[x,y] = meshgrid(-2:0.1:2);
z = x.*exp(-((x-y.^2).^2 + y.^2)); 1
contour(x,y,z),xlabel('x'),ylabel('y') 0.5
zlabel('z'),title('Contour Plot')
0
y
-0.5
-1
-1.5
-0.5
2
1 2
0 1
0
-1
-1
-2 -2
y x
0.5
n = 20;
[x,y,z] = sphere(n); -1
1
mesh(x,y,z), title('Mesh Plot of a Sphere') 0.5 1
xlabel('x-axis'), ylabel('y-axis') 0 0.5
y-axis -1 -1
x-axis
xlabel('x-axis'), ylabel('y-axis')
zlabel('z-axis'), axis('equal') -0.5
-1
0.5 1
0
0
-0.5
y-axis -1
x-axis
2. Surface Mesh Plot, Surface Surf Plot, Mesh and Contour in one plot, and emphasizing surface shape plot
Create a 3 dimensional plot of the function sinc(√𝑥 2 + 𝑦 2 ) using the following 3 – dimensional plots.
Generate the surface plot for −8 < 𝑥 < 8, −8 < 𝑦 < 8, with a spacing of 0.5. Include label for each axis and a
title.
a) Surface mesh plot
b) Surface surf plot
c) Mesh and contour plot
d) Emphasizing surface shape plot
3. Three – Dimensional Surf Surface Plot and Emphasizing Surface Shape Plot of a Sphere
Generate the 3 dimensional surf surface plot and with emphasis on the surface shape plot of a sphere
with n = 60.
t = [0:pi/10:3*pi];
n = 0.5 + exp(-0.5*t).*sin(2*t);
[x,y,z] = cylinder(n);
t = [0:pi/10:2*pi];
n = 2 + cos(t);
[x,y,z] = cylinder(n);
t = [0:pi/10:2*pi];
n = 2 + sin(t);
[x,y,z] = cylinder(n);
t = [0:pi/20:2*pi];
n = 20 + exp(0.5*t).*sin(2*t);
[x,y,z] = cylinder(n);