SE207 Lab Manual
SE207 Lab Manual
SE 207
MODELLING AND SIMULATION
LAB MANUAL
Term 061
KING FAHD UNIVERSITY OF PETROLEUM & MINERALS
Systems Engineering Department
SE 207 MODELLING AND SIMULATION
Laboratory Objective
Emphasize the practical aspects of the course and enable each student to:
Simulate systems described by ODE, Input-output models and state variable models
using
o Comdyna GP6 analog computers
o MATLAB and SIMULINK
Be familiar with equipment needed such as function generator, multimeters, oscilloscope,
To simulate and observe behavior of first and second order systems.
Table of Contents
Laboratory Objective.......................................................................................................................2
EXPERIMENT #1: Introduction to Analog Computers..................................................................4
Review of Solutions of Linear Ordinary Differential Equations...................................................11
EXPERIMENT # 2: Basic Operations of the Analog Computer..................................................13
EXPERIMENT # 3: Analog Simulation of a First Order System (RC Circuit)............................16
EXPERIMENT # 4: Analog Simulation of a Second Order Mass-Spring Mechanical System....18
Experiment #5: Function Generation Using the Analog Computer..............................................20
Experiment #6:Analog Simulation of a System of Coupled Masses.............................................22
Experiment 7 : Introduction to Digital Computer Simulation (MATLAB & SIMULINK)..........24
Experiment 8 : MATLAB m-files and their use in system simulation..........................................31
Experiment # 9 :Simulation of systems having relative displacements with other moving body 33
Experiment # 10: Simulation of systems represented by state variable model............................36
EXPERIMENT #1: Introduction to Analog Computers
Introduction
The analog computers were the first computer devices invented. They were heavily used during
the Second World War to predict the trajectories of bombs and shells and to solve stiff
differential equations. They are still used today in instrumentation, A/D-D/A converters,
navigation systems and other areas where they offer advantages over the digital computer. An
analog computer is nothing but an electric circuit that is configured to mimic the behavior of a
differential equation. The computer solves the problem by solving a corresponding problem
patched on the computer. Most general purpose analog computers use an active electrical circuit
as the analogous system because it has no moving parts, a high speed of operation, good
accuracy, and a high degree of versatility. Active electrical networks consisting of resistors,
capacitors, and operational amplifiers (OP amps) connected together are capable of simulating
any linear system since the forward voltage transfer characteristics of these networks are
analogous to the basic linear mathematical operations that are applied in the systems model.
Also, by using diode function generators and special circuits which have nonlinear voltage
transfer characteristics, it is possible to simulate nonlinear systems. The mathematical model of
an analog computer programmed to simulate a specific system is identical to the mathematical
model of the system. The voltage transfer characteristics of the electrical networks are analogous
to the desired mathematical operations. The input and output voltages (computer variables) are
equivalent to the corresponding mathematical variables (problem variables) of the problem.
Because of limitations of the computer or its associated input/output equipment, it is usually
necessary to change the scale of the computer variables, thus forcing the values of a computer
variable to differ from the corresponding problem variable values. It is important to understand
that an analog computer solution is simply a voltage waveform whose time dependency is the
same as that of the desired variable.
The normal procedure for simulating a system starts with determining the mathematical model
describing the physical quantities of interest. An analog block diagram is made to relate the
sequence of mathematical operations and to aid in scaling the variables. From the analog block
diagram, the electrical components are connected together (patched). The computer is operated
and the computer variables observed on a recorder or oscilloscope. Since the output is a
computer variable (voltage waveform) it is necessary to convert the output variable back to the
original problem variable.
The GP-6 offers hands-on analog experiments to introduce the concepts of systems,
mathematical modeling and simulation, the application of and programming of linear circuit
device; Instrumentation/ Control circuitry and scaling of measured and control variables. Each
GP-6 can simulate mathematical models of up to four, state variables. The following are some of
the important features of the GP-6
Internal Components
1. Operational Amplifiers
2. Summer Resistor Network
3. Inverter Networks
4. Electronic Switch Networks
5. Integrator Capacitor sets
6. Coefficient potentiometers
7. Multipliers/divider Boards
Patch Panel
The traditional analog computer patch panel is the only means to program linear circuit devices.
The GP-6 color coded panel is large and readily understood. Analog programming symbols
clearly indicate the active devices and associated networks. Internal summing resistors,
integrating capacitors, and active auxiliary circuits reduce patching connections without
sacrificing flexibility. Standard banana jacks and plugs allow easy connection of external
accessories, amplifiers, readout instrumentation, etc.
Interconnections
The GP-6 directly interconnects with all forms of analog, analog/digital and digital/analog
instrumentation. Front panel banana jacks on the standard 3/4 inch spacing encourage patch cord
connections as inputs and outputs.
The system positive/negative volts offers a precision reference available for external transducers,
position potentiometers, etc.
Extras
Many extras aid operator convenience and laboratory usability. Extras include: time scales per
integrator, time base ramp, compute-time readout, slavability.
Let us look more closely at the patch panel of the GP-6 and describe the function of each button
and knob. A typical GP-6 has the following:
Control Switches
IC: Initial condition mode (push button type); is used to set the output of the integrators to the
required initial condition.
Hd: Hold mode (push button type); is used to hold the variables to their current values.
Op: Operate mode (push button type); is used to start the operation of the analog computer
(integrators).
RQ: Repetitive mode (push button type); is used to periodically set the mode into IC and OP.
Coefficient Potentiometers l-8) (Rotary type); used to divide voltages for analog operation.
Y/Pot address (Rotary type); used to set the potentiometer attenuation and to read the
potentiometer voltage in the OP mode.
X address (Rotary type); used to read and plot the Op amp. outputs.
Mode selector (Rotary type); used to read potentiometer voltage, OP amp. output or external
voltage.
Compute time (Rotary type); used to generate ramp signals for the x-axis of the plotter. It
contains the power switch.
Overload Indicator used to indicate over voltage when an amplifier output exceeds 10.5 volts.
It lights to indicate this, and will remain lit until the cause of the over voltage is removed.
MODES OF OPERATION
Manual operation: Press the push buttons IC for initial condition, Hd for holding the solution
and OP to start a solution.
Repetitive operation: (RO): In this mode, the timer of the analog computer produces repetitive
control signal that repetitively sets the integrators to initial condition and then in the operation
mode.
COMPUTING COMPONENTS
Summers Two summers are available on the GP-6 analog computers. Each one consists of an
operational amplifier and five resistors (three l unit resistors and two 0.1 unit resistors). In
addition, any of the four integrators may also be used as summers.
Review of Solutions of Linear Ordinary Differential Equations
Since the analog computer deals mainly with linear or nonlinear differential equations describing
the behaviors of some physical systems, it is very important that the student remembers some
fundamental results in the solution of differential equations that he learned in his freshman.
Therefore, we will devote this small section of this manual to review some of these results.
However, the student is also expected to review these from some good books (reference [1] is a
good source).
dy
a0 a1 y f (t ) ; y (0) y 0 (1)
dt
where y(t) is the output of the system with initial value y0 . f(t) is the input, which is a given
time function, and a1 , a 0 are constant coefficient. The solution to the above system (1) is
comprised of two parts. A complementary solution (CS), and a particular solution (PS). The
complementary solution is the solution of the system when the input function f(t) = 0. It is also
referred to as the zero input solution. Furthermore, it governs the transient response of the
system. To get the complementary solution of the above system, we first obtain the auxiliary
equation of the system which is given by
a
1 0 (2)
a0
in terms of the auxiliary variable. The solution (root) of this ordinary equation gives the system
mode (or time constants), and in this case is given by
a
1 (3)
a0
y (t ) Ce t (4)
where C is an arbitrary constant to be determined from the initial conditions. For the case of the
first order system, C y 0 . Therefore, the solution becomes
y (t ) y 0 e t (5)
Now regarding the particular solution of the system, this depends on the input function f(t). The
particular solution also determines the steady state behavior of the solution. Also, there are
various methods of obtaining it. Some of these methods are : the method of integrating functions;
the method of variation of parameters; the method of undetermined coefficients and the Laplace
transform method (see reference j1 for more details on this). The Laplace transform method is
probably the easiest for the student. It also has the advantage of giving both the complementary
solution (CS) and the particular solution (PS). The sum of these two solutions gives the whole
solution of the system.
d 2 y (t ) dy (t )
a0 2
a1 a 2 y (t ) f (t ) (6)
dt dt
Without any lost of generality, we can divide the above equation throughout by a and write the
system as
d2y dy
2
b1 b2 y g (t ) (7)
dt dt
To find the complementary solution to the above system, we find the auxiliary equation of the
system as in the first order case. This is given by
2 b1 b2 0 (8)
Let the roots of this quadratic equation be OC ,a Then the complementary solution of the above
system is given by
y (t ) C1e 1t C 2 e 2t (9)
where C1 , C2 are constants, to be determined from the initial conditions. The equation (9) is the
general form of the complementary solution. If however, the roots are complex conjugates, then
equation (9) can further be simplified in the following way:
1 j , 2 j (10)
where C 3 , C 4 are another set of arbitrary constants to be determined from the initial conditions.
Finally, the particular solution of the second order equation can also be determined using Laplace
transform method.
Reference
[1] E. W. Kryszig, Advanced Engineering Mathematics, Wiley International Edition, 1992.
EXPERIMENT # 2: Basic Operations of the Analog Computer
OBJECTIVES:
The objective of this experiment is to learn basic analog computer operations, namely, summing
and integration operations.
INTRODUCTION
The operation of summation of two quantities (signals) can be performed using the analog
computer connected as a summer. This is essentially an Op amp. with a resistor in the feedback
path (the feedback resistor) and two resistors connected in the forward path through which the
signals are summed. Similarly, an integration of a signal can be performed with the analog
computer by connecting it as an integrator. In this case, a capacitor is connected in the feedback
path and a resistor in the forward path. Moreover, a number of signals can be integrated at the
same time and the sum of their integrals be taken using a summing integrator.
EQUIPMENT:
BACKGROUND
The operation of summation of any number of input voltages, say, E1, E2, En is given by the
output voltage:
E E E
E 0 R f 1 2 ...... 3 (1)
R1 R2 R3
where Rf is the feedback resistor in the summer configuration and R1,R2, . . . , Rn are the resistors
in the forward path. The minus sign appearing in the expression (1), is due to the inversion of the
signals by the OP amp. in the inverting configuration. Fig. 1. shows how the summer is
connected.
E
E0 dt (2)
0 RC
where E is the input voltage, R is the value of the resistor in the forward path and C is the value
of the capacitor in the feedback path. For n input voltages, E1,E2,..,En connected through n
resistors R1,R2,..,Rn the sum of their integrals is given by the output voltage:
E E E
E 0 1 2 ...... n dt (3)
0
R1C R2 C Rn C
Finally, the operation of the summing integrator and how it is connected are also shown in Fig. 2.
PROCEDURE:
(i) Turn on the power ON switch using the COMPUTE TIME knob.
(ii) Check to see that all Op amps. (six of them) are connected either through a resistor or a
capacitor in the feedback path.
(iii) Now Connect the summing amplifier as shown in Fig: 1(a).
(iv) To set the potentiometers, set the Mode selector to Pot set and select the desired
potentiometer from the Y/pot address. Now connect the potentiometer input to the supply and
adjust its setting using the corresponding potentiometer knob and the display. While you are
doing this, check the rear of the panel to make sure that the meter is connected to the Y/address.
(v) Complete the connections for the summing amplifier as shown in Fig. 2. (Patch panel
operation). Once you are finished with the connections, call the instructor to check it for you and
make sure that it is correct.
(vi) Now monitor the output of the summer on the display panel and record the result. To do this,
set the Y/pot address to GND/X and the X/address to the desired amplifier (1-6). Set the Mode
selector to OPR and press the OP push button. Also check the rear of the GP-6 to see that the X-
address is connected to the meter.
(i) Similarly, connect the integrator as shown in Fig. 1(b) to generate a ramp.
(ii) Increase the compute time to 100 using the compute-time knob. This allows the integrator to
integrate slowly.
(iii) Now monitor the output of the corresponding amplifier on the display panel, and see that it
overloads after a short time. This confirms that the output of the amplifier is the integral of the
input, and reaches the maximum value of 10 volts as the input is being summed.
Report
1. The theoretical results of the summing operation i.e. calculate the actual output of the
summer from the given input voltages. Compare this result with the one obtained in the
experiment.
2. Calculate also the theoretical value of the output of the integrator after the elapse
compute time (100s). Compare this with the value obtained in the experiment when the
amplifier saturates.
3. Finally, draw conclusions from (a) and (b) above. Have the objectives of the experiment
been achieved?
E1(t)=-10 V 0.01
1
E2(t)=+10 V 0.02 1
Eo(t)
0.02 10
E3(t)=+10 V
10
0.01
E4(t)=-10 V
E(t)=+10 V
0.05 1 Eo(t)
OBJECTIVES:
The objective of this experiment is to simulate a first order system, an RC-circuit, and study its
behavior.
INTRODUCTION
An electrical RC-circuit is the simplest example of a first order system. It comprises of a resistor
and capacitor connected in series to a voltage supply as shown below on Figure 1. If the
capacitor is initially uncharged at zero voltage when the circuit is switched on, it starts to charge
due to the current i through the resistor until the voltage across it reaches the supply voltage. As
soon as this happens, the current stops flowing or decays to zero, and the circuit becomes like an
open circuit. However, if the supply voltage is removed, and the circuit Is closed, the capacitor
will discharge the energy it stored again through the resistor. The time it takes the capacitor to
charge depends on the time constant of the system, which is defined as the time taken by the
voltage across the capacitor to rise to approximately 63% of the supply voltage. For a given RC-
circuit, this time constant is RC . Hence its magnitude depends on the values of the circuit
components.
The RC circuit will always behave in this way, no matter what the values of the components.
That is, the voltage across the capacitor will never increase indefinitely. In this respect we will
say that the system is passive and because of this property it is stable.
EQUIPMENT:
BACKGROUND
For the RC-circuit as shown in Fig. 1, the equation governing its behavior is given by
dv c 1 1
vc (t ) E vc (0) v0 (1)
dt RC Rn C
where vc is the voltage across the capacitor, R is the resistance and C is the capacitance. The
constant RC is the time constant of the system and is defined as the time required by the
system output i.e. vc to rise to 63% of its final value (which is E). Hence the above equation (1)
can be expressed in terms of the time constant as:
dv c (t )
v c (t ) E vc (0) v0 (1)
dt
PROCEDURE
(1) First write the system equations in the form suitable for drawing the analog simulation
diagram.
(ii) Now draw the analog block diagrams corresponding to the following values of R, C, and E:
given in Table 1.
Table 1 E=1.0 volts, v c (0) 0
Time R C
10 sec 1 0.2
20 sec 1 0.1
(iii) For the first set of values, connect the analog circuit on the GP-6 using one integrator. (iv)
Set the Y/pot-address to GND/X and mode selector to OPR.
(v) Select the output amplifier from the X-address, press the OP push button and monitor the
output of the output of the system v
(vi) Repeat the above procedure (iv) and plot the output of the system on the X-Y plot. The
procedure of how to operate the X-Y plotter is explained in the attached sheet.
(vii) Now repeat the above procedures (i)-(vi) for the second set of values of R, C.
REPORT
OBJECTIVES:
The objective of this experiment is to simulate a second order mass-spring system and study its
behavior.
INTRODUCTION
The mass spring system is a very good example of a second order physical system. The equations
governing the behavior of the system are easily derived from Newtons law. Indeed all
mechanical systems, right from the simple pendulum to the more complicated aircraft are of
second order form; because of the fact that they obey Newtons laws or Lagranges or Hamiltons
principle. Therefore, studying the behavior of the mass-spring system, will give us great insight
into the behavior of many. mechanical systems without too much complicated mathematical
analysis.
Furthermore, because of the frictional effects on the system, and an additional damping that may
be introduced in the system, the mass-spring system is always a stable system. That is, it
represents an energy dissipative system.
EQUIPMENT:
BACKGROUND
The mass-spring system is shown in Fig.1, the equation governing its behavior is given by
.. . .
M x(t ) B x(t ) Kx(t ) f (t ); x(0) x0 x(0) x00
where f is the input force, x is the displacement, M is the mass of the system, B is friction and K
is the spring constant.
PROCEDURE
(i) First write the system equations in the form suitable for drawing the analog simulation
diagram.
(ii) Now draw the analog block diagrams corresponding to the following values of M, B, and K:
given in Table 1.
(iii) For the first set of values, connect the analog circuit on the GP-6 using two integrator.
(iv) Set the Y/pot-address to GND/X and mode selector to OPR.
(v) Select the output amplifier from the X-address, press the OP push button and monitor the
output of the output of the system x(t).
(vi) Plot the response of the system on the X-Y plotter. Details of how to use the X-Y plotter are
attached.
(vii) Now repeat the above procedures (i)-(vi) for the remaining set of values of M B, K.
Table 1.
.
T (secs) M B K x ( 0) x (0)
10 1 0 2 0 0
10 1 1 2 2 0
10 1 2 2 1 1
10 1 3 2 0 0
REPORT
K f(t)
M
B
OBJECTIVES
The objective of this experiment is to synthesize a number of time functions (signals) using the
analog computer.
INTRODUCTION
The analog computer can be utilized to generate the various functions or waveforms e.g.
sinusoidal signal, saw-tooth, square waveform etc. which are used in various applications. These
signals can be synthesized as outputs of linear differential equations whose solutions are the
required function.
Therefore, the first step in synthesizing such time functions, is to recover the differential
equation governing its behavior. There are many ways to get this differential equation. The
simplest way is to write the solution of the differential equation in terms of the required time
function and to walk back to the differential equation by differentiation. It is also important here
to keep track of the initial condition. Another approach is to represent the input and output of the
differential equation corresponding to the required time function in the s-domain (using Laplace
transforms) and to recover the differential equation by taking inverse Laplace transform. Yet one
can also recover the differential equation from experience.
EQUIPMENT:
BACKGROUND
PROCEDURE
(i) First write the obtain the differential equations whose solutions are the corresponding time
functions.
For example, for the first waveform (a), this can be obtained as follows. Let
Therefore, the required differential equation whose solution is the given time function is
.. .
x (t ) 2 x(t ) 0 x ( 0) x(0) A
(ii) Now draw the analog block diagram to simulate the above system and generate the required
time function.
(iii) Simulate the differential equation and plot its output using the X-Y plotter as explained in
the previous experiments. The result should correspond with the desired time function.
(iv) Repeat the above procedure (i)-(iii) for the time functions (b) and (c). The following Hint
will also help you for the case of the time function (iv).
Hint: Functions (a) and (b) require identical unforced second-order differential equations with
initial conditions. Function (c) requires a first order unforced differential equation, and function
(d) requires a first order differential equation having the forcing function given by (c).
Alternatively, you can generate (d) from a second order linear differential equation with constant
coefficients whose auxiliary equation has equal roots. Please refer to the introductory part of this
manual on linear differential equations.
REPORT
Exercise
(i) For the time function (a), if you increase A, and separately, what happens to the output of
the analog computer?
(ii) Similarly, for the time function (c), if you increase , what happens to the output of the
analog computer?
Experiment #6: Analog Simulation of a System of Coupled
Masses
OBJECTIVES
The objective of this experiment is to study the behavior of a system of coupled mass-spring
systems using the analog computer.
INTRODUCTION
Many engineering systems have more than one input and more than one output. For example, an
aircraft has as its outputs its horizontal speed, its vertical speed and its altitude; a 6 degree of
freedom robot manipulator has as its output three Euler Angles and three spatial coordinates of
its end effector (Px, Py, Pz); while it has as inputs as many as six joint torques. Such systems are
called multiple-input, multiple- output systems (MIMO, or in short multivariable systems).
Furthermore, the system may also be large, in which case, it may present a lot of difficulties in
modeling and simulation. One approach may be to divide the system into smaller subsystems and
study the behavior of each subsystem separately. This approach works very well if the interaction
between the subsystems is small and can always be predicted. The overall behavior of the system
can then be studied by combining the behavior of the subsystems:
Another alternative, is to study the effect of each input on the overall system outputs separately,
and then sum up these effects for all the inputs to get the overall response of the system.
It is therefore the purpose of this experiment, to introduce the student to the modeling and
simulation of MIMO systems.
BACKGROUND
Figure 1. shows the model of the system. It is basically a two mass-spring system coupled side-
by-side together. The equations governing the behavior of the system are given by:
.. . . . .
M 1 x1 B1 x1 B1 ( x1 x 2 ) k1 x1 f1 ; x1 (0) 0 x1 (0) 0
.. . . . .
M 2 x 2 B3 x 2 B2 ( x 2 x1 ) k 2 x 2 f 2 ; x 2 (0) 0 x 2 (0) 0
where all the terms are explained in the previous experiment and in Figure 1. Note that the two
. .
subsystems are coupled together by the terms x1 , x 2 .
EQUIPMENT
(i) Rewrite the dynamical equations governing the behavior of the system in the form suitable for
simulation. For the values of parameters given in Table 1 below, draw the analog simulation
block for the system.
Table 1. B3=1
M1 M2 B1 B2 k1 k2 f1 f2 T(sec)
1 1 1 1 4 4 10 0 10
1 1 1 1 3 4 0 10 10
Now simulate the system for each set of values of the parameters and plot the response of the
system for both x1, x2 , using the X-Y plotter as in the previous experiments.
(ii) Find analytically, x1(t) and x2(t) by assuming f1(t)=0 and f2(t) = 10u(t).
(iii) Find lim x1 for this case, and lim x 2
t t
(iv) Compare the values you got in (iii) with the values you got from the simulation.
Report
Figure 1
Experiment 7 : Introduction to Digital Computer Simulation
(MATLAB & SIMULINK)
INTRODUCTION
This lab introduces a powerful numerical simulation software, MATLAB and its graphical user
interface (GUI), Simulink. This software is used for solving the modeling equations and
obtaining the response of a system to different inputs. The software is run on digital computers.
Both linear and nonlinear differential equations can be solved numerically with high precision
and speed, allowing system responses to be calculated and displayed for many input functions.
To provide an interface between a systems modeling equations and the digital computer, block
diagrams drawn from the systems differential equations are used. A block diagram is an
interconnection of blocks representing basic mathematical operations in such a way that the
overall diagram is equivalent to the systems mathematical model. The lines interconnecting the
blocks represent the variables describing the system behavior. These may be inputs, outputs, state
variables, or other related variables. The blocks represent operations or functions that use one or
more of these variables to calculate other variables. Block diagrams can represent modeling
equations in both input-output and state variable form.
We use MATLAB with its companion package Simulink, which provides a graphical user
interface (GUI) for building system models and executing the simulation. These models are
constructed by drawing block diagrams representing the algebraic and differential equations that
describe the system behavior. The operations that we generally use in block diagrams are
summation, gain, and integration. Other blocks, including nonlinear elements such as
multiplication, square root, exponential, logarithmic, and other functions, are available.
Provisions are also included for supplying input functions, using a signal generator block,
constants etc and for displaying results, using a scope block.
An important feature of a numerical simulation is the ease with which parameters can be varied
and the results observed directly. MATLAB is used in a supporting role to initialize parameter
values and to produce plots of the system response. Also MATLAB is used for multiple runs for
varying system parameter-s. Only a small subset of the functions of MATLAB will be considered
during these labs.
SIMULINK
Simulink provides access to an extensive set of blocks that accomplish a wide range of functions
useful for the simulation and analysis of dynamic systems. The blocks are grouped into libraries,
by general classes of functions.
Mathematical functions such as summers and gains are in the Math library.
Integrators are in the Continuous library.
Constants, common input functions, and clock can all be found in the Sources library.
Scope, To Workspace blocks can be found in the Sinks library.
Simulink is a graphical interface that allows the user to create programs that are actually run in
MATLAB. When these programs run, they create arrays of the variables defined in Simulink that
can be made available to MATLAB for analysis and/or plotting. The variables to be used in
MATLAB must be identified by Simulink using a To Workspace block, which is found in the
Sinks library. (When using this block, open its dialog box and specify that the save format should
be Matrix, rather than the default, which is called Structure.) The Sinks library also contains a
Scope, which allows variables to be displayed as the simulated system responds to an input. This
is most useful when studying responses to repetitive inputs.
Simulink uses blocks to write a program. Blocks are arranged in various libraries according to
their functions. Properties of the blocks and the values can be changed in the associated dialog
boxes. Some of the blocks are given below.
X1
X1
X2 X2
X3
X3
Two additional blocks will be needed if we wish to use MATLAB to plot the responses versus
time. These are the Clock and the To Workspace blocks.
In the Simulink diagram, the appearance of a block can be changed by changing the foreground
or background colours, or by drop shadow or other options available in the format drop down
menu. The available options can be reached in the Simulink window by highlighting the block,
then clicking the right mouse button. The Show Drop Shadow option is on the format drop-down
menu.
Simulink provides scores of other blocks with different functions.
You are encouraged to browse the Simulink libraries and consult the online Help facility
provided with MATLAB.
GENERAL INSTRUCTIONS FOR WRITING A SIMULINK PROGRAM
At the Simulation > Parameters entry, several parameters can be selected in this dialog box, but
the default values of all of them should be adequate for almost all of the exercises. If the
response before time zero is needed, it can be obtained by setting the Start time to a negative
value. It may be necessary in some problems to reduce the maximum integration step size used
by the numerical algorithm. If the plots of the results of a simulation appear choppy or
composed of straight-line segments when they should be smooth, reducing the max step size
permitted can solve this problem.
help
This command followed by the command for which help is needed can be used to get help on
any of the MATLAB commands. E.g. help plot on the command window will display help for
plot command.
plot(t,x)
Plots the time versus variable x. Time axis is the x-axis, while the variable x is plotted on y axis.
Other plot related commands are xlabel, ylabel, title, gtext, text, grid, axis. and subplot.
hold on
Holds the plot for further values to be plotted on the same plot. Useful when multiple runs are
made using varying parameter values and a single plot is required for comparison purposes. hold
off releases the plot.
EXERCISE 1: Modeling of a second order system
Construct a Simulink diagram to calculate the response of the Mass-Spring system shown below.
The input force increases from 0 to 8 N at t = 1 s. The parameter values are M 2 kg, K= 16 N/m,
and B =4 N.s/m.
PROCEDURE:
When the computer makes a short chirp sound, the simulation is complete, and the variables that
have been sent to the workspace are available there for analysis and/or plotting.
To get the plots, enter the command plot (t, x) in the main MATLAB window.
Several functions are available to make plots more informative. Among these are: xlabel, ylabel,
title, gtext, text, grid, axis and subplot.
Use xlabel, ylabel and title to label your graphs
USE help command on the MATLAB command window to get help on any command.
EXERCISE 2: System response from the stored energy with zero input
Find the response of the above system when there is no input for t 0, but when the initial value
of the displacement x(0) is zero and the initial velocity v(0) is 1 m/s.
PROCEDURE:
In the previous program
Set the size of the input step to zero
Set the initial condition on Integrator for velocity to 1.0.
Plot the results.
EXERCISE 3: Simulation with system parameter variation
The effect of changing B is to alter the amount of overshoot or undershoot. These are related to a
term called the damping ratio. Simulate and compare the results of the variations in B in exercise
1. Take values of B = 4, 8, 12, 25 N-s/m.
PROCEDURE:
Perform the following steps. Use the same input force as in Exercise 1.
Begin the simulation with B = 4 N-s/m, but with the input applied at t 0
Plot the result.
Rerun it with B = 8 N.s/m.
Hold the first plot active, by the command hold on
Reissue the plot command plot(t,x), the second plot will superimpose on the first.
Repeat for B = 12 N-s/m and for B = 25 N-s/m
Release the plot by the command hold off
Show your result.
Prepare a Simulink implementation of the system with the same values as in Exercise 1, Use it to
simulate and plot the response to the sinusoidal input
fa (t ) 8 sin( , t )
where 2 (0.05).
This specified input is a sinusoid having an amplitude of 8 N (16 N peakto-peak) and a
frequency of 0.05 Hz. The period is 1/ (0.05) = 20 s.
Plot the response for the interval 0 t 50S.
PROCEDURE:
REPORT:
The values of the parameters of a model can be saved in an M-file and changed by editing
this file if needed.
Commands to execute a model can be included, so that the results of a simulation are
created.
Plot commands and other post simulation data analysis and display commands can be used
to cause the production, printing, or storage of the desired product.
M-files are produced with a text editor; there is one built into MATLAB that is accessible from
the toolbar or through the edit command.
The Simulink model for a mass-spring system, shown below, was developed in the last
experiment. This model is used as a reference in this experiment to develop the understanding in
programming MATLAB m-files.
Modify the program by writing the variables M, K and B in place of the values in the Simulink
model. Save the model as exlmodel.mdl (You can use any other name but then use the same
name in all the following m-files).
Given below is a file that will set up the MATLAB workspace by establishing the values of the
parameters needed for the Simulink simulation of the given model.
M-file for parameter values
% This file is named exl_parameter.m.
% Everything after a % sign on a line is a comment that
% is ignored by M This file establishes the
% parameter values for exl_model.mdl.
%
M2; %kg
K= 16; %N/m
B=4; % Ns/m
A semicolon in a physical line ends the logical line, and anything after it is treated as if it were
on a new physical line. A semicolon at the end of a line that generates output to the command
window suppresses the printing of that output.
Program Execution:
Follow the following steps to execute these files:
Enter the command exlparameter in the command window. This will load the parameter
values of the model.
Open the Simulink model exl_model.mdl and start the simulation by clicking on the toolbar
entry Simulation> Start.
Enter the command exl_ plot in the command window to make the plot.
REPORT:
INTRODUCTION
In a linear translational system such as the two-mass system shown below in the figure, the
displacement variable associated with each mass can be expressed with respect to a fixed
reference position. However, sometimes the position of a mass is measured with respect to some
other moving object rather than a fixed point. This is known as relative displacement.
Let x denote the position of mass M1 with respect to fixed reference point and z denote the
relative displacement of mass M2 with respect to mass M1. The positive direction for both
displacements is towards right. The two springs are neither stretched nor compressed when
x=z=0.
z
K2
M2 Fa(t)
B2
x
K1
M1
B1
B3
PROCEDURE:
EXERCISE 1:
Plot the first 10 seconds of the response when the applied force fa(t) increases from 0 to 100 N at
t= 1sec.. The parameter values are: M1 = M2 = 5 kg, B1 = B2= 20 N.s/m, B3=50
N.s/m, and K1 = K2 = 100 N/m. Plot both x and z on the same axes.
PROCEDURE:
EXERCISE 2:
From exercise 1, change the values of B2 =30 N.s/m and B3 =20 N.s/m and K1 =20 N/m.
Rerun the simulation and compare the responses.
PROCEDURE:
EXERCISE 3:
Repeat Exercise 1 when the displacement of each mass is expressed with respect to its own fixed
reference position. Let x1 and x2 denote the displacements of M1 and M2 respectively with the
positive senses to the right.
PROCEDURE:
INTRODUCTION
In a linear translational system such as the two-mass system shown below in the figure, the state
variables are the displacements and the velocities of the two masses.
Let x1 and v1 denote the position and velocity of mass M1 with respect to fixed reference point
and x2 and v2 denote the position and velocity of mass M2. The positive direction for both
displacements is towards right. The two springs are neither stretched nor compressed when x1 =
x2 =0.
PROCEDURE:
EXERCISE 1:
Plot the first 10 seconds of the response when the applied force fa(t) increases from 0 to 10 N
at t= 1 sec. The parameter values are: M1 = M2 =10 kg, B1 = B2= B3= 20 N.s/m, and K1 =
K2 = K3 =10 N/m. Plot both x1 and x2 on the same axes.
PROCEDURE:
EXERCISE 2:
From exercise 1, change the values of B1 = B2= 30 N.s/m and K1 = 20 N/m. Rerun the simulation
and compare the responses.
PROCEDURE:
REPORT:
Introduction
Many practical system are well approximated by second order models. A general second order
model; is given by
x 2 n x n 2 x n 2 u
where is the damping ratio and n is the natural frequency. The damping ratio determines
whether the system has oscillatory response or not. A system is called under damped if its
response is oscillatory. It is called over damped if has no oscillations. The natural frequency
determines the frequency of the oscillations.
In this experiment we will study the effect of different parameters on the response of the system.
Part 1:
Select a unit step input and let n =0.5. Simulate the system for the following values of the
damping factor {0, .2, .5, 1 , 2 10}. Plot the response and mark the curves.
What are the values of the damping ratio that give under damped response?
What are the values of the damping ratio that give damped response?
Part 2:
Let the input be a unit step and the damping ratio = 0.5. Simulate and plot the response of the
system for the following natural frequencies {0.5, 1 , 2 , 10}.
Part 3:
Simulate the system having = 0, n =0.5 for the following inputs,
u (t ) 0.5 sin(0.5t )
u (t ) 0.5 sin(0.5t 2)
u (t ) 0.5 sin(t )
u (t ) 0.5 sin(6t )
Introduction:
Rolling mills are common in steel industry. Hot slabs are rolled into successively thinner slabs
until sheets are formed. This is accomplished by squeezing the material between pairs of rollers.
Variations in the thickness of the finished product can be attributed to many factors> These
include variations in the material and the hydraulic process that pushes the rollers. A feedback
control system is used to control the thickness of the finished product by controlling the
hydraulic pressure that push the rollers. A simplified sketch of the rolling process with the
control system is shown in figure 1. A block diagram of the system is shown in figure 2. The
process and controller parameters are
Ns b
M 10 3 kg D 0.25 10 5 , 10
m a 1
N m2 N
, G ( s) 2
K 0.25 10 7 K c 0.75 , K m 10 6 Ms Ds K
m s s m3
yr e Kc Km b/a
G y
Transfer functions:
The transfer function of a linear time-invariant system is defined as the ratio of Laplace
transform of the output to the Laplace transform of the input. It is widely used to model of linear
systems. SIMULINK offers a simple way of representing transfer functions.
Procedure:
Case 1: Simulate the system with the given controller assuming no disturbance
plot the response y(t) and the error signal e(t) when yr is a step of size 0.1 m
Case 2: Assume a sinusoidal disturbance of magnitude 0.02 is applied, Simulate the system with
yr being a step of size 0.1 meter and plot the output and the error.
Case 3: Plot the response with uniform random numbers in the range -0.02 and 0.02.
plot y(t)
Objective:
To simulate a simplified model of a car and investigates the effect of changes in the mass and
spring constants as well as the shape of the road depression.
Introduction:
Models of the car suspension systems are important in the design of a car that satisfy the
customers expectation of a nice ride. Practical car models are used to determine the forces on
the deriver and his motion as the car moves on roads surface.
Cars (at least small cars) have four wheels and each one moves independently as the car moves.
Both translational and rotational motion is present. A typical simplified lumped model involves
seven degrees of freedom. Translational motion of the four wheels and rotational motion in three
axes. In this lab experiment we use further simplification and consider the motion of the front
right side of the car and ignore other sides and ignore rotational motion as well.
y2 Mb
Bp
Kp
y1
Mw
Kt
u(t)
M b y 2 (t ) K p ( y1 y 2 ) B p ( y 1 y 2 ) M b g
M w y1 (t ) K p ( y1 y 2 ) K t ( y1 u (t )) B p ( y 1 y 2 ) M w g
where
M b mass of car body ( driver seat ...)
Kt Spring constant of tire
g Gravitational constant
K p Spring constant of the shock absorber
B p Damping coefficient of the shock absorber
M w mass of wheel tire
y2 Vertical Displacement of the driver
y1 Vertical Displacement of the wheel
y Position of the road surface (input)
Typical output of interest are the displacements, velocities and accelerations of the masses.
M b 390 kg
M w 69 kg
Kt 190 000 N / m
g 9.81 m / s 2
Kp 7812 N / m
Bp 1000 Ns / m
InitialCon ditions :
Mb Mw
y1 (0) g
Kt
Mb
y 2 (0) y1 (0) g
Kp
y 1 (0) y 2 (0) 0
Case 4: What happen if the tires spring constant is reduced to 160 000N/m? Repeat Case 2 with
the new spring constant.
Case 5: What happen if the shock absorber damping coefficient is reduced to 90% , and 80% of
its original value? Repeat Case 2 with the new damping coefficient.
What to submit?:
Derivation of the model ( includes freebody diagrams and equations)
Simulation diagrams
plot of the input and outputs in the five cases.
Comments on the results.