Announcements

advertisement

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

• Today’s 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 Sun’s:

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

• Ordered set of numbers: (1,2,3,4)

• Example: ( x,y,z ) v v

 coordinates of pt in space.

If v

( x

1

, x

2

,  , x n

)

 i n

1 x i

2

1 , v is a unit vecto r

Indexing into vectors

Vector Addition v

 w

( x

1

, x

2

)

( y

1

, y

2

)

( x

1

 y

1

, x

2

 y

2

) v

V+w w

Scalar Product a v

 a ( x

1

, x

2

)

( ax

1

, ax

2

) av v

Operations on vectors

• sum

• max, min, mean, sort, …

• Pointwise: .^

Inner (dot) Product v

 w v .

w

( x

1

, x

2

).( y

1

, y

2

)

 x

1 y

1

 x

2

.

y

2

The inner product is a SCALAR!

v .

w

( x

1

, x

2

).( y

1

, y

2

)

|| v ||

|| w || cos

 v .

w

0

 v

 w

A n

 m

 a a a

31 a

11

21 n 1 a

12 a

22 a

32

 a n 2

 a a a

1 m

2

3 m m a nm

Matrices

Sum:

C n

 m

A n

 m

B n

 m c ij

 a ij

 b ij

A and B must have the same dimensions

Matrices

Product:

C n

 c ij p

A n

 m k m 

1

B m

 a ik b kj p

A and B must have compatible dimensions

A n

 n

B n

 n

B n

 n

A n

 n

1

Identity Matrix:

I

0

0

0

1

0

0

0

1

IA

AI

A

Transpose:

C m

 n

 c

 ij

A

T n

 m a ji

Matrices

( A

B )

T 

A

T 

B

T

( AB )

T 

B

T

A

T

If A

T 

A A is symmetric

Matrices

Determinant: A must be square det

 a

11 a

21 a

12 a

22

 a

11 a

21 a

12 a

22

 a

11 a

22

 a

21 a

12 det

 a

11

 a a

21

31 a

12 a

22 a

32 a

13 a

23 a

33

 a

11 a

22 a

32 a

23 a

33

 a

12 a

21 a

31 a

23 a

33

 a

13 a

21 a

31 a

22 a

32

Matrices

Inverse:

A n

 n

A

1 n

 n

 a

11 a

21

A

1 n

 n

A n

 n

I a

12 a

22

1

 a

11 a

22

1

 a

21 a

12

 a a

22

21

A must be square

 a a

12

11

Indexing into matrices

Euclidean transformations

P

2D Translation

P’ t

t y y

2D Translation Equation x

P t

P’

P

( x , y ) t

( t x

, t y

) t x

P '

( x

 t x

, y

 t y

)

P

 t

t y y

2D Translation using Matrices x

P t

P’ t x

P '

 x y

 t x

 t y

P

( x , y ) t

( t x

, t y

)

1

0

0

1 t x t y t



 x y

1

P

P

P’

Scaling

s.y

y x

P

Scaling Equation

P’ s.x

P

( x , y )

P '

( sx , sy )

P '

 s

P

P '

 sx sy



 s

0

P '

S

P

S

0 s



 x y



P’

P

Rotation

Y’ y

Rotation Equations

Counter-clockwise rotation by an angle 

P’

X’ x

P

 x y

'

'

 cos sin

P'

R.P

 sin cos

 

 x y

Degrees of Freedom

 x y

'

'

 cos sin

 sin cos

 

 x y

R is 2x2 4 elements

BUT! There is only 1 degree of freedom: 

The 4 elements must satisfy the following constraints:

R

R

T 

R

T det( R )

1

R

I

S y

.y

y x

P

Stretching Equation

P

( x , y )

P’

P '

( s x x , s y y )

S x

.x

P '

 s s x y x y

 s x

0

S

0 s y



 x y



P '

S

P

Stretching = tilting and projecting

(with weak perspective)

P '

 s s x y x y

 s

0 x

0 s y



 x y



 s y

 s s y

0 x 0

1

 

 x y



Linear Transformation

P '

 a c



 sin

 cos

 b d



 x y

 cos

 sin

 

 s x

0

SVD

0 s y

 



 sin cos

 s y



 sin cos

 cos

 sin

 

 

 

 s x s y

0

0

1 

 



 sin cos

 cos

 sin



 x y

 cos sin



 x y



Affine Transformation

P '

 a c b d tx

 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. We’ll give hints in problem sets.

• Linear algebra allows geometric manipulation of points.

• Learn to love SVD.

Download