Rayleigh Quotient Iteration - Octave Implementation

Octave Implementation

The following is a simple implementation of the algorithm in Octave.

function x = rayleigh(A,epsilon,mu,x) x = x / norm(x); y = (A-mu*eye(rows(A))) \ x; lambda = y'*x; mu = mu + 1 / lambda error = norm(y-lambda*x) / norm(y) while error > epsilon x = y / norm(y); y = (A-mu*eye(rows(A))) \ x; lambda = y'*x; mu = mu + 1 / lambda error = norm(y-lambda*x) / norm(y) end end

Read more about this topic:  Rayleigh Quotient Iteration