0% found this document useful (0 votes)
9 views12 pages

M&SM Lab2

modeling and simulation lab 2 report

Uploaded by

msohaib0088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

M&SM Lab2

modeling and simulation lab 2 report

Uploaded by

msohaib0088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Modeling and Simulation in Mechatronics (MT-373)

Lab Manual

STUDENTS NAME Muhamamd Sohaib

SESSION BEMTS-F21-A

LAB NO 2

SUBMITTED TO Sir Hamza Shabbir Minhas

DATE 19th feb,2024

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)

Notice that, by default, MATLAB® connects the points with straightline


segments. An alternative is the following.

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 1960 1970 1980 1990


Population 26183 43704 61138 77240 88109

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

2. Colors, Line Styles, and Markers


To change the line color, line style, and marker type, add a line specification string to the x,
y pair. For example, adding the string, 'g: *', plots a green dotted line with star markers. You
can omit one or more options from the line specification, such as 'g:' for a green dotted line
with no markers. To change just the line style, specify only a line style option, such as '--' for
a dashed line.

x = linspace(0,2*pi,100);y = sin(x);
plot(x,y,'g: *')

i. Specify Line Style


This example shows how to create a plot using a dashed line. Add the optional line
specification string, '--', to the x, y pair.

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

ii. Specify Different Line Styles for multiple lines.


This example shows how to plot two sine waves with different line styles by adding a line
specification string to each x, y pair. Plot the first sine wave with a dashed line using '--'.
Plot the second sine wave with a dotted line using ':'.

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')

iv. Specify Line Style, Color, and Markers


This example shows how to specify the line style, color, and markers for two sine waves. If
you specify a marker type, then plot adds a marker to each data point. Define x as 25 linearly
spaced values between 0 and 2 . Plot the first sine wave with a green dashed line and circle
markers using '--go'. Plot second sine wave with a red dotted line and star markers using ':
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

v. Plot Data Points


This example shows how to plot only the data points by omitting the line style option from
the line specification string. Define the data x and y. Plot the data and display a star marker
at each data point.
x = linspace(0,2*pi,25);
y = sin(x);
plot(x,y,'*')

Page |
(Department of Mechatronics and Biomedical Engineering)
Modeling and Simulation in Mechatronics (MT-373)
Lab Manual

3. Create Simple Line Plot


Define x as 100 linearly spaced values between -2 and 2 . Define y1 and y2 as sine and
cosine values of x. Create a line plot of both sets of data.

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 .

title('Graph of Sine and Cosine Between -2\pi and 2\pi')

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)

ii. Surface Plot


MATLAB® graphics defines a surface by the z-coordinates of points above a rectangular
grid in the x-y plane. The plot is formed by joining adjacent points with straight lines. Surface
plots are useful for visualizing matrices that are too large to display in numerical form and for
graphing functions of two variables.
surf(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)

You might also like