Announcements Class mailing list: send email to Hyoungjune Yi: [email protected] 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. n
2 i 1 i x v 1, v is a unit vector Indexing into vectors Vector Addition v w ( x1 , x2 ) ( y1 , y2 ) ( x1 y1 , x2 y2 ) v
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
w 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 a22 a32 an 2 a1m a2 m a3m
anm Sum: Cnm Anm Bnm cij aij bij A and B must have the same dimensions Matrices Product: Cnp Anm Bmp
m cij aik bkj k 1 Identity Matrix: A and B must have compatible dimensions Ann Bnn Bnn Ann 1 0 0 0 1 0
I 0 0 1 IA AI A Matrices Transpose: T Cmn A
nm cij a ji If T A A T T ( A B) A B ( AB )T B T AT A is symmetric
T 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 nn
a12 a22 A 1 1 nn Ann I 1 a11a22 a21a12
a22 a 21 a12 a11 Indexing into matrices Euclidean transformations 2D Translation P t P
2D Translation Equation ty P P t P ( x, y ) t (t x , t y ) y x tx
P ' ( x t x , y t y ) Pt 2D Translation using Matrices ty P P t y x tx
P ( x, y ) t (t x , t y ) t x x tx 1 0 tx P' y y ty 0 1 ty 1 P
Scaling P 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 S Rotation
P P Rotation Equations Counter-clockwise rotation by an angle Y P y X
P 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 R T R T R I det(R ) 1
Stretching Equation P ( x, y ) P' ( s x x, s y y ) P Sy.y sx x sx P ' s y 0 y P
y x 0 x sy y S Sx.x P ' S P Stretching = tilting and projecting (with weak perspective) sx x sx
P ' s y 0 y 0 x sy y sx s y s y 0
0 x y 1 Linear Transformation a b x P' c d y sin cos
sin s y cos SVD cos s x 0 sin 0 sin cos x
s y cos sin y sx cos 0 sin cos x sy cos sin y sin 0 1 Affine Transformation x a b tx
P' y c d ty 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.