2013 Lab MatlabSimulink
2013 Lab MatlabSimulink
2013 Lab MatlabSimulink
19
Introduction to Simulink
Laboratory Guide - MCHA2000
Objectives
The objective of this Lab is to introduce Simulink, which is an graphical environment for numerical
simulation of ODEs based on block diagrams. As an exercise, we will build a simulator for a massspring-damper system.
Contents
1 Introduction
1 Introduction
Simulink is a Matlab toolbox for simulation of dynamic systems. This toolbox provides a graphical
interface for representing models using block diagrams.
In this Lab, we introduce the basic features of Matlab-Simulink. For further reference, students should
R
, available onrefer to help documentation Simulink - Getting Started with SIMULINK, Mathworks
line at http://www.mathworks.com.au/help/simulink/getting-started-with-simulink.html.
To open the Simulink library browser, click on the button
available in top part of the Matlab
toolbar. This action will open the window shown in Figure 1. To open a window where we can build
a model, select File > New > Model.
Simulink Libraries
Simulink contains a wide range of elementary components or blocks to build models. These components
are grouped into libraries according to their characteristics. In this Lab, we will focus on the components of the Continuous, Math Operations, Sinks and Sources libraries (see Figure 1). The help documentation of the Simulink blocks is available in Help > Product Help > Simulink > Block Reference.
(1)
Follow the procedures below to build the Simulink model shown in Figure 2.
1. Open a new model window (File > New > Model) and save it as mymodel.mdl.
2. Add the necessary blocks from the libraries to the mymodel window. This can be done by dragging
the blocks from the library browser and dropping them into the model window. Alternatively,
right-click on the block in the library and select Add to. We will need the following blocks:
Integrator, Gain, Sum, Step, Scope and To Workspace.
3. Interconnect the blocks in the model by drawing lines between the outputs and inputs. This can
be done as follows, (i) position the mouse pointer over an output, the pointer will change to a
cross shape, (ii) drag a line from the output to an input.
Exercise.
1. Replace the parameters of the previous model with the following variables:
Step block. Step time = stept, Initial value = stepi, Final value = stepf.
Integrator block. Initial condition = x0.
2. Create a script in a M-file with the following content:
tau=0.5;
x0=0;
stept=1;
stepi=0;
stepf=10;
sim(mymodel)
plot(mytime,x)
3. Save the script as mymodel_sim.m and run it.
F(t)
b
k
m
x(t)
(3)