Why doesn't the L in my partial pivot LU decomposition switch rows?
Show older comments
Everything else works well besides my L, please help.
A= [1 2 3 1; 4 5 6 2; 7 8 0 4; 0 1 3 1];
GE = GE_partial(A);
%%
function[L,U,P] = GE_partial(A)
[n,n] = size(A); %nxn matrix A
L = eye(n,n);
P = eye(n,n);
U = A;
for j =1:n-1 % looping over the columns of U
%Finding the row width with the largest magnitude
[~, r] = max(abs(U(j:n,j)));
% Calling the index of this row k
k = r + j - 1;
% Swap rows of j and k for U and P
U([j,k],:) = U([k,j],:); %Swaping the first and the third row.
P([j, k],:) = P([k, j],:); % swaping the first ad third row
% Swap rows j and k in L for coulmns 1 to j-1
for c = 1:j-1
L([j,k],c) = L([k,j],c)
end
end
end
3 Comments
Torsten
on 19 Feb 2023
Output j and k in the outer loop (for j =1:n-1) and you'll see the reason.
Jessica Arroyo
on 19 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!