Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

function s = eigenvalues(A, Nit, epsilon) % function that computes the eigenvalu

ID: 3678674 • Letter: F

Question

function s = eigenvalues(A, Nit, epsilon) % function that computes the eigenvalues of a matrix A using the QR % iteration algorithm with a maximum of Nit iterations or until a trheshold % epsilon has been achieved. % input : A a squared matrix % Nit maximum number of iterations % epsilon tolerace % In this file you will compute the eigenvalues of A, up to an accuracy % epsilon using the QR iteration. You will find using similarity % transformations a diagonal matrix (that is similar to A), that contains % the eigenvalues of A. %test that the matrix is squares [m,n] = size(A auxiliary matrix you need to compute the QR factorization of A using the built-in mat lab % funtion qr % [Q, R] = qr(D); % you will form the new matrix % stopping criterion % everything not in the diagonal of A has to be really small

Explanation / Answer

clear

A = input(“Enter the matrix:”);

mtx= readmtx(‘A’,4,4,’int8’);

Nit = input(“Enter max no of iterations:”);

epsilon=input(“Enter tolerance:”);

function s= eigenvalues(A,Nit,epsilon);

[m,n] = size(mtx);

if m~=n

error(‘Matrix is not squared’);

end

D = mtx;

s=0;

function[Q,R] = qr(D)

disp(s,Matrix);

end

for int i=1:Nit

qr(D)

n=size(D,1); G = eye(n); R=D;

for int j=1:n

for i=n: (-1) :j+1

x= R(:,j);

if norm([x(i-1),x(i)]) >0

c= x(i-1)/ norm([x(i-1),x(i)]);

s = -x(i)/ norm([x(i-1),x(i)]);

Q=eye(n);

G([i-j],[i-1,i]) = [c,s;-s,c];

R=G’*R;

Q = Q*R;

end

end

end

return [Q,R];

end

eigenvalues(A,Nit,epsilon)

do

X = eig(D,Matrix);

while(epsilon);

end

return X;

end