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](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66e072b263de8_45766e072b1a4269.jpg)
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
Get step-by-step solutions from verified subject matter experts
