Professional Documents
Culture Documents
MECHANICAL SYSTEMS
(MEEN-561)
INTRODUCTION
TO
MATLAB- SIMULINK
By
Kiran Kumar. K
Lecturer in Mechanical Engineering Department
Eritrea Institute Of Technology
Email:- kiranmek3@gmail.com
kiranmedesign@gmail.com
STATIC ANALYSIS
KINEMATIC ANALYSIS
DYNAMIC ANALYSIS
VIBRATION ANALYSIS MODULE
CONTROL SYSTEM ANALYSIS
MECHANISMS SIMULATION MODULE
HYDRAULIC SYSTEM SIMULATION MODULE
ASSESSMENT SCHEME
(75% FOR CONTINUOUS ASSESSMENTS)
Prentice-Hall, 1999.
Sigmon and Davis, MATLAB Primer, 6th Edition, CRC Press, 2001
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/
http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf
http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/using_ml.pdf
http://www.mathworks.com/access/helpdesk/help/toolbox/control/control.shtml
http://www.mathworks.com/academia/student_version/
http://www.mathworks.com/academia/student_version/companion.html
http://travis.eng.man.ac.uk/barry/control2/lab/SIMULINK.htm
http://matlab.kimhua.co.kr/digest/dec98/nonlinear.html
http://www.engin.umich.edu/group/ctm/working/mac/simulink_basics/
http://www.messiah.edu/acdept/depthome/engineer/Resources/tutorial/matlab/simu.html
http://rclsgi.eng.ohio-state.edu/courses/me780/handouts/simulink.pdf
http://www.mae.ncsu.edu/homepages/buckner/simulink2.pdf
http://www.tutorgig.com/showurls.jsp?group=896&index=0
http://www.rpi.edu/dept/chem-eng/WWW/faculty/bequette/lou/simtut/simtut_html.html
http://www.math.siu.edu/matlab/tutorials.html
http://www.engin.umich.edu/group/ctm
OPEN
WEB
RESOURCES
Mathworks Information
Mathworks: http://www.mathworks.com
Mathworks Central: http://www.mathworks.com/matlabcentral
http://www.mathworks.com/applications/controldesign/
http://www.mathworks.com/academia/student_center/tutorials/launchpad.html
Matlab Demonstrations
Matlab Overview: A demonstration of the Capabilities of Matlab
http://www.mathworks.com/cmspro/online/4843/req.html?13616
Numerical Computing with Matlab
http://www.mathworks.com/cmspro/online/7589/req.html?16880
Select Help-Demos in Matlab
Matlab Help
Select Help in Matlab. Extensive help about Matlab, Simulink and toolboxes
Matlab Homework Helper
http://www.mathworks.com/academia/student_center/homework/
Newsgroup: comp.soft-sys.matlab
Matlab/Simulink student version (program and book ~50)
http://www.mathworks.com/academia/student_center
Other Matlab and Simulink Books
Mastering Matlab 6, Hanselman & Littlefield, Prentice Hall
Mastering Simulink 4, Dabney & Harman, Prentice Hall
10/14
EE-M110
W1Simulink
06-07
MatlabEFIS,
and
Student Version Release
14
What is Matlab?
MATLAB (Matrix Laboratory) is basically a high level language
which has many specialized toolboxes for making things easier for
us.
MATLAB is a software for doing numerical computation. It was
originally designed for solving linear algebra type problems using
matrices. Its name is derived from Matrix Laboratory.
MATLAB has since been expanded and now has built-in functions
for solving problems requiring data analysis, signal processing,
optimization, and several other types of scientific computations.
It also contains excellent GUI features of functions for 2-D and 3-D
graphics and animation.
Powerful,
extensible,
highly
integrated
computation,
programming, visualization, and simulation package.
Widely used in engineering, mathematics, and science.
Why?
Need to Perform
Vibration analysis
Human Vibration
BASICS
Displacement
distance
35 Metres
Speed
65 m/s
D
Time
Velocity
V
Time
0-60 m/s
in 8.6
second
Acceleration
A
Time
d = D sinnt
Displacement
D
Time
Frequency
1
T
Period, Tn in [sec]
k
Frequency, fn=
n= 2 fn =
1
Tn
k
m
in [Hz = 1/sec]
Continued
Natural frequency of a simple single degree of freedom
undamped system is given by the equation
N = square root of (stiffness / mass)
Mg
Fs
Fc
Yo
Ys
Yin
d 2 yo
M 2 Mg Fc Fs
dt
Components of a car
For comfortable ride in a car requires analysis of car frame and
many other components, e.g. exhaust systems (bellows),
shock absorber, tire etc.
ms
ks
cs
mu
xu
kt
Mg
y
Suspension system
ys
yin
24
CONTINUED
CONTINUED
CONTINUED
sprung mass
(body) Ms
suspension spring
unsprung mass
(wheel, axle) Mu
tyre stiffness Kt
suspension damper
zu
zr
CONTINUED
CONTINUED
CONTINUED
Active suspension
Matlab WINDOW
Variables
No need for types. i.e., no need of declaring
variables
int a;
double b;
float c;
Accuracy and comfort is very high with MATLAB
codes.
>>x=5;
>>x1=2;
Array, Matrix
Matrix Index
Operators (arithmetic)
MatriX Operations
x = [1,2,3] , vector-row,
y=[1;2;3], vector-column,
x=0:0.1:0.8 , vector x=[0,0.1,0.2,0.3....0.8],
A = [1,3,5;5,6,7;8,9,10], matrix,
A(1,2), element of matrix, 1. row, 2. column,
A(:,2), second column of matrix,
A(1,:), first row of matrix ,
C=[A;[10,20,30]] matrix with additional row,
B=A(2:3,1:2), part of matrix,
x, transpose.
44
Type-2
Programming
Program:clc;
clear all;
p=input('enter the value of p:');
t=input('enter the value of t:');
r=input('enter the value of r:');
I=(p*t*r)/100
Solution:Input:
enter the value of p:10000
enter the value of t:2
enter the value of r:11
Output:
I = 2200
PERFORMING Differentation
Performing Integration
Numerical Integration
quad:
It integrates the specified function over specified limits, based on adaptive
Simpson's rule.
The general call syntax for both quad and quadl is as follows:
Syntax:integral = quad(function, a, b)
dblquad: (It calculates double integration)
MATLAB provides a function dblquad. The calling syntax for dblquad is:
Syntax:I = dblquad(function_xy, xmin, xmax, ymin, ymax)
x = 1:2:50;
y = x.^2;
plot(x,y,'*-')
xlabel('Values of x')
ylabel('y')
plot(x,y,line specifiers)
Line
Style
Specifier
Solid
dotted
:
dashed
dash-dot
--.
Line
Color
red
green
blue
Cyan
magenta
yellow
black
Specifier
r
g
b
c
m
y
k
Marker Specifier
Type
plus sign
circle
asterisk
point
square
diamond
+
o
*
.
s
d
Example
>> a = 1:0.1:30;
>> plot3( sin(a), cos(a), log(a) )
Contd..
sin(x)
Program:0.6
clear all; % clear all variables
0.4
clc;
% clear screen
0.2
N=30;
0
h=pi/N;
-0.2
x=0:h:(2*pi);
-0.4
y=sin(x);
-0.6
plot(x,y)
-0.8
xlabel('x')
-1
0
1
ylabel('sin(x')
title('Graph of sine function in 0 to (2*pi) range')
6
y=f(x)
Program:clc;
clear all;
x=-1:1:2;
y=-3*x+4;
figure
plot(x,y)
xlabel('x')
ylabel('y=f(x)')
grid on
title('plot of function f_1(x)');
legend('f_1(x)');
axis([-2 4 -2 12])
-2
-2
-1
1
x
0.8
Program:-
0.6
functions
clc;
0.4
clear all;
0.2
N=15;
0
h=pi/N;
-0.2
x=0:h:2*pi;
-0.4
plot(x,sin(x),'r-',x,cos(x),'g--')
-0.6
legend('sine','cosine');
-0.8
grid
-1
xlabel('x');
0
1
ylabel('functions');
title('Test of multi-plot option in Matlab');
4
x
Cosine functions
Program:2
x = 0:pi/100:2*pi;
1
y1 = 2*cos(x);
0
y2 = cos(x);
-1
y3 = 0.5*cos(x);
plot(x,y1,'--',x,y2,'-',x,y3,':'); -2
xlabel('0 \leq x \leq 2\pi');
-3
0
1
ylabel('Cosine functions');
legend('2*cos(x)','cos(x)','0.5*cos(x)');
title('Typical example of multiple plots');
axis([0 2*pi -3 3]);
2*cos(x)
cos(x)
0.5*cos(x)
3
0 x 2
Sin(t)
Program:1
clc;
0.9
<--sin(/3)
clear all;
0.8
x=0:.1:2*pi;
0.7
y=sin(x);
0.6
plot(x,y);
0.5
grid on;
0.4
hold on;
0.3
plot(x, exp(-x), 'r:*');
0.2
axis([0 2*pi 0 1]);
0.1
title('2-D Plot');
0
xlabel('Time');
0
1
2
ylabel('Sin(t) ');
text(pi/3, sin(pi/3), '<--sin(\pi/3) ');
legend('Sine Wave','Decaying Exponential');
3
Time
Multiple Plots
t=0:pi/100:2*pi;
y1=sin(t);
y2=sin(t+pi/2);
subplot(2,2,1)
plot(t,y1)
grid on
subplot(2,2,2)
plot(t,y2);
grid on
0.5
0.5
-0.5
-0.5
-1
-1
subplot(i,j,k)
i is the number of rows of subplots in the plot
j is the number of columns of subplots in the plot
k is the position of the plot
7.5
10
6.5
5.5
Program:
clc;
Clear all;
x=[1 2 3 5 7 7.5 8 10];
y=[2 6.5 7 7 5.5 4 6 8];
plot(x, y)
1988
1989
1990
1991
1992
1993
1994
Sales (M)
127
130
136
145
158
178
211
Program:
clc;
Clear all;
year = [1988:1:1994];
sales = [127, 130, 136, 145, 158, 178, 211];
plot(year, sales,'--r*')
30
Program:clc;
clear all;
z = 0:0.1:10*pi;
x = exp(-z/20).*cos(z);
y = exp(-z/20).*sin(z);
plot3(x,y,z,'LineWidth',2)
grid on
xlabel('x')
ylabel('y')
zlabel('z')
20
10
0
1
0.5
1
0.5
-0.5
y
-0.5
-1
-1
clc;
clear all;
t=0:pi/50:10*pi;
plot3(sin(t),cos(t),t);
40
30
20
10
0
1
0.5
1
0.5
-0.5
-0.5
-1 -1
2.5
4
2
2
1.5
y
0
1
-2
Program:-
nearest
0.8
0.6
0.4
0.2
sin(x)
clc;
clear all;
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,'nearest');
plot(x,y,'o',xi,yi)
xlabel('x');
ylabel('sin(x)');
title('nearest interpolation ');
legend('nearest')
0
-0.2
-0.4
-0.6
-0.8
-1
5
x
10
Program:-
nearest
0.8
0.6
0.4
0.2
sin(x)
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,'linear');
plot(x,y,'x',xi,yi)
xlabel('x');
ylabel('sin(x)');
title('linear interpolation ');
legend('linear')
0
-0.2
-0.4
-0.6
-0.8
-1
5
x
10
Program:x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,'spline');
plot(x,y,'o',xi,yi);
xlabel('x');
ylabel('sin(x)');
title('spline interpolation ');
legend('spline');
0
-0.2
-0.4
-0.6
-0.8
-1
5
x
10
Program:x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,'cubic');
plot(x,y,'o',xi,yi);
xlabel('x');
ylabel('sin(x)');
title('cubic interpolation ');
legend('cubic');
0
-0.2
-0.4
-0.6
-0.8
-1
5
x
10
Output:
average =
Program:
clc;
clear all;
close all;
x = 1:1:10;
term = 1./sqrt(x);
y = sum(term);
Solution:
y=
Control Structures
Control Structures
Control Structures
Continued
Program:clc;
clear all;
a=input('enter value of a:');
b=input('enter value of b:');
c=input('enter value of c:);
discr = b*b - 4*a*c;
if discr < 0
disp('Warning: discriminant is negative, roots are imaginary');
else
disp('Roots are real, but may be repeated')
end
Solution:Input:
enter value of a:1
enter value of b:3
enter value of c:2
Output:
Roots are real, but may be repeated
Example
Program :n = input(Enter the upper limit: );
if n < 1
disp (Your answer is meaningless!)
end
x = 1:n;
term = sqrt(x);
y = sum(term)
Example
Program:clc;
clear all;
A=input(enter the value of A: );
B=input(enter the value of B:);
if A > B
'A is bigger'
elseif A < B
'B is bigger'
elseif A == B
'A equals B'
else
error('Something odd is happening')
end
Solution:Input:
enter the value of A: 4
enter the value of B: 3.9
Out put:
A is bigger
-1
-1
1
-0.5
0.5
0
-1
-1
1
-1
-1
1
-0.5
0.5
-0.5
0.5
-0.5
0.5
0
-0.5
0.5
0
-1
-1
-1
-1
1
0
-0.5
0.5
-1
-1
Add grid.
Contd
There are two methods to format a plot:
1.
Formatting commands.
In this method commands, that make changes or additions to the
plot, are entered after the plot() command. This can be done in
the Command Window, or as part of a program in a script file.
2.
FORMATTING COMMANDS
title(string)
Adds the string as a title at the top of the plot.
xlabel(string)
Adds the string as a label to the x-axis.
ylabel(string)
Adds the string as a label to the y-axis.
FORMATTING COMMANDS
legend(string1,string2,string3)
Creates a legend using the strings to label various curves (when
several curves are in one plot). The location of the legend is
specified by the mouse.
text(x,y,string)
Places the string (text) on the plot at coordinate x,y relative to the
plot axes.
gtext(string)
Places the string (text) on the plot. When the command executes
the figure window pops and the text location is clicked with the
mouse.
Example Program
Light Intensity as a Function of Distance
1200
INTENSITY (lux)
clc;
Theory
Experiment
clear all;
1000
x=[10:0.1:22];
y=95000./x.^2;
800
Comparison between theory and experiment.
xd=[10:2:22];
600
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
400
hold on
plot(xd,yd,'ro--','linewidth',1.0,'markersize',10)
200
hold off
0
xlabel('DISTANCE (cm)')
8
10
12
14
16
18
20
22
DISTANCE (cm)
ylabel('INTENSITY (lux)')
title('\fontname{Arial}Light Intensity as a Function of Distance','FontSize',14)
axis([8 24 0 1200])
text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2)
legend('Theory','Experiment',0)
24
Consider a particle moving in a straight line, and assume that its position is defined by the
equation, where x is expressed in meters and t in seconds. Write a program in MATLAB to
determine the displacement, velocity and acceleration variation with respect to time interval
from 0 to 120 seconds.
Program:clc;
clear all;
syms t;
t=0:0.1:120;
x=6.*t.^2-t.^3;
v=12.*t-3.*t.^2;
a=12-6.*t;
plot(t,x);
xlabel(time in seconds);
ylabel(displacement in m);
title(displacement of a particle along its motion);
%plot(t,v);
%xlabel(time in seconds);
%ylabel(velocity in m/s);
%title(velocity of a particle in motion);
%plot(t,a);
%xlabel(time in seconds);
%ylabel(acceleration in m/s2);
%title(acceleration of a particle);
A particle moves along a straight line with variable acceleration. If the displacement is
measured in m, and given by the relation interms of time taken t, as below, determine the
displacement, velocity and acceleration of the particle
S=t3 +2t2+7t+3
Program:clc;
clear all;
syms t;
t=0:0.1:120;
x=t.^3+2*t.^2+7.*t+3;
v=3.*t.^2+4.*t+7;
a=6.*t+4;
plot(t,x);
xlabel(time in seconds);
ylabel(displacement in m);
title(particle behavior along its motion);
%plot(t,x,'.'t,v,'o',t,a,'+');
%xlabel(time in seconds);
%ylabel(displacement, velocity and acceleration of a particle);
%title(kinematics behavior of a particle along its motion);
Spring/Mass/Damper system
example
105
INTRODUCTION
PROBLEM
PROBLEM
Result
single degree of freedom spring mass damper system behaviour
6
displacement
5
displacement in mm
4
3
2
1
0
-1
-2
-3
10
time in seconds
15
SIMULINK
Simulink is an interactive tool for dynamics system modeling and
analysis.
Simulink is a Matlab add-on that allows one to simulate a variety of
engineering systems.
Used for modeling, simulating, and analyzing the behavior of dynamic
systems.
Basically it is a tool for model-based design.
Simulink is a graphical extension to MATLAB for modeling and simulation
of various engineering systems.
In Simulink, systems are drawn on screen as block diagrams.
Simulink offers a variety of components that are assembled to provide a
full system simulation.
Many elements of block diagrams are available, such as transfer
functions, summing junctions, etc., as well as virtual input and output
devices such as function generators and oscilloscopes.
Simulink is integrated with MATLAB and data can be easily transferred
between the programs.
Simulink
Simulink can be used to solve any initial value ODE.
Modelling/designing dynamic systems including
nonlinear dynamics.
Modelling/designing control systems including
nonlinear controller plants.
User creates device model by means of standard blocks
and carries out calculations.
There are additional block libraries for different scopes
as SimMechanics mechanical devices modeling,
SimHydraulics Hydraulic systems modeling.
Sources
1.
2.
3.
4.
Sinewaves
Function
Generators
From MATLAB
workspace
From Disk Files
Sinks
Systems
1.
Interconnection
of Linear and
Nonlinear blocks
1.
2.
3.
4.
Displays scopes
FFT scopes
To MATLAB
workspace
To disk files
117
Simulink- libraries
Continuous; integrator, transfer function..
Discrete; discrete transfer function, unite delay,
memory..
Math operations; gain, product, sum, trigonometric
functions..
Sinks; blocks that have only input, scope, to worspace..
Sources; blocks that have only output, generators,
constant,...
User defined functions: S-function, S-function builder,..
118
119
120
An Introduction to Simulink
Configuration Parameters
Simulink is designed to be a front-end tool for
integrating ordinary differential equations
(ODEs).
Connecting blocks
1. Hold down the Control key down.
2. Click on the source icon.
3. Click on the sink icon.
4. Press the left mouse key to make the
connection.
Displaying Output
Can use the scope attached to any signal.
Use the Autoscale function that appears as
binoculars in order to look at the results of the
entire simulations.
Click on the X, the Y or the zoom
functions to look at any specific part of the
simulation.
SIMULINK DESIGN
RESULT
DESIGN PROBLEM
Build a Simulink model that solves the
following differential equation
2nd-order mass-spring-damper system
zero ICs
input f(t) is a step with magnitude 3
parameters: m = 0.25, c = 0.5, k = 1
mx cx kx f (t )
Simulink Design
SIMULINK DESIGN
Simulink design
Continued
Continued
CONVERSIONS IN MATLAB
Transfer function to state space
[A,B,C,D]=tf2ss([num],[den]);
[num,den]=ss2tf(A,B,C,D);
[z,p,k]=tf2zp([num],[den]);
[num,den]=zp2tf(z,p,k);
[z,p,k]=ss2zp(A,B,C,D,iu);
[A,B,C,D]=zp2ss(z,p,k);
EXAMPLE
SIMULINK DESIGN
FIRST STEP
SIMULINK DESIGN
Problem2
Simulink design
UNDERSTANDING CONTROL
PROBLEM
UNDERSTANDING CONTROL
PROBLEM
PROBLEM (OSCILLATOR)
SIMULINK DESIGN
EXAMPLE
MODELLING COMPOUND PENDULUM
SIMULINK DESIGN
CONTINUED
PROCEDURE
CONTINUED
SIMULINK DESIGN
EXAMPLE
CASCADED M-C-K SYSTEM
EXAMPLE
MODEL OF MECHANICAL ACCELEROMETER
dt
dt
dt
dt
Yo
Ys
Yin
Force balance
M
Mg
Fs Fc
Ma Mg Fc Fs
d 2 yo
M 2 Mg Fc Fs
dt
Simulink design
Fs k ( y0 yin ys )
Fc Fs
v g dt
M M
dyo dyin
Fc C
dt
dt
yo vdt
Y o-Y in
Yin
Fs
Ks
du/dt
dY in/dt
Derivative
.5
1
s
Fc
Integrator1
C
0
Mv
Mg
Mg
v =dY o/dt
.5
1/M
v =dY o/dt
1
s
Y0
Integrator2
Scope
SELF PRACTISE-1
SELF PRACTISE-2
INTRODUCTION
TO
SimMechanics
Introduction
SimMechanics provides a multi body Simulation
environment for Mechanical Systems like robots, vehicle
suspension systems, construction equipment and any
mechanism and machinery etc.
We model systems using blocks representing bodies, joints,
constraints, and force elements and then SimMechanics
formulates and solves the equations of motion for the
complete mechanical system.
Models from CAD systems, including mass, inertia, joint,
constraint, and 3D geometry can be imported into
SimMechanics.
An automatically generated 3D animation lets you visualize
the system dynamics.
CONTINUED
CONTINUED.
SIMULINK DESIGN
EXERCISE 2:
MODELING FOUR BAR
MECHANISM
SIMULINK DESIGN
CONTINUED
TEST OF UNDERSTANDING
SIMULINK DESIGN
SOLUTION
Solving by matlab
Equation of motion are derived as
Simulink design
for forward dynamics
Forward dynamics
by
simmechanics
Inverse dynamics
by
sim mechanics
SIMULINK DESIGN
Elevator system
Thank You
Any Questions ?