how to avoid nan result when calculate sparse matrics division
9 ビュー (過去 30 日間)
古いコメントを表示
I'm doing a calculation using sparse matrics with the size of 12905*12905. I attached the code here.
WH = ones(P.npts, 1);
A = [L.*WL;sparse(1:P.npts,1:P.npts, WH)];
b = [zeros(P.npts,3);sparse(1:P.npts,1:P.npts, WH)*P.pts];
cpts = (A'*A)\(A'*b);
'WL' is a weighted value. 'P.npts' means the number of points with double type, which is a mumber in the structure 'P'.
P.npts = 12905
My question is: Sparse matric 'A' and 'b'are not a zero matrics, and matric (A'*A) either. But I always get 'NaN' result of cpts matrics. How to avoid getting NaN result when calculating a sparse matric. The structure rank of A is 12905. Could anyone help to solve this problem? Really appreciated!
Thanks
0 件のコメント
採用された回答
John D'Errico
2017 年 8 月 31 日
Sigh. Without seeing your numbers, this is hard to tell. Just telling us the size of the matrix is irrelevant.
I will tell you that you are doing something that is foolish.
Do NOT do this:
cpts = (A'*A)\(A'*b);
That squares the condition number of the problem.
Whereas this does not:
cpts = A\b;
Whoever told you to use the form you are using was steering you to a very poor way of solving the problem.
In the end, what matters is what the rank and condition number of A is in terms of linear algebra. So what does this tell you?
cond(A)
If that is too slow, then just do
condest(A)
It won't be to far off. If the condition number is greater than roughly 1e8, then the form you were using will have a condition number of roughly 1e16, which will then potentially yield NaNs for a result.
So at the very least, report the condition number of A.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!