Professional Documents
Culture Documents
Mat Labs I Mu Link Intro
Mat Labs I Mu Link Intro
1/14
EE-M110 EFIS,
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,
3/14
Introduction to Matlab
Click on the Matlab
icon/start menu
initialises the Matlab
environment:
Variable
browser
Command
window
EE-M110 EFIS,
4/14
5/14
% This is a comment,
y = 5*3 + 2^2;
x = [1 2 4 5 6];
x1 = x.^2;
E = sum(abs(x).^2);
P = E/length(x);
x2 = x(1:3);
z = 1+i;
a = real(z);
b = imag(z);
plot(x);
t = 0:0.1:100;
x3=exp(-t).*cos(t);
plot(t, x3, x);
EE-M110 EFIS,
it starts with a %
% simple arithmetic
% create the vector x
% square each element in x
% Calculate signal energy
% Calculate av signal power
% Select first 3 elements in x
% Create a complex number
% Pick off real part
% Pick off imaginary part
% Plot the vector as a signal
% Generate sampled time
% Generate a discrete signal
% Plot points
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)
vs, vc
EE-M110 EFIS,
7/14
EE-M110 EFIS,
8/14
EE-M110 EFIS,
9/14
10/14
EE-M110 EFIS,
11/14
Strings
Dynamic function and expression evaluation
Cell arrays
Data structures
Data plotting (2D/3D), figures
GUIDE
Simulink
EE-M110 EFIS,
12/14
Day 1: Laboratory
Remember
Turn on the diary on to save the commands and results from the lab session to a
file for future reference
Questions
1. Use the help and lookfor commands and look at the normal Matlab help
section in the pull down menu (F1). How does the sin() function work?
2. Evaluate expressions such as 7*8/9, 8^2, 6+5-3
3. Using the in-built Matlab functions, evaluate sin(0), sin(pi/2), abs(-3)
4. Using the editor, write a Matlab script to solve the quadratic equation
2x2 -10x + 12 = 0
5. Evaluate, using a for loop, the first twenty numbers of the Fibonacci series
xn = xn-1 + xn-2,
x0 = 1, x1 = 1
6. Create the two vectors [1 2 3], [4 5 6] and calculate their inner product
7. Create the 3*3 matrix A = [1 2 3; 4 5 6; 7 8 9] and the column vector b
= [1 2 3], and multiply the two together A*b.
8. Solve the equation A*x = b, where A and b are given in (6)
9. Modify (8), so that you neglect the 3rd row & column of information.
10. http://www.facstaff.bucknell.edu/maneval/help211/exercises.html
EE-M110 EFIS,
13/14
Day 2: Laboratory
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Write a function that returns the two roots of a quadratic equation, given the three arguments a, b and
c. Test the function from the command line
Write a function that returns the mean and standard deviation of a vector of numbers (input vector).
While Matlab supplies the mean() and std() functions, try just using the sum() and length()
functions.
Write a function that reverses the order of letters in a string, and returns the new string.
Use the eval() Matlab function to evaluate strings such as:
exp1 = 5*6 + 7;
Note this, and feval(), is very useful for dynamic programming
Use a cell array to store a list of expressions, stored as strings. Then use eval() and a for loop to
iterate over the expressions and evaluate them.
Create two simple data structures to modify your solution to (1). Use one data structure to pack the
parameters of the quadratic equation into a single variable, and use another to return the roots inside
a single data structure
Create the vector 0:pi/20:2*pi and use it to sample the sin() function. Plot the results and edit
the figure window to put labels on the figure. Save the figure (.fig) and export a .jpg file.
Use the meshgrid() function to sample a 2 dimensional input space between 0 and 2, then use
the data to sample the function sin(x1)*cos(x2). Plot the results using the mesh() function.
Create a GUI that prompts the user for a number and then displays double that number next to the
entered value.
Start Simulink and using a sin() source and a scope sink, view the signal over 10 seconds.
Change the frequency of the sin() source and again compare the results. Next change the
simulation length.
Build the first order system H(s) = 1/(1+3s) in the model and pass a sin() signal through the
system. Make sure you run the simulation for a long enough time for the transients to die down and
the system to settle.
Replace the first order system in (6) with the second order system, what is the difference when the
system settles down H(s) = 1/(1+2s+s^2).
EE-M110 EFIS,
14/14