deleting row and column from very large Sparse matrix efficiently
14 次查看(过去 30 天)
显示 更早的评论
dear frnds
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
0 个评论
回答(1 个)
Zhuoran Han
2021-1-1
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!