The function `algo' determines automatically the row or column operation dictated by the algorithm of Section 7 and performs that operation, assuming the matrix is in `hat format'--- that is, is an (m + n)x(m + n) matrix in which the lower right entry is m and the matrix on which the row or column operation is to be performed is the matrix in the upper left mxn corner.
The normal format for using this function is a command G = algo(G), where G is in hat format. Thus, the first example at the bottom of page 20 can be done by giving the command G = newhat([3 1;9 3]) followed by six commands G = algo(G) (use the `up arrow' key for the last 5). The display will give exactly the 7 matrices shown at the bottom of page 20.
If the input matrix to `algo' is already diagonal, no operation is performed, which is to say that the output is identical to the input.
Try applying `algo' to the last example on page 22. You will not only find the sequence of steps given in the book, you will also find unimodular matrices M and N such that MAN is diagonal. To check this, give the Matlab command that defines A to be the matrix of this example, then enter the command G = newhat(A) followed by 33 commands G = algo(G). When the diagonalization is complete, enter the commands [D,M,N] = unhat(G) and M*A*N - D. The result of this last command will be a 3x4 matrix of zeros, indicating that the matrix product M*A*N is equal to D.
The function `algo' allows you to do several steps at once. For example, G = algo(G,10) executes 10 steps and shows only the end result. Therefore, in the previous example, you can go directly to the end by entering G = algo(G,33), or, for that matter, G = algo(G,1000) (once the upper left mxn corner is diagonal, the steps result in no change).
If you are interested only in the operation of the algorithm on A, not its operation on the augmented matrix A hat, you can replace G = algo(G) with G = algo(G); unhat(G), giving two instructions on one line. The semicolon following the first instruction suppresses printing of the output of that instruction. The second instruction gives no name to the output of unhat(G), so only the first output---the upper left mxn corner---will be printed, with the name `ans'. Of course the first instruction has modified G, so G is ready for the next step.
Return to Chapter 2.