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

Due on 02/12 at the beginning of lab. Write a function MYLU to perform the LU fa

ID: 2261418 • Letter: D

Question

Due on 02/12 at the beginning of lab. Write a function MYLU to perform the LU factorization for an arbitrary nx n matrix (under the assumption that elimination can be performed without row exchanges) Run the function on the input 8 8 -60 5 22 -2-4 1 7046 4 2 755 Test to see if this factorization is correct HW GUIDELINES . You should turn in both your completed code (the m-file), and the command window containing successful execution of the code (using the tests given in the problem). Your grade will be based on correctness, completeness, organization, and neatness » Remember to suppress output and only show output where appropriate. » Remember that m-files should be commented so that a reader would know what the program/function does » Feel free to use the hint uploaded in our shared folder.

Explanation / Answer

Matlab code

function [L, U, s] = myLU4(A)

%A must be square

%get size of input matrix

sizeofA=size(A);

n=sizeofA(1);

%instantiate L, S, U

L=eye(n);

S=eye(n);

U=A;

% process

for i=1:n

    %Row Reduction

    if U(i,i) == 0

        maxofU = max(abs(U(i:end,1)));

        for j=1:n

            if maxofU == abs(U(j,i))

                temp = U(1,:);

                U(1,:) = U(j,:);

                U(j,:) = temp;

             

                temp = S(:,1);

                S(1,i) = P(j,:);

                S(j,:) = temp;

            end

        end

    end

    if U(i,i) ~=1

        temp = eye(n);

        temp(i,i)=U(i,i);

        L=L*temp;

        U(i,:) = U(i,:)/U(i,i); %Ensure pivots are 1

    end

    if i~=n

     

        for k=i+1:length(U)

            temp = eye(n);

            temp(k,i) = U(k,i);

            L=L*temp;

            U(k,:)=U(k,:)-U(k,i)*U(i,:);

        end

    end

end

S= P';

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