Theory of Machines Lab#3
Theory of Machines Lab#3
Lab No: 03
Below Basic
Excellent (4) Proficient (3) Basic (2) Student’
Criteria (1) s Score
Report is mostly Report is
Report is as per
as per the disorganized Sections/Steps
the guidelines.
To organize the lab guidelines and and follows are not
All
report and practice most some ordered and
sections/steps
the writing skills as sections/steps are guidelines but Report is not
are clearly
per the guidelines ordered well but most of the as per the
organized in a
requires minor guidelines are guidelines
logical order.
improvements. missing
The report
completely
The report
discusses the The report is
The report discusses the
To discuss the required task in totally
discusses the lab work but
actual task own words with irrelevant to
required task have irrelevant
some relevant the lab work
information
additional
information
Calculations and
Calculations Most data and
data analysis
and data observations
were performed Calculations
analyses were were recorded
To perform accurately, but and data
performed adequately, but
calculations and minor errors were analyses of
clearly, with several
data analysis made both in lab were
concisely, and significant
calculations and missing
accurately, with errors or
in applying
correct units. omissions.
correct units
Graphs, if
necessary, were Graphs, if Major
To present results Graphs, if
drawn necessary, were components
in the form of necessary, were
accurately and drawn but of lab were
graphs drawn adequately
neatly and were inadequately. missing
clearly labelled.
1
MtE-323L, Theory of Machines Lab, 5th Semester
Objectives:
To study basics of MATLAB animation and plotting
How to developed different part of crank slider using MATLAB code
To developed crank slider mechanism using MATLAB code
Apparatus:
Laptop
MATLAB Software 2019 Version
Theory:
MATLAB:
MATLAB is been used for many useful purposes around the globe in engineering fields such
as, it includes deep learning and machine learning, signal processing and communications,
image and video processing, control systems, test and measurement. MATLAB is a high-
performance language for technical computing. It is used for analytical modeling, simulation,
and visualization. MATLAB (matrix laboratory) is a fourth-generation high-level
programming language and interactive environment for numerical computation, visualization
and programming. It has numerous built-in commands and math functions that help you in
mathematical calculations, generating plots, and performing numerical methods. It can
perform every basic and advanced arithmetic operation.
Main Features:
Easy to use built in function
Easy interface
Add other library and tool box
It has numerical, graphical, and programming capabilities
2
In Lab Activity:
In this lab we learned and wrote different codes in MATLAB for various different
purposes, such as:
We wrote a code for plotting a graph in MATLAB
Then we wrote a code to plot multiple graph’s
Then after this we also wrote a code to change the colour of the graph
We also typed and run the code to indicate the plotted graph for various depended
variables, such as legend code
We also typed a code to label our x and y axis of our graph in MATLAB
Then we also wrote a code for a line in MATLAB
We also wrote a code for plotting arc and circle in MATLAB through coding as
shown below
All the in lab tasks and their codes along with results are given below
In Lab Tasks:
>>xlabel(‘time’)
>>ylabel(‘sin(x)’)
>>legend ('sin_x')
>> grid on
3
Figure 1: Plot Result
Code:
>> x= 0:pi/100:2*pi;
>> y = sin(x);
>> y2 = sin(x-0.25);
y3 = sin(x-0.5);
plot(x,y,x,y2,x,y3)
>> plot(x,y,x,y2,x,y3,'r-*')
4
Figure 2: Results of MATLAB Window Workspace
5
Figure 3: MATLAB code and its Result
Subplots:
Code:
subplot(m,n,p)
m= Rows
n= columns
p= position
>> x=0:0.1:2*pi;
>> y=sin(x);
>> subplot(1,2,1);
>> plot(y)
Example:
6
Figure 4: MATLAB code and its Result for subplot code
barh(x,y)
7
Figure 6: Function creates horizontal Bar plot
stairs(x,y)
compass(x,y)
8
Figure 8: Function creates polar plot Location of points to plot in “Cartesian coordinates”
pie(x)
9
3rd. Step: calculate the vertical values of your points. y = sin(angle);
4th. Step: plot your 360 pairs of x and y values.
plot(x, y)
5th. Step: force your x distance to equal your y-distance in the plot axis('equal’);
Plot Multiple Sine, Cosine wave form in one graph using following
Commands:
1.Title (name & Registration No.)
2.Different color for each waveform.
3.Legend command
4.Axis labelling.
Code:
>> x=0:pi/100:2*pi;
>> y=sin(x);
>> y1=cos(x);
>> plot(x,y,'g-','k-*');
>> plot(x,y,'g-',x,y1,'k-*');
>> title('Muhammad Shaheer 19pwmct0706')
>> xlable('x axis');
Did you mean:
>> xlabel('x axis');
>> ylabel('y axis');
>> legend('sin(x)','cos(x)')
10
Procedure:
First of all, I selected an in depended variable x, and give it some value as shown in
the code
Then I took two dependent variable y and y1
Then I used the plot function to plot their graph
I also changed their colour by using the required code function as shown in the code
above
Then I used the title command
Then for axis’s x and y I used the command xlabel and ylabel commands
To locate the indication of the graphs plotted I used the legend command
11
Figure 12: MATLAB Result for 3D Plotting Code
12
For Plotting Arc:
Code:
xCenter = 1;
yCenter = 1;
radius = 4;
theta =linspace(20, 100, 50);
x =radius * cosd(theta)+xCenter;
y = radius *sind(theta)+yCenter;
plot(x, y,'r-','LineWidth',4);
axis equal;
grid on;
Home Task:
Developed a Code for Crank Slider Mechanism in Matlab
Code:
angle = linspace(0,720,500);
for k=1:length(angle)
x=linspace(cosd(angle(k)),0);
y=linspace(sind(angle(k)),0);
a=linspace(cosd(angle(k)),cosd(angle(k))+2);
z=linspace(sind(angle(k)),0);
x2=linspace(cosd(angle(k))+2.5,cosd(angle(k))+1.5);
y2=linspace(0,0);
plot(x,y,a,z,x2,y2)
13
set(gca,'xLim',[-5 5],'yLim',[-5 5])
drawnow
end
References:
"MATLAB," 26 May 2021. [Online]. Available: https://en.wikipedia.org/wiki/MATLAB.
Online available at getintopc.com link: https://getintopc.com/softwares/mathworks-matlab-
2018-free-download-4777289/
14