Question: function [L,U,P] = LUPP(A) [m,n] = size(A); if m ~= n error('GEPP can only handle square matrices. '); end % initialize permutation vector p p

 function [L,U,P] = LUPP(A) [m,n] = size(A); if m ~= n

function [L,U,P] = LUPP(A)

[m,n] = size(A);

if m ~= n

error('GEPP can only handle square matrices. ');

end

% initialize permutation vector p

p = 1:n;

% LU decomposition with partial pivoting

for k = 1:n-1

% find row index of relative maximum in column k

[~,pidx] = max(abs(A(k:n,k)));

pidx = pidx + k-1;

% interchange rows k and q and record this in p

A([k,pidx],:) = A([pidx,k],:);

p([k,pidx]) = p([pidx,k]);

% compute the corresponding column of L

idx = k+1:n;

A(idx,k) = A(idx,k) / A(k,k);

% update

A(idx,idx) = A(idx,idx) - A(idx,k) * A(k,idx);

end

P = eye(n,n); P = P(p,:);

L = tril(A,-1) + eye(n,n);

U = triu(A);

Q3 (15 pts) (a) Find the LU factorization with partial pivoting of A in [Q2 by hand. Compare your L, U and P with those obtained by MATLAB's [L,U,P] = lu(A) ; (b) Use the uploaded code LUPP.m to compute the three matrices and compare with those computed by MATLAB. (c) Solve the linear system in [Q2| (c) by the uploaded LUPP.m and your forward and back substitutions, and compare with MATLAB's backslash output. Q3 (15 pts) (a) Find the LU factorization with partial pivoting of A in [Q2 by hand. Compare your L, U and P with those obtained by MATLAB's [L,U,P] = lu(A) ; (b) Use the uploaded code LUPP.m to compute the three matrices and compare with those computed by MATLAB. (c) Solve the linear system in [Q2| (c) by the uploaded LUPP.m and your forward and back substitutions, and compare with MATLAB's backslash output

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!