M&SM Lab2
M&SM Lab2
Lab Manual
SESSION BEMTS-F21-A
LAB NO 2
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
Lab # 02
To plot functions and applications in MATLAB®
Objective
To plot functions and applications in MATLAB®
i. 2-D plot
ii. 3-D plot
iii. Surface Plot
1. Plot
The simplest graphs to create are plots of points in the Cartesian plane. Forexample:
x = [1;2;3;4;5];
y = [0;.25;3;1.5;2];
plot(x,y)
x = [1;2;3;4;5];
y = [0;.25;3;1.5;2];
plot(x,y,'o') %only data points will be plotted
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
Year=1950:10:1990
Population=[26183 43704 61138 77240 88109]
Plot(year, population)
i. 2D Line Graph
This example shows how to create a simple line graph. Use the linspace function to
define x as a vector of 100 linearly spaced values between 0 and 2.
x = linspace(0,2*pi,100);y = sin(x);
plot(x,y)
Create a stair step plot of y versus x. Open a new figure window using the figure
command. If you do not open a new figure window, then by default, MATLAB®
clears existing graphs and plots into the current figure.
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
x = linspace(0,2*pi,100);y = sin(x);
plot(x,y,'g: *')
x = linspace(0,2*pi,100);y = sin(x);
plot(x,y,'--')
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
x = linspace(0,2*pi,100);y1 = sin(x);
y2 = sin(x-pi/4);
plot(x,y1,'--',x,y2,':')
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
iii. Specify Line Style and Color
This example shows how to specify the line styles and line colors for a plot. Plot a sine wave
with a green dashed line using '--g'. Plot a second sine wave with a red dotted line using ': r'.
The elements of the line specification strings can appear in any order.
x = linspace(0,2*pi,100);y1 = sin(x);
y2 = sin(x-pi/4);
plot(x,y1,'--g',x,y2,':r')
x = linspace(0,2*pi,25);
y1 = sin(x);
y2 = sin(x-pi/4);
plot(x,y1,'--go',x,y2,':r*')
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
Add a title to the graph using the title function. Pass the title function a text string with the
desired title. To display Greek symbols in a title, use the TeX markup. Use the TeX markup,
\pi, to display the Greek symbol .
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
Add axis labels to the graph using the xlabel and ylabel functions. Passthese functions a
text string with the desired label.
xlabel('-2\pi < x < 2\pi') % x-axis label ylabel('sine and cosine values') % y-
axis label
Add a legend to the graph identifying each data set using the legend function. Pass the
legend function a text string description for each line. Specify legend descriptions in the
order that you plot the lines.
legend('y = sin(x)','y = cos(x)')
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
4. 3D Plot
i. Mesh Plot
The mesh function creates a wireframe mesh. By default, the color of the mesh is
proportional to the surface height.
z = peaks(25);
mesh(z)
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
iii. Contour Plot
The contour function is used to create a plot with contour lines of constant value.
contour(z,16)
Conclusion:
In this lab we learned about plots. We drew different types of graphs, we implemented some basic
commands and obtained there graphs. We learned to draw graphs using different shapes and symbols.
We learned how we can see output in different forms using surface, mesh and contour command.
Assessment
Focused PLOs for this lab are PLO 5 (P4-CLO 1) and PLO 9 (A4-CLO 2) as mentioned in the course
outline. The assessment is done according to the rubrics and marked as follows:
Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual
PLO 5: Modern Tool Usage (Assembles, Calibrates, Constructs, Dismantles, Displays, Fastens,
Fixes, Grinds, Heats, manipulate, Measure, Mends, Mixes, Organizes, Sketches)
Attributes No Progress Minimal Basics Adequate Good Excellent
0 1 2 3 4 5
Software Understand
based Modeling the
functions Understand Understand
Understand of the plots the the
the & operate functions of functions of
functions of their the plots plots
the plots functions with properly
Don’t but can’t on Matlab properly with
understand operate the but can’t simulations accurately
the different simulate on MatLab simulation
Mostly unaware functions of functions of the but can’t on Matlab &
the software the 2D, 3D plot in functions analyze the explain the
operations plots Matlab properly results results
Does not Does not Can only Can start Can start Can start
Simulations comprehend comprehend start the simulator, simulator, simulator,
Matlab model model them model them
software them by by using by using
for the using basic & basic &
simulations basics but advance advance
deficiency commands commands
to but lacks in & presents
understand analysis of the results
advance results with
commands complete
explanation
PLO 9: Individual and Teamwork (Adheres, Alters, Arranges, Combines, Compares, Completes,
Defends, Explains, Formulates, Generalizes, Identifies, Integrates, Modifies, Orders, Organizes,
Prepares, Relates, Synthesizes)
Attributes No Progress Minimal Basics Adequate Good Excellent
0 1 2 3 4 5
Individual Does not Partially Inconsistently Perform Perform all
Performance perform any perform with performs Performs duties that duties
duties no interest duties that are duties are assigned assigned and
assigned with that are with minor actively
little interest assigned negligence assists
others
Teamwork No working Interaction Partially does Usually Always does
coordination with only the assign Usually does assigned
selective work often does assigned work &
members needs assigned work rarely gladly helps
with no reminding work needs others and is
involvement with little reminding involved in
in discussions & constructive
constructive discussions discussions
discussions
Page |
(Department of Mechatronics and Biomedical Engineering)