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
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 outputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started