Question: LUFactorization.m function Q = LUFactorization(A) Q = A; n = size(A,1); for i = 1:n for r = i+1:n if (Q(i,i) == 0) error('Zero pivot

 LUFactorization.m function Q = LUFactorization(A) Q = A; n = size(A,1);

LUFactorization.m

function Q = LUFactorization(A)

Q = A; n = size(A,1);

for i = 1:n for r = i+1:n if (Q(i,i) == 0) error('Zero pivot element'); end Q(r,i) = Q(r,i) / Q(i,i); for c = i+1:n Q(r,c) = Q(r,c) - Q(r,i) * Q(i,c); end end end

Solving a linear system Ax-b by LU decomposition requires three phases: compute the decomposition A-LU, solve Ly-b (forward substitution), and solve Uz (backward substitution) Download the m-file LUFactorization.m from Moodle. This program implements the LU decomposition pseudocode from class, not worrying about pivoting (it checks for a zero pivot element and stops). The program returns the matrices L and U as one matrix Q, using the compressed storage method discussed in class: L is stored in the part of Q below the diagonal (the 1s on the diagonal of L are not stored in Q), and U is stored in the upper triangular part of Q (a) You are asked to complete the implementation and code up forward and backward substitution in Matlab, using only primitive commands (i.e. do not appeal to the built-in linear algebra functionality in MATLAB). You should use the function header given for each below and submit a copy of your code on Moodle and in the assignment package submitted to the assignment boxes (i) Forward Substitution. This function should take as input the matrix Q output by LUFactorization.m. function y - ForwardSubstitution(Q, b) % Usage: y- ForwardSubstitution (Q, b) % Perform forward substitution using the unit % lower triangular portion of the matrix Q (ii) Backward Substitution. This function should take as input the matrix Q output by LUFactorization.m. function x - BackwardSubstitution(Q, y) % Usage : x- BackwardSubstitution(Q, y) % Perform backward substitution using the % upper triangular portion of the matrix Q Solving a linear system Ax-b by LU decomposition requires three phases: compute the decomposition A-LU, solve Ly-b (forward substitution), and solve Uz (backward substitution) Download the m-file LUFactorization.m from Moodle. This program implements the LU decomposition pseudocode from class, not worrying about pivoting (it checks for a zero pivot element and stops). The program returns the matrices L and U as one matrix Q, using the compressed storage method discussed in class: L is stored in the part of Q below the diagonal (the 1s on the diagonal of L are not stored in Q), and U is stored in the upper triangular part of Q (a) You are asked to complete the implementation and code up forward and backward substitution in Matlab, using only primitive commands (i.e. do not appeal to the built-in linear algebra functionality in MATLAB). You should use the function header given for each below and submit a copy of your code on Moodle and in the assignment package submitted to the assignment boxes (i) Forward Substitution. This function should take as input the matrix Q output by LUFactorization.m. function y - ForwardSubstitution(Q, b) % Usage: y- ForwardSubstitution (Q, b) % Perform forward substitution using the unit % lower triangular portion of the matrix Q (ii) Backward Substitution. This function should take as input the matrix Q output by LUFactorization.m. function x - BackwardSubstitution(Q, y) % Usage : x- BackwardSubstitution(Q, y) % Perform backward substitution using the % upper triangular portion of the matrix

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!