LAB 9: Introduction To MATLAB/Simulink
LAB 9: Introduction To MATLAB/Simulink
LAB 9: Introduction To MATLAB/Simulink
INTRODUCTION:
This lab introduces powerful graphical user interface (GUI), Simulink of MATLAB. This software is used
for solving the modeling equations and obtaining the response of a system to different inputs. 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
system modeling equations and the digital computer, block diagrams drawn from the system’s differential
equations are used.
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
blocks, 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 parameters. Only
a small subset of the functions of MATLAB will be considered during this lab.
SUM:
A dialog box obtained by double-clicking on the SUM block performs the configuration of the SUM block,
allowing any number of inputs and the sign of each. The sum block can be represented in two ways in
Simulink, by a circle or by a rectangle. Both choices are shown
GAIN:
A gain block is shown by a triangular symbol, with the gain expression written inside if it will fit. If not, the
symbol - k - is used. The value used in each gain block is established in a dialog box that appears if the user
double-clicks on its block.
INTEGRATOR:
The block for an integrator as shown below looks unusual. The quantity 1/s comes from the Laplace
transform expression for integration. When double-clicked on the symbol for an integrator, a dialog box
appears allowing the initial condition for that integrator to be specified. It may be implicit, and not shown on
the block, as in Figure (left). Alternatively, a second input to the block can be displayed to supply the initial
condition explicitly, as in Figure (right). Initial conditions may be specific numerical values, literal
variables, or algebraic expressions.
CONSTANTS:
Constants are created by the Constant block, which closely resembles Figure. Double- clicking on the
symbol opens a dialog box to establish the constant’s value. It can be a number or an algebraic expression
using constants whose values are defined in the workspace and are therefore known to MATLAB.
STEP:
A Simulink block is provided for a Step input, a signal that changes (usually from zero) to a specified new,
constant level at a specified time. These levels and time can be specified through the dialog box, obtained by
double-clicking on the Step block.
SIGNAL GENERATOR:
One source of repetitive signals in Simulink is called the Signal Generator. Double-clicking on the Signal
Generator block opens a dialog box, where a sine wave, a square wave, a ramp (saw tooth), or a random
waveform can be chosen. In addition, the amplitude and frequency of the signal may be specified. The
signals produced have a mean value of zero. The repetition frequency can be given in Hertz (Hz), which is
the same as cycles per second, or in radians/second.
SCOPE:
The system response can be examined graphically, as the simulation runs, using the Scope block in the sinks
library. This name is derived from the electronic instrument, oscilloscope, which performs a similar function
with electronic signals. Any of the variables in a Simulink diagram can be connected to the Scope block, and
when the simulation is started, that variable is displayed.
CLOCK:
The clock produces the variable “time” that is associated with the integrators as MATLAB calculates a
numerical (digital) solution to a model of a continuous system. The result is a string of sample values of
each of the output variables. These samples are not necessarily at uniform time increments, so it is necessary
to have the variable “time” that contains the time corresponding to each sample point. Then MATLAB can
make plots versus “time.” The clock output could be given any arbitrary name; we use “t” in most of the
cases.
To Workspace:
The ‘To Workspace’ block is used to return the results of a simulation to the MATLAB workspace, where
they can be analyzed and/or plotted. Any variable in a Simulink diagram can be connected to a To
Workspace block. In our exercises, all of the state variables and the input variables are usually returned to
the workspace.
Example: Check the step response of transfer function for RC-series circuit, where R = 1kΩ, C = 1µF
Vc ( s ) 1
=
V ( s ) RCs+1
First of all, you have to save the constants values in workspace of MATLAB then drag the transfer function
block, step block and scope block and arrange them as shown in figure.
Quick Hands on Practice: Simulate the step response of the given transfer function.
7
G ( s )= 2
s + 2 s+7
SOLVING STATE SPACE MODELS IN SIMULINK:
In lab 5, we did vehicle suspension system example, whose differential equations are
m1 y¨1 +k 2 ( y 1− y 2) + b ( ẏ 1− ẏ 2 ) +k 1 y 1=k 1 u
Use following parameters for simulation m1=25; m2=1; b=10; k1=30; k2=50;
Simulate system for 10sec and compare the out response for following forcing functions of different
frequencies;
u=5*sin(2*pi*t);
TASK:
Differential equation of simple mass-spring-damper system is given
ẏ ( t ) +3 y ( t ) =e−t
TASK:
Solve this expression in MATLAB/Simulink with non-zero initial conditions y(0)=1.
ẏ ( t ) +3 y ( t ) =e−t
HINT: Double click on integrator block and change the initial conditions.
Task:
Solve a third order differential equation. Use the equation given below and solve it on simulink.
Solve this expression in MATLAB/Simulink with non-zero initial conditions y(0)=1 & ẏ(0)=0.5
Simulate the non-linear dynamic model of Simple Pendulum with parameters given below: