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

Modify Matlab Code for QR Algorithm to Include Iterations (Please DO NOT copy an

ID: 3348620 • Letter: M

Question

Modify Matlab Code for QR Algorithm to Include Iterations

(Please DO NOT copy and paste other Chegg Solutions as they were not addressing the actual question and are incorrect)

Need help completing the code below to be able to iterate the algorithm, which will converge to all of the eigenvalues that become clear in the diagonal after so many iterations (do not use any built in functions)

Thank you.

function [Q R]=QR_GramSchmidt(A) % QR decomposition by Gram-Schmidt method

A=[3,1,0;1,4,2;0,2,1]; %Testing

n=3; %Testing

[n n]=size(A);

    Q=zeros(n);

    R=zeros(n);

    R(1,1)=norm(A(:,1));

    Q(:,1)=A(:,1)/R(1,1);

    for j=2:n

        Q(:,j)=A(:,j);

        for i=1:j-1

            Q(:,j)=Q(:,j)-A(:,j)'*Q(:,i)*Q(:,i);

            R(i,j)=A(:,j)'*Q(:,i);

        end

        R(j,j)=norm(Q(:,j));

        Q(:,j)=Q(:,j)/norm(Q(:,j));

    end   

end

Explanation / Answer

For a given A we can find Q and R

But as you want to modify your A everytime we get Q.

As many times as you want.

For this we have to put one more for loop in the code of QR decomposition.

So I am modifying your code as below it will keep printing modified A as many times as you want.

A=input('Enter the Square matrix A ');

s=input( 'Enter the number of iterations you want '); %please_enter_a_positive_integer

for k=1:s

[n n]=size(A);

    Q=zeros(n);

    R=zeros(n);

    R(1,1)=norm(A(:,1));

    Q(:,1)=A(:,1)/R(1,1);

    for j=2:n

        Q(:,j)=A(:,j);

        for i=1:j-1

            Q(:,j)=Q(:,j)-A(:,j)'*Q(:,i)*Q(:,i);

            R(i,j)=A(:,j)'*Q(:,i);

        end

        R(j,j)=norm(Q(:,j));

        Q(:,j)=Q(:,j)/norm(Q(:,j));

    end   

end

A=Q'*A*Q

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote