You are on page 1of 35

Announcements

Class mailing list: send email to


Hyoungjune Yi: aster@cs.umd.edu
Homework at the end of class.
Text is on reserve in the CS library.
Powerpoint should be available by
10am class day.

Matlab tutorial and Linear


Algebra Review

Todays goals:
Learn enough matlab to get started.
Review some basics of Linear Algebra
Essential for geometry of points and lines.
But also, all math is linear algebra.
(ok slight exaggeration).
Many slides today adapted from Octavia
Camps, Penn State.

Starting Matlab
For PCs, Matlab should be a program.
For Suns:
Numerical

Analysis and Visualization

Matlab 6.1

Help
help
help command
Eg., help plus
Help on toolbar
demo
Tutorial:
http://amath.colorado.edu/scico/tutorials/
matlab/

Matlab interpreter
Many common functions: see help ops

Vectors
v ( x1 , x2 , , xn )

Ordered set of
numbers: (1,2,3,4)
v
Example: (x,y,z)
coordinates of pt in
If
space.

i 1

v 1, v is a unit vector

Indexing into vectors

Vector Addition
v w ( x1 , x2 ) ( y1 , y2 ) ( x1 y1 , x2 y2 )

V+w
w

Scalar Product
av a ( x1 , x2 ) (ax1 , ax2 )
av
v

Operations on vectors
sum
max, min, mean, sort,
Pointwise: .^

Inner (dot) Product


v

v.w ( x1 , x2 ).( y1 , y2 ) x1 y1 x2 . y2

The inner product is a SCALAR!

v.w ( x1 , x2 ).( y1 , y2 ) || v || || w || cos


v.w 0 v w

Matrices
Anm

a11
a
21
a31


an1

a12

a1m

Sum:

a22 a2 m
a32 a3m

an 2 anm

Cnm Anm Bnm


cij aij bij

A and B must have the same


dimensions

Matrices
Product:

Cn p Anm Bm p
m

cij aik bkj


k 1

Identity Matrix:

A and B must have


compatible dimensions

Ann Bnn Bnn Ann

0 0 1

IA AI A

Matrices
Transpose:

Cmn A

nm

cij a ji
If

A A
T

( A B) A B
T

( AB)T B T AT
A is symmetric

Matrices
Determinant:

A must be square

a11
det
a21

a12
a11

a22
a21

a11
det a21
a31

a12
a22
a32

a12
a11a22 a21a12
a22

a13
a22

a23 a11
a32
a33

a23
a21
a12
a33
a31

a23
a21
a13
a33
a31

a22
a32

Matrices
Inverse:

Ann A
a11
a
21

A must be square
1

n n

a12

a22

A
1

nn

Ann I

a11a22 a21a12

a22
a
21

a12
a11

Indexing into matrices

Euclidean transformations

2D Translation
P
t
P

2D Translation Equation
ty

P ( x, y )
t (t x , t y )

y
x

tx

P ' ( x t x , y t y ) Pt

2D Translation using Matrices


ty

y
x

tx

P ( x, y )
t (t x , t y )
t

x tx 1 0 tx
P'

y ty 0 1 ty

x
y

1

Scaling
P

Scaling Equation
P

s.y
P

P ( x, y )
P ' ( sx, sy )

P' s P

y
x

s.x

sx s 0 x
P'

sy 0 s y
P' S P

Rotation
P
P

Rotation Equations
Counter-clockwise rotation by an angle

y
X

x' cos
y ' sin

P' R.P

sin x
cos y

Degrees of Freedom
x' cos
y ' sin

sin x

cos y

R is 2x2

4 elements

BUT! There is only 1 degree of freedom:


The 4 elements must satisfy the following constraints:

R RT RT R I
det(R ) 1

Stretching Equation
P ( x, y )
P ' ( s x x, s y y )

Sy.y

sx x sx
P'

s
y
0
y

P
y
x

0
s y
S

Sx.x

P' S P

x

y

Stretching = tilting and projecting


(with weak perspective)
sx x sx
P'

s
y
0
y

0
s y

x

y

sx
sy sy

0 x

y
1

Linear Transformation
a b
P'

c
d

x

y

sin

cos

cos
sin

sin
sy
cos

SVD

sx
0

cos
sin

sx
s
y
0

sy

sin
cos

0 sin

cos
1

cos
sin

x

y

cos x
sin y

Affine Transformation

a b tx
P'

c d ty

x
y

1

Files

Functions
Format: function o = test(x,y)
Name function and file the same.
Only first function in file is visible
outside the file.

Images

Debugging
Add print statements to function by
leaving off ;
keyboard
debug and breakpoint

Conclusions
Quick tour of matlab, you should teach
yourself the rest. Well give hints in
problem sets.
Linear algebra allows geometric
manipulation of points.
Learn to love SVD.

You might also like