## Question

## Transcribed Text

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

Problem 1.We apply the QR algorithm to determine the eigenvalues of the matrix A via the algorithm explained in the problem. This produces a sequence of matrices, and we check if the diagonal elements converge by comparing each with the diagonal elements of the previous matrix.

If the absolute value of the difference in diagonal elements is small enough (given by a user prescribed tolerance) we say that the algorithm has converged.

Sample runs:

D=diagonal(1,2,3,4,5)

A=S D S^{-1}, with S a random matrix as produced by rand

Tol= 1.e-7

75 iterations till convergence

D=diagonal(1,2,3,4,5,6,7,8,9,10)

A=S D S^{-1}, with S a random matrix as produced by rand

Tol= 1.e-7

140 iterations till convergence.

Matlab code:

function [ev,iter]=qr_diagonalize(A,tol)

%INPUT:

% A: n by n matrix

% tol: tolerance for convergence

%OUTPUT:

% eigenvalues - of equation A obtain by QR

n=size(A,1);

if size(A,2) ~= n

error('A must be square')

end

if nargin < 2

tol=eps;

end

done=0;

iter=0;

while ~done

iter=iter+1;

[Q,R]=qr(A);...