0% found this document useful (0 votes)
39 views

Theory of Machines Lab#3

The document is a lab report for an Introduction to Mechanism of Machine using MATLAB course. It discusses using MATLAB to develop different parts of a crank slider mechanism through coding. Various MATLAB codes are presented to plot graphs, change colors, label axes, and plot circles, arcs, and sine/cosine waves. The student scored proficient marks by presenting an organized report that discussed the tasks, showed accurate calculations and analyses with minor errors, and included adequately drawn graphs.

Uploaded by

Muhammad Shaheer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Theory of Machines Lab#3

The document is a lab report for an Introduction to Mechanism of Machine using MATLAB course. It discusses using MATLAB to develop different parts of a crank slider mechanism through coding. Various MATLAB codes are presented to plot graphs, change colors, label axes, and plot circles, arcs, and sine/cosine waves. The student scored proficient marks by presenting an organized report that discussed the tasks, showed accurate calculations and analyses with minor errors, and included adequately drawn graphs.

Uploaded by

Muhammad Shaheer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

DEPARTMENT OF MECHATRONICS ENGINEERING

UNIVERSITY OF ENGINEERING & TECHNOLOGY, PESHAWAR

MtE-323L, Theory of Machines Lab, 5th Semester

Student Name: Muhammad Shaheer______

Reg No: 19pwmct0706_____

Lab No: 03

Lab Tittle: Introduction to Mechanism of Machine using MATLAB

Course Instructor: Engr. Wahad Ur Rahman

LAB REPORT RUBRICS:

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

 MATLAB has the following windows:


 The Command Window
 The Command History
 The Workspace
 The script file or M. file
 The Help Browser etc.

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 Codes and Results:

In Lab Tasks:

 Plotting a graph in MATLAB:


 Code:
>>title(‘This is the sinus function’)

>>xlabel(‘time’)

>>ylabel(‘sin(x)’)

>>legend ('sin_x')

>> grid on

>> grid off

3
Figure 1: Plot Result

 Plotting Multiple Graphs in MATLAB:

 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

 Line specifiers in the plot(t) command:

 The fplot Command:


 Code:
 fplot (‘function’,[limits])
 Now plotting the equation, so we get the following results:

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)

>> title('sin(x) wave')

Example:

6
Figure 4: MATLAB code and its Result for subplot code

 Additional Plotting Graphs:


 Codes and their Results are attached below:
 bar(x,y)

Figure 5:Function creates vertical Bar plot

 barh(x,y)

7
Figure 6: Function creates horizontal Bar plot

 stairs(x,y)

Figure 7: Function Creates Stair Plot

 compass(x,y)

8
Figure 8: Function creates polar plot Location of points to plot in “Cartesian coordinates”

 pie(x)

Figure 9: Function creates pie plot

 Plotting a Circle in MATLAB:


 There are five basic step code for this:
1st. Step: define the values of the angles to be considered.
angle = linspace(0, 2*pi, 360);
2nd. Step: calculate the horizontal values of your points. x = cos(angle);

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’);

Figure 10: MATLAB Results

 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

Figure 11: Results for Multiple Graph’s in MATLAB

 Now for 3D Plotting:


 Code:
t = 0:pi/50:10*pi;
st = sin(t);
ct = cos(t);
plot3(st,ct,t)

11
Figure 12: MATLAB Result for 3D Plotting Code

 For line Command:


 Code:
p1=[0 0];
p2=[20 20];
line([p1(1) p2(1)],[p1(2) p2(2)])

Figure 13: MATLAB Result for Line Command

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;

Figure 14: MATLAB Results for ARC Code

 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

Figure 15: MATLAB Results for Crank Sliding Mechanism

 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

You might also like