The Function `ifdiag'

The function `ifdiag' applies rules 4, 5, and 6 of Section 2 to a diagonal matrix in hat format. Thus, to step through the long example in Section 2, enter A = diag([-1 -2 0 -3]), G = newhat(A), and G = ifdiag(G). The last of these commands will carry out the first step of the computation, which amounts to the operation G = rcop(G,1,1,4,3) determined by rule 4. Since the matrix is no longer diagonal, the next few steps are accomplished by G = algo(G) until the next diagonal matrix is reached. Using the up arrow key, enter another G = ifdiag(G) to accomplish the next step, then repeat G = algo(G) until another diagonal matrix is reached, and so forth. (If you want to see just the evolution of the 4x4 matrix as it is shown in Section 4, replace G = ifdiag(G) with G = ifdiag(G); unhat(G) and G = algo(G) with G = algo(G); unhat(G).)

If, by mistake, you apply `ifdiag' to a matrix that is not diagonal, nothing will be done, and a message will be displayed stating that the matrix must be diagonal. If you apply `ifdiag' to a strongly diagonal matrix, nothing will be done and a message will be displayed stating that the matrix is strongly diagonal.

When ifdiag is used to supplement the function `algo' of Chapter 2---that is, to implement all rules 1-3, 1'-3', and 4-6 of Section 2---the resulting algorithm suffices to find a strongly diagonal matrix equivalent to any given matrix. The procedure is to enter the given matrix A, then enter G = newhat(A), and repeatedly enter G = algo(G) (using the up arrow key, of course). Whenever algo produces a diagonal matrix, use G = ifdiag(G). Eventually, the result of `ifdiag' will be a message stating that the matrix is now strongly diagonal. The command [D,M,N] = unhat(G) then produces unimodular matrices M and N such that MAN is the unique strongly diagonal matrix D equivalent to A.

To convince yourself that this algorithm must eventually terminate (that is, must reach a strongly diagonal matrix) you might try to find relatively small matrices with relatively small entries for which many steps are executed before the algorithm terminates.