Clear Filters
Clear Filters

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

2 views (last 30 days)
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
[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;
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.

Accepted Answer

Bruno Luong
Bruno Luong on 17 Mar 2024
Edited: Bruno Luong on 17 Mar 2024
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 Comment
weyronndsb000 on 17 Mar 2024
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.

Sign in to comment.

More Answers (0)


Find more on Operating on Diagonal Matrices in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!