Matlab gives wrong determinant value of 2x2 Matrix without warning.

7 次查看(过去 30 天)
Hi,
When I am taking the determinant of 2x2 reciprocal matrix with matlab ( which should be 1 ) , matlab is giving wrong results without any warning for overflow. Here is what I am doing :
m =
63245986 102334155
102334155 165580141
>> det(m)
ans =
1.5249
>> m(1)*m(4)-m(2)*m(3)
ans =
2
If I mannually do the calculation , I am getting the right result ie ans=1 . Please check and tell the reason for the same.

回答(5 个)

Derek O'Connor
Derek O'Connor 2012-3-20
@Nitin,
The "issue" here is not round-off. It is the ill-condition of your matrix. Floating point arithmetic and its rounding merely certify that your matrix is ill-conditioned; it does not cause your matrix to be ill-conditioned. Even if you use infinite precision (exact) arithmetic, your matrix is still ill-conditioned. There is no floating point "work-around".
Your calculation does not "suffer from large roundoff error". The large (forward) error is caused by a small round-off error which is then magnified by the huge condition number: Ef = Cond(A)*Er.
I would follow Nick Trefethen's advice and ask a different question (use a different matrix):
If the answer is highly sensitive to perturbations, you have probably asked the wrong question.

Andreas Goser
Andreas Goser 2012-3-19
I can explain, but can't tell what do do else. If you look at
m(1)*m(4)
ans =
1.047227927956403e+16
m(2)*m(3)
ans =
1.047227927956402e+16
Then you see those numbers are large and relatively close to each other. What you see is simply a numerical effect.
  3 个评论
Titus Edelhofer
Titus Edelhofer 2012-3-19
Second comment: to get the exact result you will need to compute the determinant symbolically:
M = sym(m)
M =
[ 63245986, 102334155]
[ 102334155, 165580141]
det(M)
ans =
1

请先登录,再进行评论。


Aldin
Aldin 2012-3-19
It depends of your MATLAB version. My version is MATLAB 7.9.0 (R2009b) - worked a charm. By me the result of matrix is 2.
  1 个评论
Andreas Goser
Andreas Goser 2012-3-19
Which may be more the effect of 32 bit vs. 64 bit MATLAB or a different processor or a different BLAS library...

请先登录,再进行评论。


Derek O'Connor
Derek O'Connor 2012-3-19
The products above are too big to fit in 32-bit integers. You can get the correct result by switching to 64-bit integers:
>> m64 = int64(A)
>> detm64 = m64(1)*m64(4)-m64(2)*m64(3)
detm64 = 1
Look at the L-U decomposition of A:
>> [L U P] =lu(A)
L =
1.000000000000000e+000 0
6.180339887498949e-001 1.000000000000000e+000
U =
1.023341550000000e+008 1.655801410000000e+008
0 -1.490116119384766e-008
P =
0 1
1 0
This shows that U(2,2) is numerically zero relative to U(1,1) and U(1,2). Thus U is numerically singular, and so is A.
Now look at the lower bound estimate of the 1-norm condition of A:
lbcond1A = condest(A) = 4.707074327130931e+016
This shows that A is very ill-conditioned. There is no hope of getting accurate results with double precision because log10(condest(A)) is about 17, the number of digits of precision lost when calculating the solution of Ax = b.
This example shows that there is no connection between det(A) and the condition of a matrix.

Nitin Chhabra
Nitin Chhabra 2012-3-20
Hi Andreas/Titus/Derek,
You are correct that values are numerically zero relative to other values and I am getting roundoff errors. But I require some work-around for this round off errors ( numerical issues ) in case of complex matix(a+jb).
with regards,
Nitin

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by