Professional Documents
Culture Documents
Suez University
MDP2218
Dynamics of Machines
Assoc. Prof. Dr. Mohamed Aziz
Dynamics of Machines
• Total marks (100)
• Final Exam (60) (3 hours)
• Year work (40) = (MT15+Q10+R5+A10)
References
• Kinematics and Dynamics of Machinery by Charles E. Wilson,
Peter Sadler
• Kinematics and Dynamics of Machines by George H. Martin
• Michael M Stanisic - Mechanisms and Machines_ Kinematics,
Dynamics, and Synthesis-Cengage Learning (2015)
1. Introduction to MATLAB®
MATLAB is one of the most widely used examples of engineering software in the
world. The main reason for its wide implementation of common tasks in
engineering (solving systems of equations, plotting) in very easy manner. This
chapter introduce you to some of the basic concepts in MATLAB
After typing this you should see the variables a and b appear in the Workspace
window,
Workspace panel (window), which lists all the MATLAB variables currently in
memory.
1.1.1. Vector in MATLAB
To enter a vector into MATLAB we use square brackets:
As a row vector:
>> a=[2 4 6]
a =
2 4 6
To access a particular entry in a, you would use the index enclosed in regular
parentheses. In the Command Window type
>> a(3)
ans =
6
Now type
>> a(2)
ans =
4
A column vector:
Semicolons (;) to separate each row and that the semicolons have also appeared in
the Workspace window
>> b = [3;5;7]
b =
3
5
7
The command size() is a built-in MATLAB function that gives the dimensions of
a vector or matrix.
Remember that in multiplying a and b, we are multiplying two vectors, not two
numbers.
The dot product
Is defined as
a · b = a1b1 + a2b2 + a3b3
the size of a*b is 1 × 1, in other words a single number (a scalar). The size of b*a,
on the other hand, is 3 × 3.
The transpose operation
To convert a row vector into a column vector we can use the transpose operation,
To enter a matrix
you would type
>> A =[2 4 6; 3 5 7]
A =
2 4 6
3 5 7
The A matrix has dimension 2 × 3. To access the first row, third column of A, type
>> A(1,3)
ans =
6
1.1- Vector Notation in MATLAB®
Entering vectors one number at a time is fine for small vectors, but there will be
times when we wish to define vectors with hundreds, or even thousands, of entries.
Luckily,
MATLAB has an easy way to do this using the simple colon operator.
Try typing
>> a=0:10
a =
0 1 2 3 4 5 6 7 8 9 10
If we want a different spacing, we place the increment between the first and last
numbers
>> a=0:2:10
a =
0 2 4 6 8 10
Example
The list of odd numbers between 1 and 11.
>> b=1:2:11
b =
1 3 5 7 9 11
Or, even, numbers between 1 and 11.
>> b = a + 1
b =
1 3 5 7 9 11
Square matrix
If A is a square matrix, then A^2 = A*A. to do this use the dot-carat notation
before the operator.
>> c=2.^a
c=
1 4 16 64 256 1024
Placing the dot before the carat (or a multiplication symbol) tells MATLAB to
perform the operation on each element.
1.1- A First Plot
command for plotting in MATLAB is:
plot(c)
After you hit Enter, a new plot window should open that resembles
plot(x,y)
The first argument is a vector of x values on the plot and the second argument is a
vector of the corresponding y values.
1.1- Writing a Simple MATLAB® Script
Create m-file
A script is a series of MATLAB commands that we store in a file called an m-file.
On the Home tab in the Command Window click on the New button and choose
Script from the pulldown menu.
When we are done typing the script, we can hit the Run button (or the F5 key) to
execute it.
The result will be the same, for the most part, as if we had typed each command,
one after the other, in the Command Window.
Clears all
This clears all the variables that are in memory so that you can start with a “clean
slate.”
clear variables; close all; clc
Example
We’ll calculate the sine function in 1° increments
x = 0:360;
theta = x*pi/180;
This multiplies each value in the vector x by π/180. Note that pi is a built-in
constant in
MATLAB. Now that we have theta in radians, we can calculate the sine of theta
y = sin(theta);
theta is a vector with 361 elements; calculating the sine of theta also results in a
vector of 361 elements. Thus, y(1) = sin(0) and y(361) = sin(2π).
plot(UnitSquare(1,:),UnitSquare(2,:),'LineWidth',2)
xlabel('x (m)'); xlim([-2 2])
ylabel('y (m)'); ylim([-2 2])
grid on
axis equal
used to fix stretched in the x or y direction if the x axis is much wider than the y
axis.
axis equal
filled polygon
To make a filled polygon
fill(UnitSquare(1,:),UnitSquare(2,:),'b','LineWidth',2)
The fill command requires that you specify a color (in this case ‘b’ means blue)
right after you give the x and y coordinates.
plot a square with side length 2 centered at the coordinates (1, 1)
define a new matrix, called NewSquare, as follows:
NewSquare = 2*UnitSquare + [1; 1];
% SquarePlot.m
% plots a filled square
clear variables; close all; clc
UnitSquare = 0.5*[-1 1 1 -1 -1;
-1 -1 1 1 -1];
NewSquare = 2*UnitSquare + [1; 1];
fill(NewSquare(1,:),NewSquare(2,:),'b','LineWidth',2)
xlabel('x (m)'); xlim([-2 2])
ylabel('y (m)'); ylim([-2 2])
grid on
axis equal
1.1- A Primitive Animation