Why doesn't the L in my partial pivot LU decomposition switch rows?
Mostrar comentarios más antiguos
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 comentarios
Torsten
el 19 de Feb. de 2023
Output j and k in the outer loop (for j =1:n-1) and you'll see the reason.
Jessica Arroyo
el 19 de Feb. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!