cs249 lecture notes, Fall 2001 Week 10, Monday Assignment for next time: draw a sketch of a blueprint for a self-similar figure (as in Figure 5.22) and compute the values of e, f, phi, psi, r and s for each lens system. Dot products ------------ In linear algebra, the dot product of two vectors is a scalar, which is the sum of the products of the corresponding elements of the vectors. The operation is only defined if the vectors have the same length. MATLAB complicates this picture a litte by distinguishing between row vectors and column vectors. The vectors we have seen so far are row vectors: >> a = [1 2] a = 1 2 >> b = [3 4]' b = 3 4 >> a * b ans = 11 The apostrophe ' is the transpose operator. It converts a row vector to a column vector or back. Why doesn't this work? >> a * a ??? Error using ==> * Inner matrix dimensions must agree. Why DOES this work? >> b * a ans = 3 6 4 8 Matrices -------- A matrix is a bunch of numbers in a box. In MATLAB, you can create a matrix the same way you create vectors, with semi-colons between the rows: >> a = [1 2; 3 4] a = 1 2 3 4 Also, the ones command creates a matrix with the given number of rows and columns >> ones(2, 3) ans = 1 1 1 1 1 1 I used matrices to write drawLine and triangle function drawLine (v1, v2) z = [v1;v2]; line (z(:,1), z(:,2)) function triangle (v1, v2, v3, color) z = [v1;v2;v3]; fill (z(:,1), z(:,2), color) Matrix-vector multiplication ---------------------------- Multiplying a matrix by a vector yields a vector: >> a = [1 2; 3 4] a = 1 2 3 4 >> a * [1 1]' ans = 3 7 Again, the dimensions have to agree and the orientation of the vector has to be right. >> a * [1 1] ??? Error using ==> * Inner matrix dimensions must agree. You can keep all this stright by drawing a picture. Matrix operators ---------------- You can think of a matrix as an operator on vectors. Multiplying by a matrix transforms one vector into another. In particular, there are special matrices that have an identifiable effect on vectors. Example, the rotation matrix R(theta) rotates a vector counterclockwise by theta degrees cos (theta) -sin (theta) R(theta) = sin(theta) cos (theta) In MATLAB, we can write function fern () v = [1 1]'; r = rotate (pi/4) r * v function r = rotate (theta) r = [cos(theta) -sin(theta); sin(theta) cos(theta)]; And get: r = 0.7071 -0.7071 0.7071 0.7071 ans = 0.0000 1.4142 Draw a picture and convince yourself that it is doing the right thing. What is the visual effect of multiplying a vector by a scalar? What is the visual effect of adding two vectors? Affine transformation --------------------- Affine transformation is a generalization of rotation than includes the possibility of flipping and scaling. r cos (phi) s -sin (psi) R(theta) = r sin (phi) s cos (psi) r controls the scaling in the x direction s controls the scaling in the y direction if psi = phi, then it rotates angle phi counterclockwise if phi = pi and psi = 0, it reflects around the y axis Write a MATLAB function that computes the matrix for an affine transformation described by parameters r, s, phi and psi. Barnsley's fern --------------- Barnsley described a fern in terms of a set of transformations (see handout) The idea is that if something is self similar, we can describe it entirely just by enumerating the _ways_ in which it is self-similar! Potentially a very dense form of image encoding. Blueprints: diagram showing the initial image and each transformation of it Lens: a transformation defined by translation (e, f), rotation (phi, psi) and scaling (r, s). MRCM: multiple reduction copy machine Next time: draw that fern!