MATLAB help. Do not use any built in MATLAB functions such as li,mldivide, and d
ID: 3684919 • Letter: M
Question
MATLAB help. Do not use any built in MATLAB functions such as li,mldivide, and divide. Do not copy and paste from other chegg answers. Part 1 (30 pts): Write a MATLAB function of the form L, U, P-get_lu (A) that accepts a square matrix A and returns the LU decomposition of A with the permutation matrix P If A is rectangular or singular, then you must notify the user by throwing a suitable error message using MATLAB function error or assert. Your function must perform row exchanges, if necessary, and the pivots must be chosen to reduce roundoff error using the technique of partial pivoting. Hint: You'll need to set a tolerance to determine when a pivot position value is "zero" and when A is singular.) function of the form [L, U, P] = get-lu (A) that accepts a squareExplanation / Answer
function [L, U, P] = get_lu(A)
len = size(A,1);
arr = A;
L = eye(len);
U = zeros(len);
P = eye(len);
for j = 1:len-1
[~,r] = max(abs(arr(j:end,j)));
r = len-(len-j+1)+r;
arr([j r],:) = arr([r j],:);
P([j r],:) = P([r j],:);
L([j r],:) = L([r j],:);
for i = j+1:len
L(i,j) = arr(i,j) / arr(j,j);
for j = 1:len
U(j,j) = arr(j,j);
arr(i,j) = arr(i,j) - L(i,j)*arr(j,j);
end
end
end
U(:,end) = arr(:,end);
return
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.