Error calculating inverse for matrix block of LU decomposition of a full row rank matrix

4 次查看(过去 30 天)
I have the following code for calculating LU for sparse rectangular matrices with full row rank
rows = 100;
columns = 120;
A = sprand(rows,columns,0.1);
while rank(full(A))<rows %full row rank matrix
A=sprand(rows,columns,0.1);
end
[L,U,P1,P2] = sparseLU(A);
U1 = U(:,1:rows); % first m columns of U, square matrix of order m
U2 = U(:,rows+1:columns); % rest of the matrix U
X = inv(U1);
function [lower,upper,P1,P2] = sparseLU(sparseA)
[L,U,P,Q] = lu(sparseA); % P*A*Q = L*U
lower = L;
upper = U;
P1 = P;
P2 = Q;
end
Breaks down when calculating the matrix X, which has only NaN values. After using spy() on U1 I noticed that it has zero entries on the main diagonal, but I'm not sure how this can happen since LU uses full pivoting and A is full row rank. My goal is to calculate X.
Any help is welcome.

采纳的回答

Bruno Luong
Bruno Luong 2024-3-17
编辑:Bruno Luong 2024-3-17
It's a little bit perturbant, but reading the lu doc I don't see why U1 must have the same rank than U (or A, meaning 100 on your example). Therefore there is no reason to expect that the diagonal of U have all non zero elements.
The full rank occurs if you swap one of the column of U2 with the column of U1 that has 0 on the main diagonal.
  1 个评论
weyronndsb000
weyronndsb000 2024-3-17
After perfoming LU I swapped the zero diagonal entries with non zero ones from the right side of the matrix while swapping the columns of the permutation matrix P2 on your advice using a while loop and now I have all non zeros on the main diagonal, thank you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by