Error in lu-decomposition function?
5 ビュー (過去 30 日間)
古いコメントを表示
I need to do a lu-decomposition, receiving a lower triangular matrix with unit diagonal. The MATLAB-Function [L,R,P] = lu(A) should do exactly that.
A=[ 28 -35 21
-12 19 -15
16 -30 48];
[L,R,P]=lu(A);
Testing the result:
P*A==L*R
ans =
1 1 1
1 1 1
1 1 0
What am I overlooking, why do the results not match?
0 件のコメント
回答 (1 件)
John D'Errico
2015 年 12 月 14 日
編集済み: John D'Errico
2015 年 12 月 14 日
No. This is NOT an error in the lu function, but an error in how you think about floating point arithmetic.
Instead of testing for EXACT equality, why not subtract the two? What is the difference?
Do you want to make a bet that the differences are tiny numbers? In fact, it looks like only one of the elements was not exactly the same. I'll save you some time.
P*A-L*R
ans =
0 0 0
0 0 0
0 0 -1.7764e-15
So welcome to the world of floating point arithmetic, where you should virtually NEVER test for exact equality.
13 件のコメント
Christine Tobler
2015 年 12 月 17 日
編集済み: Christine Tobler
2015 年 12 月 17 日
The problem with this brute-force lu decomposition is that it doesn't do permutation, which can lead to completely wrong results. For example, try this matrix:
A = [0 0 1; 1 0 0; 0 1 0];
The brute-force LU will return matrices L and U with Inf and NaN values, while the lu function's output is still correct. In less extreme examples, not using permutation will simply lead to high levels of numerical error.
For the plots you show, I assume from your answer that the first is using your brute-force algorithm and the second the output from lu? In that case, I would assume there is something wrong with the way you are using L, U and P to solve the linear system. Can you post your formula for this?
If you only need to solve one linear system, you can also just use
x = A \ b;
which will solve the linear system A*x = b directly without any worries about the decomposition used.
John D'Errico
2015 年 12 月 17 日
Yes. the pivoted LU will be more accurate, although still not perfect. Nothing can achieve that, unlesss you use exact arithmetic.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



