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

this is my matlab code please help me figure out what to write for the comments

ID: 1811333 • Letter: T

Question

this is my matlab code please help me figure out what to write for the comments for each step and what do the steps mean.


FUNCTION FILE:

function[L,U,X]=LU_Parker(A,B)

[m n]=size(A);

    % Part 2 : Decomposition of matrix into L and U

L=zeros(m,m);

U=zeros(m,m);

for i=1:m

% Finding L

for k=1:i-1

L(i,k)=A(i,k);

for j=1:k-1

L(i,k)= L(i,k)-L(i,j)*U(j,k);

end

L(i,k) = L(i,k)/U(k,k);

end

% Finding U

for k=i:m

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

for j=1:i-1

U(i,k)= U(i,k)-L(i,j)*U(j,k);

end

end

end

for i=1:m

L(i,i)=1;

end

% Program shows U and L

U

L

% Now use a vector y to solve 'Ly=b'

y=zeros(m,1);

y(1)=B(1)/L(1,1);

for i=2:m

y(i)=-L(i,1)*y(1);

for k=2:i-1

y(i)=y(i)-L(i,k)*y(k);

y(i)=(B(i)+y(i))/L(i,i);

end;

end;% Now we use this y to solve Ux = y

x=zeros(m,1);

x(1)=y(1)/U(1,1);

for i=2:m

x(i)=-U(i,1)*x(1);

for k=i:m

      x(i)=x(i)-U(i,k)*x(k);      x(i)=(y(i)+x(i))/U(i,i);end;

   end

COMMAND FILE:

>> A=[ 130 -30 0; 90 -90 0; -40 0 60];

>> A=[ 130 -30 0; 90 -90 0; -40 0 60]

A =

   130   -30     0

    90   -90     0

   -40     0    60

>> B= [ 200 0 500]'

B =

   200

     0

   500

>> LU_Parker(A,B)

U =

130.0000 -30.0000         0

         0 -69.2308         0

         0         0   60.0000

L =

    1.0000         0         0

    0.6923    1.0000         0

   -0.3077    0.1333    1.0000

ans =

    1.0000         0         0

    0.6923    1.0000         0

   -0.3077    0.1333    1.0000

Explanation / Answer

function[L,U,X]=LU_Parker(A,B) %LU_parker (A,B) .... inputs are A,B

[m n]=size(A); %an array of size equal to A

    % Part 2 : Decomposition of matrix into L and U

L=zeros(m,m); % initialising L,U by zeroes

U=zeros(m,m);

for i=1:m % i from 1 to m with step size =1

% Finding L

for k=1:i-1   

L(i,k)=A(i,k); % equating two two dimensional arrys

for j=1:k-1

L(i,k)= L(i,k)-L(i,j)*U(j,k); %given condition

end

L(i,k) = L(i,k)/U(k,k);

end

% Finding U % same as finding L

for k=i:m

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

for j=1:i-1

U(i,k)= U(i,k)-L(i,j)*U(j,k);

end

end

end

for i=1:m

L(i,i)=1;

end

% Program shows U and L

U

L

% Now use a vector y to solve 'Ly=b'

y=zeros(m,1); %one dimensional

y(1)=B(1)/L(1,1);

for i=2:m

y(i)=-L(i,1)*y(1);

for k=2:i-1

y(i)=y(i)-L(i,k)*y(k);

y(i)=(B(i)+y(i))/L(i,i);

end;

end;% Now we use this y to solve Ux = y

x=zeros(m,1);

x(1)=y(1)/U(1,1);

for i=2:m

x(i)=-U(i,1)*x(1);

for k=i:m

      x(i)=x(i)-U(i,k)*x(k);      x(i)=(y(i)+x(i))/U(i,i);end;

   end