[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Possible wrong matrix determinant value
From: |
HALL, BENJAMIN PW |
Subject: |
RE: Possible wrong matrix determinant value |
Date: |
Wed, 13 May 2009 09:09:42 -0400 |
|-----Original Message-----
|From: Marco Guazzone [mailto:address@hidden
|
|It seems the function "det()" gives a wrong determinant value for
|certain matrices.
|
|Look at the following code:
|
|--- [code_snip] ---
|A=[0.5560, 0.2747, 0.5406, 0.7989; 0.1089, 0.8301, 0.8917, 0.8953;
|0.9480, 0.9732, 0.2165, 0.8832; 0.0238, 0.6754, 0.2318, 0.4503]
|det(A);
|--- [/code_snip] ---
|
|The result (on my machine: Intel Core 2 Duo+Fedora 10 x86_64) with
|octave 3.0.3 is: -0.078647
|
|However, trying with other tools/libraries, the above value seems to
|be wrong. In fact:
|
|With Octave 3.0.3: -0.078647
|With BOOST uBLAS 1.39: -0.07874537
|With R 2.9.0: -0.07874537
|With NumPy 1.2.0: -0.078745369636711721
|With Mathematica 7: -0.07874537
|
Are you sure you entered exactly the same matrix into all the different
codes? I get the following:
Octave: -0.0786470081539579
Mathematica: -0.07864700815395793
Matlab: -0.078647008153958
R: -0.078647008154
===================================================
octave-3.0.0:
octave:1> A=[0.5560, 0.2747, 0.5406, 0.7989; 0.1089, 0.8301, 0.8917,
0.8953;
> 0.9480, 0.9732, 0.2165, 0.8832; 0.0238, 0.6754, 0.2318, 0.4503]
A =
0.556000 0.274700 0.540600 0.798900
0.108900 0.830100 0.891700 0.895300
0.948000 0.973200 0.216500 0.883200
0.023800 0.675400 0.231800 0.450300
octave:3> dd = det(A)
dd = -0.078647
octave:4> format long
octave:5> dd
dd = -0.0786470081539579
===================================================
Matlab-7.7.0:
>> A=[0.5560, 0.2747, 0.5406, 0.7989; 0.1089, 0.8301, 0.8917, 0.8953;
0.9480, 0.9732, 0.2165, 0.8832; 0.0238, 0.6754, 0.2318, 0.4503]
A =
0.5560 0.2747 0.5406 0.7989
0.1089 0.8301 0.8917 0.8953
0.9480 0.9732 0.2165 0.8832
0.0238 0.6754 0.2318 0.4503
>> dd = det(A);
>> format long
>> dd
dd =
-0.078647008153958
===================================================
Mathematica-6.0:
A = {{0.5560, 0.2747, 0.5406, 0.7989},
{0.1089, 0.8301, 0.8917, 0.8953},
{0.9480, 0.9732, 0.2165, 0.8832},
{0.0238, 0.6754, 0.2318, 0.4503} };
A // MatrixForm
d = Det[A];
Out[19]= -0.078647
NumberForm[Det[A], 16]
Out[32]= -0.07864700815395793
===================================================
R-2.8.1:
A <- matrix( c(0.5560, 0.2747, 0.5406, 0.7989,
0.1089, 0.8301, 0.8917, 0.8953,
0.9480, 0.9732, 0.2165, 0.8832,
0.0238, 0.6754, 0.2318, 0.4503), nrow=4, ncol=4 )
A <- t(A) ## not that this matters for the determinant
> A
[,1] [,2] [,3] [,4]
[1,] 0.5560 0.2747 0.5406 0.7989
[2,] 0.1089 0.8301 0.8917 0.8953
[3,] 0.9480 0.9732 0.2165 0.8832
[4,] 0.0238 0.6754 0.2318 0.4503
> det(A)
[1] -0.07864701
> print(sprintf("%.12f",det(A)))
"-0.078647008154"