Iteration and Matrix-Vector Multiplication

Everything we shall need is revealed upon clicking Getting Started at Mathworks.

To iterate is to apply the same rule over and over again. Though simple to say and easy to code this can produce some amazing patterns, e.g., eye balls, palm trees and galaxies.

To get started consider the rabbit rule `multiply by 6'. If we start with a population of 10 and iterate we achieve 10, 60, 360, 2160, 12960, ... No, I am not amazed by this pattern. If we instead apply the cannibal rule `multiply by 1/2' we arrive at 10, 5, 2.5, 1.25, 0.625, ... again, nothing new here.

To get more interesting patterns we move into higher dimensions. More precisely, instead of transforming one number into another via scalar multiplication we wish to transform a pair of numbers, say x(1) and x(2), into a second pair, say y(1) and y(2), via matrix multiplication. More precisely, we write

   y(1) = A(1,1)*x(1) + A(1,2)*x(2)
   y(2) = A(2,1)*x(1) + A(2,2)*x(2)

or more compactly

   y = A*x

where x and y are 2-by-1 vectors and A is the 2-by-2 matrix

     A(1,1)  A(1,2) 
A = 
     A(2,1)  A(2,2)

For example, the matrix

     0  1
A =      
    -1  0

rotates every vector clockwise by 90 degrees. Do you see it? Try it by hand for a few vectors and then coax Matlab to do it by trying variations on the following sequence of commands:

>> A = [0 1; -1 0];
>> x = [1; 1];
>> y = A*x;
>> plot([0 x(1)],[0 x(2)]);
>> hold on
>> plot([0 y(1)],[0 y(2)],'r');
>> y = A*y;
>> plot([0 y(1)],[0 y(2)],'r--');
>> y = A*y;
>> plot([0 y(1)],[0 y(2)],'r-.');
>> axis equal

I agree that repeated application of A will just take us in circles. You yearn for something different.

Visualization in Matlab

Although Matlab has a friendly interactive face its power lies in its ability to chew on user generated programs. Yes, a program is just a list of legal Matlab commands like our little example above. We will be building and changing programs of greater and greater complexity and so it is much wiser to create and save such programs than to reenter them interactively at the Matlab command line.

One creates and saves programs through the use of a text editor. There are many editors at your disposal, for instance Notepad and Word on Windows machines and vi and emacs on Unix machines. Matlab also has a built-in editor that most students prefer. You may invoke it by typing edit from the Matlab prompt. No matter how you create any Matlab program you should save it with a `.m' extension, e.g., caam210.m is OK. For this example, typing caam210 at the matlab prompt (assuming that Matlab's current directory contains a program caam210.m) will execute the program caam210.m.

Here is a program, Circle Deform I, that plots the unit circle and its deformation under a particular matrix transformation. This program waits till the end to show what it has done. To watch it work on the fly check out Circle Deform II and Circle Deform III. These programs demonstrate the use of a for loop. They also sport an informative header. They also enjoy proper indenting and are sprinkled with many comments. They each produce a plot with an informative title.

All of these elements, as well as the if clause are in evidence in our Circle Deform IV. You will use a for loop and an if clause in your first assignment.

I recommend that you save the Circle Deforms to your directory, run them, change the A matrix, run them, change A, run them ..., until your excitement ebbs. These runs are static incarnations of Matlab's dynamic eigshow demo. I encourage you to run the demo, hit the help button, and ponder the significance of eigenvalues and eigenvectors.

An eigenvector of a matrix A is a vector that gets stretched by A but not rotated, and the eigenvalue is the amount of stretch. The geometry is clear, but is there any value in pursuing these notions? Eigen is German for self. Ask Google to Google itself by searching for eigenvalue and google. Or better yet, check out the $25,000,000,000 Eigenvector