You are on page 1of 10

Introduction to

Matlab and Simulink

Dr Martin Brown
E1k, Control Systems Centre
School of Electrical and Electronic Engineering
University of Manchester
Tel: 0161 306 4672
martin.brown@manchester.ac.uk
EEE Intranet

EE-M110 EFIS, W1 06-07 1/14


Background and Aims
Matlab and Simulink have become a defacto standard for system
modelling, simulation and control
It is assumed that you know how to use these tools and develop
Matlab and Simulink programs on this MSc.
Over the next two weeks, we’re going to have a rapid introduction
to Matlab and Simulink covering:
• Introduction to Matlab and help!
• Matrix programming using Matlab
• Structured programming using Matlab
• System (and signal) simulation using Simulink
• Modelling and control toolboxes in Matlab
Note that we’re not covering everything to do with Matlab and
Simulink in these 4*2 hour lectures
Also, after every lecture block in this module, there is a 1 hour lab
scheduled – programming is a practical activity
EE-M110 EFIS, W1 06-07 2/14
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
• Matlab and Simulink Student Version Release 14
• lots more on mathworks, amazon, …. It is important to have one reference book.
EE-M110 EFIS, W1 06-07 3/14
Introduction to Matlab
Variable Command
Click on the Matlab
browser window
icon/start menu
initialises the Matlab
environment:
The main window is the
dynamic command
interpreter which
allows the user to
issue Matlab
commands
The variable browser
shows which variables
currently exist in the
workspace
Command history
EE-M110 EFIS, W1 06-07 4/14
Matlab Programming Environment
Matlab (Matrix Laboratory) is a
dynamic, interpreted,
environment for matrix/vector
analysis
Variables are created at run-time,
matrices are dynamically re-sized,

User can build programs (in .m files
or at command line) using a
C/Java-like syntax
Ideal environment for model building,
system identification and control
(both discrete and continuous time
Wide variety of libraries (toolboxes)
available
EE-M110 EFIS, W1 06-07 5/14
Basic Matlab Operations
>> % This is a comment, it starts with a “%”
>> y = 5*3 + 2^2; % simple arithmetic
>> x = [1 2 4 5 6]; % create the vector “x”
>> x1 = x.^2; % square each element in x
>> E = sum(abs(x).^2); % Calculate signal energy
>> P = E/length(x); % Calculate av signal power
>> x2 = x(1:3); % Select first 3 elements in x
>> z = 1+i; % Create a complex number
>> a = real(z); % Pick off real part
>> b = imag(z); % Pick off imaginary part
>> plot(x); % Plot the vector as a signal
>> t = 0:0.1:100; % Generate sampled time
>> x3=exp(-t).*cos(t); % Generate a discrete signal
>> plot(t, x3, ‘x’); % Plot points

EE-M110 EFIS, W1 06-07 6/14


Introduction to Simulink
Simulink is a graphical, “drag and drop” environment for building
simple and complex signal and system dynamic simulations.
It allows users to concentrate on the structure of the problem,
rather than having to worry (too much) about a programming
language.
The parameters of each signal and system block is configured by
the user (right click on block)
Signals and systems are simulated over a particular time.

vs, vc

t
EE-M110 EFIS, W1 06-07 7/14
Starting and Running Simulink
Type the following at the Matlab
command prompt
>> simulink
The Simulink library should appear

Click File-New to create a new


workspace, and drag and drop
objects from the library onto the
workspace.

Selecting Simulation-Start from the


pull down menu will run the dynamic
simulation. Click on the blocks to
view the data or alter the run-time
parameters

EE-M110 EFIS, W1 06-07 8/14


Signals and Systems in Simulink
Two main sets of libraries for building simple
simulations in Simulink:
• Signals: Sources and Sinks
• Systems: Continuous and Discrete

EE-M110 EFIS, W1 06-07 9/14


Basic Simulink Example
Copy “sine wave” source and
“scope” sink onto a new Simulink
work space and connect.
Set sine wave parameters modify
to 2 rad/sec
Run the simulation:
Simulation - Start
Open the scope and leave open
while you change parameters
(sin or simulation parameters)
and re-run
Many other Simulink demos …

EE-M110 EFIS, W1 06-07 10/14

You might also like