Exercise "matrix diagonalization"
Objective
Implement Jacobi eigenvalue algorithm
Tasks
Implement the Jacobi eigenvalue method for real symmetric matrices using the cyclic sweep algorithm: eliminate off-diagonal elements in a predefined sequence which spans all off-diagonal elements, for example row after row, and repeat the sweeps until converged.
Make some interesting examples proving your implementation works as intended.
(3 points) Jacobi diagonalization eigenvalue-by-eigenvalue
Implement a variant of Jacobi diagonalization algorithm which calculates the given number of lowest/largest eigenvalues:
Eliminate the off-diagonal elements in the first row only (by running the sweeps not over the whole matrix, but only over the first row until the off-diagonal elements of the first row are all zeroed). Argue, that the corresponding diagonal element is the largest (or lowest) eigenvalue. Find out how to change the formulas for the rotation angle to obtain the lowest (largest) eigenvalue.
Eliminate the off-diagonal elements in the second row. Argue, that the eliminated elements in the first row will not be affected and can therefore be omitted from the elimination loop. Argue that the corresponding diagonal element is the second largest (lowest) eigenvalue.
Continue elimination of the subsequent rows (omitting the operations with the already eliminated rows!) until the given number of the lowest (largest) eigenvalues is calculated.
Compare the effectiveness of the two implementations.
Now, instead of eliminating the off-diagonal elements of a row
consecutively one after another, do
do :
find the largest off-diagonal element of the row
eliminate it by Jacobi transformation
until all off-diagonal elements of the row are eliminated.
Find out whether this gives any improvements in i) the number of rotations, ii) the run-time.
my_prog can be determined by the POSIX time
utility.
The command
\time --format "%U" --append --output=time.txt ./my_prog > /dev/null
or, in short
\time -f "%U" -ao time.txt ./my_prog > /dev/null
runs the program (disregarding the standard output) and appends the
number of consumed CPU-seconds to the file time.txt.
Without the --append option (or, in short, -a)
the file time.txt gets overwritten. Backslash here is
needed to run the actual utility rather than built-in bash command (with
similar possibilities, actually).
An example of the usage of time can be found here (see the
makefile).
Implement the following strategy in the Jacobi diagonalization method:
Find out whether this algoritm gives any speed improvement compared to your other algorithms.
Make up an interesting exercise with matrix diagonalisation.