Simulation Lab Manual 3107
Simulation Lab Manual 3107
Simulation Lab Manual 3107
ME-406
SIMULATION LAB
Introduction to MATLAB
The name MATLAB stands for Matrix Laboratory. MATLAB was written originally to provide easy
access to matrix software developed in 1984 and is now considered as a standard tool at most
universities and industries worldwide.
MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming environment. Furthermore, MATLAB is a modern programming
language environment; it has sophisticated data structures, contains built-in editing and
debugging tools, and supports object-oriented programming. These factors make MATLAB an
excellent tool for teaching and research.
MATLAB has many advantages compared to conventional computer languages (e.g.,C,
FORTRAN) for solving technical problems. MATLAB is an interactive system whose basic data
element is an array that does not require dimensioning.
MATLAB integrates mathematical computing, visualization, and a powerful language to provide
a flexible environment for technical computing. The open architecture makes it easy to use
MATLAB and its companion products to explore data, create algorithms and create custom
tools that provide early insights and competitive advantages. Known for its highly optimized
matrix and vector calculations, MATLAB offers an intuitive language for expressing problems
and their solutions both mathematically and visually. Typical uses include:
Numeric computation and algorithm development.
Symbolic computation (with the built-in Symbolic Math functions).
Modeling, simulation and prototyping.
Data analysis and signal processing.
Engineering graphics and scientific visualization.
It has powerful built-in routines that enable a very wide variety of computations. It also has
easy to use graphics commands that make the visualization of results immediately available.
Special applications are collected in packages referred to as toolbox. There are toolboxes for
signal processing, symbolic computation, control theory, simulation, optimization, and several
other fields of applied science and engineering.
1
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
INTRODUCTION TO SIMULINK
Simulink is a graphical extension to MATLAB for modeling and simulation of dynamic systems.
In Simulink, systems are drawn on screen as block diagrams. 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.
Steps for using SIMULINK are as follows
1. Starting Simulink
2. Model Files
3. Basic Elements
4. Running Simulations
2
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
ME 406
SIMULATION LAB
LIST OF EXERCISES
3
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
Equation can be written as the system of two differential equations for z=[z1,z2], with
assumptions as
Then the stage comes to reduce the second order differential equation interms of Ѳ to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as expone.m in the current working directory of MATLAB:
4
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
5
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
MATLAB PROGRAM:-
Create the function file and save it as exptwo.m in the current working directory of MATLAB:
6
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
7
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
3) Write the program for the task given: The motion of the free vibratory spring-mass system is
modeled by the following equation, solve the differential equation and find the displacement,
velocity with respect to time (from 0 to 120 seconds).Analyze the system by MATLAB
Programming and validate the solution by using SIMULINK. Assume m=1 kg, k=2 N/m.
Then the stage comes to reduce the second order differential equation in terms of x to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as expthree.m in the current working directory of MATLAB:
8
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
9
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
4) Write the program for the task given: The motion of the forced vibratory system with spring-
mass system is modeled by the following equation, solve the differential equation and find the
displacement, velocity with respect to time (from 0 to 120 seconds).Analyze the system by
MATLAB Programming and validate the solution by using SIMULINK. Assume m=1 kg, k=2
N/m, F=120N and ω=1 rad/sec.
M*(d2x/dt2)+K*x(t)=F*sin(w*t)
Then the stage comes to reduce the second order differential equation in terms of x to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as expfour.m in the current working directory of MATLAB:
Function of the program:-
function dzdt = expfour(t,z);
m=1;
k=2
w=1;
f=120;
dzdt =[z(2); -(k/m)*z(1)+(f/m)*sin(w*t)];
10
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
11
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
5) Write the program for the task given: The motion of the free vibratory system with spring-mass-
damping system is modeled by the following equation, solve the differential equation and find the
displacement, velocity with respect to time (from 0 to 120 seconds).Analyze the system by MATLAB
Programming and validate the solution by using SIMULINK. Assume m=1 kg, c=0.5 Ns/m, k=2 N/m.
M*(d2x/dt2)+C*(dx/dt)+K*x(t)=0
Then the stage comes to reduce the second order differential equation in terms of x to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as expfive.m in the current working directory of MATLAB:
Function of the program:-
function dzdt = expfive(t,z);
m=1;
k=2
c=0.5;
dzdt =[z(2); -(k/m)*z(1)-(c/m)*z(2)];
12
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
13
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
6) Write the program for the task given: The motion of the forced vibratory system with spring-
mass-damping system is modeled by the following equation, solve the differential equation and
find the displacement, velocity with respect to time (from 0 to 120 seconds).Analyze the system
by MATLAB Programming and validate the solution by using SIMULINK. Assume m=1 kg,
c=0.5 Ns/m, k=2 N/m, ω=1 rad/sec and F=120 N.
M*(d2x/dt2)+C*(dx/dt)+K*x(t)=F*sin(ω*t)
Then the stage comes to reduce the second order differential equation in terms of x to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as expsix.m in the current working directory of MATLAB:
Function of the program:-
function dzdt = expsix(t,z);
m=1;
k=2
c=0.5;
w=1;
f=120;
dzdt =[z(2); -(k/m)*z(1)-(c/m)*z(2)];
Main body of the program:-
clc;
clear all;
m=1;
k=2;
w=1;
f=120;
z0=[0,1];
tspan =[0,120];
[t,z] = ode45('expsix',tspan,z0);
x=z(:,1);
v=z(:,2;
acc=-(k/m)*x+(c/m)*v;
plot(t,x,t,v,t,acc);
xlabel('t');
ylabel('x(t),v(t)and a(t)');
legend('displacement','velocity','acceleration');
title('position, velocity and acceleration variation with respect to time');
14
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
15
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
7) Write the program for the task given: The motion of the forced vibratory system with
nonlinear damping system is modeled by the following equation, solve the differential equation
and find the displacement, velocity with respect to time (from 0 to 120 seconds).Analyze the
system by MATLAB Programming and validate the solution by using SIMULINK. Assume
m=10 kg, CD=2 N/m/s, F(t)=12*sin(5*t)N.
m*(d2x/dt2)+CD*(dx/dt)^2=F(t)
The above equation can be rewritten as:
Then the stage comes to reduce the second order differential equation in terms of x to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as exptest.m in the current working directory of MATLAB:
Function of the program:-
function dzdt = exptest(t,z);
m=10;
CD=0.5;
F=12*sin(5*t);
dzdt =[z(2); (F/m)*sin(5*t)-(CD/m)*z(2)^2];
Main body of the program:-
clc;
clear all;
m=10;
CD=0.5;
F=12*sin(5*t);
z0=[0,1];
tspan =[0,120];
[t,z] = ode45('exptest',tspan,z0);
x=z(:,1);
v=z(:,2;
acc=(F/m)*sin(5*t)-(CD/m)*v^2;
plot(t,x,t,v,t,acc);
xlabel('t');
ylabel('x(t),v(t)and a(t)');
legend('displacement','velocity','acceleration');
title('position, velocity and acceleration variation with respect to time');
16
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
17
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
8) Write the program for the task given: The motion of the compound pendulum is modeled by
the following equation, solve the differential equation and find the displacement, velocity
with respect to time (from 0 to 120 seconds).Assume the value of d=0.023 m, m=0.43 kg,
L=0.495 m, J=0.009 kg-m2, c=0.00035, g=9.81. Analyze the system by MATLAB
Programming and validate the solution by using SIMULINK.
Equation can be written as the system of two differential equations for z=[z1,z2], with
assumptions as
Then the stage comes to reduce the second order differential equation interms of Ѳ to a first
order differential equation in terms of z which is termed as state-variable method.
MATLAB PROGRAM:-
Create the function file and save it as explearn.m in the current working directory of MATLAB:
18
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
L=0.495;
J=0.009;
c=0.00035;
g=9.81;
z0=[0,1];
tspan =[0,120];
[t,z] = ode45('explearn',tspan,z0);
x=z(:,1);
v=z(:,2);
a= -(c/j)*v-(m*g*d/j)*sin(x);
plot(t,x,t,v,t,a);
xlabel(‘time in seconds’);
ylabel(‘x(t),v(t) & a(t)’);
legend ('displacement','velocity',’acceleration’);
title(‘Kinematic analysis of compound pendulum’);
SIMULINK DESIGN:-
19
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
9) Write the program for the task given: The motion of the Two Degree of freedom free
vibratory system with spring-mass-damping system is modeled by the following
equation, solve the differential equation and find the displacement, velocity with respect
to time (from 0 to 120 seconds). Analyze the system by MATLAB Programming and
validate the solution by using SIMULINK. Assume m1=4 kg, m2=6 kg,
k1=2N/m,k2=3N/m, c1=1.5Ns/m, c2=3.0 Ns/m.
MATLAB PROGRAM:-
Create the following function file and save it as twodof.m in the current working
directory of Matlab:
Function of the Program:-
function dxdt=twodof(t,x);
c1=1.5;
c2=3.0;
k1=2;
k2=3;
m1=4;
m2=6;
dxdt=[x(2);-(c1/m1)*(x(2)-x(4))-(k1/m1)*(x(1)-x(3));x(4);-(c1/m1)*(x(4)-x(2))
(c2/m2)*x(4)-(k1/m2)*(x(3)-x(1))-(k2/m2)*x(3)];
20
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
NOTE:-There will be test to check the understanding level posing question on Two degree of
freedom Free and forced vibratory system on spring-mass and spring-mass-damper system.
Students should be able to obtain the solution for exercise by MATLAB Programming and
validate your Solution by Simulink Design.
21
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
NOTE:- This is TEST-1 for Understanding to build Simulink Design for the Experiment 9.
22
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
10) Write the program for the task given: The motion of the Two Degree of freedom
forced vibratory system with spring-mass system by considering friction is modeled by
the following equation, solve the differential equation and find the displacement, velocity
with respect to time (from 0 to 120 seconds). Analyze the system by MATLAB
Programming and validate the solution by using SIMULINK. Assume M1=1kg, M2=2kg,
k=1N/m, F=1; mu=0.002; g=9.81.
MATLAB PROGRAM:-
Create the following function file and save it as twodofwithfriction.m in the current
working directory of Matlab:
Function of the Program:-
function dzdt=twodofwithfriction(t,z,mu,g,f,k,m1,m2);
mu=0.02;
g=9.81;
f=1;
k=1;
m1=1;
m2=2;
dzdt=zeros(4,1);
dzdt(1)=z(2);
dzdt(2)=-(k/m1)*(z(1)-z(3))-mu*g*z(2)-(f/m1)
dzdt(3)=z(4);
dzdt(4)=-(k/m2)*(z(1)-z(3))-mu*g*z(4);
23
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
24
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
SIMULINK DESIGN:-
25
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
26
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
27
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
28
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
29
Mechanical Engineering Department, B.S.Abdur Rahman University, Vandalur, Chennai-600048.
30