MATLAB Tutorial: A Whirlwind Tour
MATLAB Tutorial: A Whirlwind Tour
a whirlwind tour
Hinke Osinga
h.m.osinga@bris.ac.uk
Engineering Mathematics
Queen’s Building 2.12
is a column vector.
With a ’ you turn a column vector into a row vector
>>w’
ans =
4 5 6
MATLAB Tutorial – p.4/30
Multiplication of matrices
You can multiply the vectors v and w
>>v*w
ans =
32
Recall: 1 × 3 times 3 × 1 gives 1 × 1
Similarly, 3 × 1 times 1 × 3 gives 3 × 3
>>A = w*v
A =
4 8 12
5 10 15
6 12 18
MATLAB Tutorial – p.5/30
Matrix operations
Standard multiplication is really matrix multiplication
>>log(ans)
ans =
1 2 3
>>sqrt(v)
ans =
1.0000 1.4142 1.7321
MATLAB Tutorial – p.8/30
Special constants
The variable pi is a permanent variable with value π
>>pi
ans =
3.1416
>>y = tan(pi/6);
>>ans
ans =
3.1416
MATLAB Tutorial – p.9/30
Dealing with Matrices
To create a matrix, you could do something like:
>>M = [-3 0 1; 2 5 -7; -1 4 8]
The semicolons indicate the end of a row.
All rows have to be the same length.
>>M*ev1
ans =
−2.8094
0.3648
−0.3931
y =
1.0000 0.7500 0.5000 0.2500 0
MATLAB Tutorial – p.16/30
Generating matrices
You can build certain types of matrices automatically.
Try
>>Id = eye(3,3)
>>Y = zeros(3,5)
>>Z = ones(2)
>>plot(x, sin(x))
>>hold on
>>hold off
>>xlabel(’the x-axis’)
>>ylabel(’the y-axis’)
>>load filename.mat
mandelbrot.m
from the
Data Analysis Website
mandelbrot.m
in your favourite editor.
sierpinski.m
from the
>>axis(’equal’)
MATLAB Tutorial – p.30/30