Message Boards Message Boards

1
|
6783 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Should LinearSolve warn that this matrix is singular?

Posted 12 years ago
There is a blog post on WalkingRandomly pointing out that numpy doesn't give a warning when trying to solve a linear system with a singular matrix.  Many other systems, such as MATLAB, Octave and R do give a warning.  I tried the same matrix in Mathematica and it seems that for the matrix itself it does give a warning, but not for its transpose.  

Do you consider this incorrect behaviour?

Here are the examples:
mat = Partition[Range[9], 3]
LinearSolve[N[mat], {15, 15, 15}]

LinearSolve::luc: "Result for LinearSolve of badly conditioned matrix {{1.,2.,3.},{4.,5.,6.},{7.,8.,9.}} may contain significant numerical errors. "
{-39., 63., -24.}

LinearSolve[N[mat\[Transpose]], {15, 15, 15}]
{-2.5, -2.66454*10^-15, 2.5} (* no warning *)
POSTED BY: Szabolcs Horvát
Hi,

This is related with the condition number, the max/min ratio of the singular values of the matrix (here).

The singular values of N(mat) are
SingularValueList[N[mat], Tolerance -> 0]
{16.8481, 1.06837, 5.54311*10^-16}
while those of the transpose are
SingularValueList[N[Transpose[mat]], Tolerance -> 0]
{16.8481, 1.06837, 3.92749*10^-16}
The transpose has a slightly larger condition number. The difference is due to the nature of the floating point arithmetic. The smallest singular value of the exact matrix is of course zero.

Now for another singular matrix mat1,
mat1 = {{1, 1, 1}, {1, 2, 4}, {1, 4, 10}};
LinearSolve[N[mat1], {15, 15, 15}]
{10.7143, 6.42857, -2.14286}
LinearSolve[N[Transpose[mat1]], {15, 15, 15}]
{10.7143, 6.42857, -2.14286}
and no warning is given. The singular values are
SingularValueList[N[mat1], Tolerance -> 0]
{11.8151, 1.18493, 1.86425*10^-16}
SingularValueList[N[Transpose[mat1]], Tolerance -> 0]
{11.8151, 1.18493, 1.86425*10^-16}
Hence both have the same condition number, which is even larger than that of Transpose(mat). Mathematica is silent for exactly singular matrices, too,

This means that LinearSolve gives the "badly conditioned matrix" warning for matrices with the condition number in some range but gives no warning for exactly or nearly singular matrix. If higher precision is used, the conditition number will become larger and the warning message may disappear.

Youngjoo Chung
POSTED BY: Youngjoo Chung
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract