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

(40 pts) Write a function named ubitname _ get_LU () that takes (as input) any s

ID: 3575001 • Letter: #

Question

(40 pts) Write a function named ubitname _ get_LU () that takes (as input) any size square matrix and returns (as output s ) the matrices L and U from its LU decomposition in the conventional format of Eq. (1) , which is consistent with the method discussed in class . To do this, you must follow the same methodology used for Crout’s method shown on pages 5 -­ 10 by first re -­ deriving the general equations that ar e equivalent to equations (4.34 – 38) of Ref. [1], but using the conventional format for L and U shown in Eq. (1) . You must clearly show your work in your paper copy of the project including the re -­ derivation of the general equations — starting from Eq. ( 1) — that will be used later in your function to obtain the L and U matrices. However , using Crout’s method (and also your method , which is derived from Crout’s method) , the LU decomposition can only b e obtained for square matrices, so if the input matrix is rectangular, your function must throw an error (see Deliverable #4 ). Furthermore , Crout’s method (and yours) unfort unately cannot handle all singular matrices. Therefore, after testing for “rectangularity,” you r function must test if the input matrix is singular using MATLAB’s built -­ in det() function. If the input matrix is singular, you r function must throw an error u sing the built -­ in MATLAB function error() with the message 'Matrix is singular; the LU decomposition cannot be computed by this function.' ( Note : MATLAB’s lu() function is able to handle rectangular and singular matrices.)

Explanation / Answer

Crout method gives a lower triangular matrix and a unit upper triangular matrix.

Matlab Program

function [L,U]=ByCroutLU(A)
%computes the lu factorization of A
%input: A
%output: L a lower triangular matrix
% U an upper triangular matrix
%
[n,m] = size(A);
U(1,:) = A(1,:);
d = zeros(1,n);
L = diag(d+1,0);
for i = 1:n-1
L(i+1:n,i) = A(i+1:n,i)/U(i,i);
for j = i+1:n
A(j,i:n) = A(j,i:n) - L(j,i)*U(i,i:n);
1.3. MATRIX FACTORIZATION 27
end
U(i+1,i+1:n) = A(i+1,i+1:n);
end