deleting row and column from very large Sparse matrix efficiently
32 views (last 30 days)
I am performing the following operation for deleting row and column from very large *Sparse* stiffness (K) matrix
K(doft,:) = 0;
K(:,doft) = 0;
K(doft,doft) = speye(length(doft));
but it taking lots of time as indexing of sparse matrix is very slow. would you please suggest me the better option to do it efficiently.
Thanks in advance
Zhuoran Han on 1 Jan 2021
This is an easy way to deal with boundary conditions in stiffness matrices, have you tried permutation?
Suppose your original matrix is A = [a b c; d e f; g h i], and your desired matrix is B = [a 0 c; 0 1 0; g 0 i], you can try to break A into 9 peices from a to i (all matrices instead of numbers), and concatenate them together.  is quite fast with sparse matrices. If you want the upper left 100x100 from a 1000x1000 matrix, use A(1:100,1:100) similar to permutation.
Another idea might be faster, you reorder (permute) the entire matrix and move the "doft" rows and cols to lower right, and use A(1:900,1:900) to extract the entire upper left matrix, and then blkdiag with speye(100). blkdiag is very fast with sparse matices. Finally, try to back-permute the entire matrix.