Professional Documents
Culture Documents
Matlab Basics
John J. H. Oh
Pohang Univ. Of Science and Technology
What is Matlab?
A software environment for interactive numerical computations
Examples:
Matrix computations and linear algebra
Solving nonlinear equations
Numerical solution of differential equations
Mathematical optimization
Statistics and data analysis
Signal processing
Modelling of dynamical systems
Solving partial differential equations
Simulation of engineering systems
Introduction to Matlab 3
Matlab Background
Alternatives Complements
Matrix-X Maple (symbolic)
Octave (free; GNU) Mathematica (symbolic)
Lyme (free; Palm)
Introduction to Matlab 4
Construction
Core functionality: compiled C-routines
Most functionality is given as m-files, grouped into toolboxes
m-files contain source code, can be copied and altered
m-files are platform independent (PC, Unix/Linux, MAC)
Simulation of dynamical systems is performed in Simulink
Simulink
C-kernel m-files
Introduction to Matlab 5
Matlab Desktop
Launch Pad
Command
Window
History
Introduction to Matlab 6
Workspace
Command
Window
Current
DIrectory
Introduction to Matlab 7
Matlab Help
Introduction to Matlab 9
Color keyed
text with auto
indents
Interactive Calculations
Matlab is interactive, no need to declare variables
>> 2+3*4/2
>> a=5e-3; b=1; a+b
s e f
1 2 12 13 64
Matrix Operators
All common operators are overloaded
>> v + 2
Note:
Matlab is case-sensitive
A and a are two different variables
• Transponate conjugates complex entries; avoided by
>> B=A.’
Introduction to Matlab 16
Indexing Matrices
Indexing using parentheses
>> A(2,3)
Indexing Matrices
Index complete row or column using
the colon operator
>> A(1,:)
Matrix Functions
Many elementary matrices predefined
>> help elmat;
>> I=eye(3)
v α
w v.w = ( x1 , x2 ).( y1 , y2 ) = x1 y1 + x2 . y2
v.w = 0 ⇔ v ⊥ w
Introduction to Matlab 21
Matrices
Sum:
Cn×m = An×m + Bn×m
a11 a12 a1m
a
21 a22 a2 m cij = aij + bij
An×m = a31 a32 a3m
A and B must have the same
dimensions
an1 an 2 anm
Introduction to Matlab 22
Matrices
1 0 0
Identity Matrix:
0 1 0
I = IA = AI = A
0 0 1
Introduction to Matlab 23
Matrices
Transpose:
Cm×n = A T
n× m ( A + B) = A + B
T T T
cij = a ji ( AB)T = B T AT
If A =A
T
A is symmetric
Introduction to Matlab 24
Matrices
Matrices
2D Translation
P’
t
P
Introduction to Matlab 27
2D Translation Equation
P’
t
ty P P = ( x, y )
y t = (t x , t y )
x tx
P ' = ( x + t x , y + t y ) = P+t
Introduction to Matlab 28
P’ P = ( x, y )
t
ty P
t = (t x , t y )
y
t P
x tx x
x + t x 1 0 t x
P' → = ⋅ y
y + t y 0 1 t y 1
Introduction to Matlab 29
Scaling
P’
P
Introduction to Matlab 30
Scaling Equation
P’
s.y
P = ( x, y )
P P ' = ( sx, sy )
y
P' = s ⋅ P
x s.x
sx s 0 x
P' → = ⋅
sy 0 s y
P' = S ⋅ P S
Introduction to Matlab 31
Rotation
P’
Introduction to Matlab 32
Rotation Equations
Graphics
Graphics
Three-dimensional graphics
>> A = zeros(32);
>> A(14:16,14:16) = ones(3);
>> F=abs(fft2(A));
>> mesh(F)
>> rotate3d on
Graphics
Bitmap images can also be visualized
>> load mandrill
>> image(X); colormap(map)
>> axis image off