Homework 8 Task 9: Rayleigh Quotient vs. Inverse Iteration Computational Time

April 27, 2019 ยท View on GitHub

Task: Compare the Inverse Iteration Algorithm and the Rayleigh Quotient Algorithm in terms of the amount of time needed to compute an eigenvalue. Tabulate your results for the two methods.

This process can be executed in Fortran with the following code

INTEGER :: n, maxiter, i, j
REAL*8, ALLOCATABLE :: A(:, :), v0(:), v(:)
REAL*8 :: tol, lam, t1, t0, alpha

n = 16

tol = 10.D-16
maxiter = 10000
alpha = 3.D0
ALLOCATE(A(n, n), v0(n), v(n))
CALL spd_mat_gen(A, n)
v0 = 1.D0
WRITE(*,*) "Inverse Iteration"
CALL CPU_TIME(t0)
CALL inverse_iteration(A, n, v0, alpha, tol, maxiter, 1, v, lam)
CALL CPU_TIME(t1)
WRITE(*,*) lam
WRITE(*,*) t1 - t0
WRITE(*,*) "Rayleigh Quotient"
v0 = 1.D0
CALL CPU_TIME(t0)
CALL rayleigh_quotient(A, n, v0, tol, maxiter, 1, v, lam)
CALL CPU_TIME(t1)
WRITE(*,*) lam
WRITE(*,*) t1 - t0

The computational times, number of iterations, and final convergence errors for the Rayleigh Quotient method are shown in the table below for random matrices.

Matrix SizeComputational Time (s)# of Iterations
42.4999999999999849E-0058
86.1999999999999989E-0057
161.3499999999999992E-0046
326.0799999999999960E-0045

And for the Inverse Iteration method...

Matrix SizeComputational Time (s)# of Iterations
41.3200000000000017E-00427
81.5700000000000002E-00435
161.8699999999999988E-00432
325.8299999999999975E-00426

It should be noted that these are for a fixed guess for alpha, so there is some variation depending on how close the guess is to a given eigenvalue. In general, though, the trend follows that the Rayleigh Quotient and the Inverse Iteration take roughly the same amount of time (at times an order of magnitude different, though!), but the Rayleigh Quotient converges in FAR FEWER iterations.