1
我試圖與主要基於LU decomposition with partial pivoting MatlabMATLAB LU分解的部分迴轉
function [L,U,P] = lup(A)
n = length(A);
L = eye(n);
U = zeros(n);
P = eye(n);
for k=1:n-1
% find the entry in the left column with the largest abs value (pivot)
[~,r] = max(abs(A(k:end,k)));
r = n-(n-k+1)+r;
A([k r],:) = A([r k],:);
P([k r],:) = P([r k],:);
L([k r],:) = L([r k],:);
% from the pivot down divide by the pivot
L(k+1:n,k) = A(k+1:n,k)/A(k,k);
U(k,1:n) = A(k,1:n);
A(k+1:n,1:n) = A(k+1:n,1:n) - L(k+1:n,k)*A(k,1:n);
end
U(:,end) = A(:,end);
end
這似乎對於大多數矩陣(等於MATLAB魯功能)工作,我的路分解工作,但下面的矩陣似乎以產生不同的結果:
A = [
3 -7 -2 2
-3 5 1 0
6 -4 0 -5
-9 5 -5 12
];
我只是不知道什麼是錯的。它似乎在鏈接提到的矩陣上工作正常