LU decomposition with partial pivoting Matlab
问题 I am trying to implement my own LU decomposition with partial pivoting. My code is below and apparently is working fine, but for some matrices it gives different results when comparing with the built-in [L, U, P] = lu(A) function in matlab Can anyone spot where is it wrong? function [L, U, P] = lu_decomposition_pivot(A) n = size(A,1); Ak = A; L = zeros(n); U = zeros(n); P = eye(n); for k = 1:n-1 for i = k+1:n [~,r] = max(abs(Ak(:,k))); Ak([k r],:) = Ak([r k],:); P([k r],:) = P([r k],:); L(i,k