Sparse Matrices and Machine Precision
古いコメントを表示
I have a large sparse matrix, K. My problem is that over time some values in K that where once non-zero will change to zero through some matrix calculations. However, due to floating point precision inaccuracies the values don't reach exactly zero. Thus Matlab allows these near zero values to be represented as non-zero values.
Currently my solution is
K(abs(K)<threshold) = 0;
where threshold is some small value. This does help, however this operation is slow and as K is changed by matrix operations often, it needs to be re-run often.
Is there a way to force sparse matrices to see values smaller than a certain threshold as zero? Or is there another solution?
Thanks
採用された回答
その他の回答 (1 件)
James Tursa
2012 年 1 月 6 日
1 投票
If you are really desperate for speed one could write a mex routine to do this operation in-place. My guess is it probably wouldn't take too much time ... but that is just a guess. You would have to manually call this function, however. As John noted, you cannot make MATLAB automatically do this for all of your linear algebra calculations.
2 件のコメント
Superfish
2012 年 1 月 6 日
James Tursa
2012 年 1 月 7 日
No. I mean have MATLAB do the matrix multiplication, but after the fact have a mex routine clean it of small values in-place.
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!