我有LU分解的代码,但是我想要包括L和U的行列式,以便输出将是LU的决定因素或PLU的决定因素。
function [ P, L, U ] = LUdecomposition(A)
A=input('matrix A =');
m = size(A);
n = m(1);
L = eye(n);
P = eye(n);
U = A;
for i=1:m(1)
if U(i,i)==0
maximum = max(abs(U(i:end,1)));
for k=1:n
if maximum == abs(U(k,i))
temp = U(1,:);
U(1,:) = U(k,:);
U(k,:) = temp;
temp = P(:,1);
P(1,:) = P(k,:);
P(k,:) = temp;
end
end
end
if U(i,i)~=1
temp = eye(n);
temp(i,i)=U(i,i);
L = L * temp;
U(i,:) = U(i,:)/U(i,i);
end
if i~=m(1)
for j=i+1:length(U)
temp = eye(n);
temp(j,i) = U(j,i);
L = L * temp;
U(j,:) = U(j,:)-U(j,i)*U(i,:);
end
end
end
P = P';
end
答案 0 :(得分:0)
L和U是三角矩阵。所以它们的决定因素是对角元素的乘积。在经典的LU分解中,L的对角元素是1,因此det(L)= 1.由于A = L * U => det(A)= det(L)* det(U)您可以通过计算U的行列式来轻松计算LU的行列式。因此det(PLU)= +或 - det(LU)。我不确定如何弄明白:/