Discussion:
Warning: Matrix is singular to working precision.
(too old to reply)
VASIQ Khan
2016-08-06 09:29:03 UTC
Permalink
I am trying to find the inverse of the following matrix but its giving the following error;
Warning: Matrix is singular to working precision.

The matrix is a 9x9 matrix and all rows and columns are different ;

A = [1 0 0 1 0 0 1 0 0;0 1 0 0 1 0 0 1 0;0 0 1 0 0 1 0 0 1;0 -30 0 0 30 0 0 0 200;30 0 0 -30 0 0 0 0 0;0 0 0 0 0 0 -200 0 0;1 0 0 -1 0 0 0 0 0;0 0 1 0 0 -1 0 0 0;0 0 0 0 0 0 0 0 0];
Nasser M. Abbasi
2016-08-06 09:43:29 UTC
Permalink
Post by VASIQ Khan
I am trying to find the inverse of the following matrix but its giving the following error;
Warning: Matrix is singular to working precision.
The matrix is a 9x9 matrix and all rows and columns are different ;
A = [1 0 0 1 0 0 1 0 0;0 1 0 0 1 0 0 1 0;0 0 1 0 0 1 0 0 1;0 -30 0 0 30 0 0 0 200;
30 0 0 -30 0 0 0 0 0;0 0 0 0 0 0 -200 0 0;1 0 0 -1 0 0 0 0 0;0 0 1 0 0 -1 0 0 0;0 0 0 0 0 0 0 0 0];
it is not enough that all rows and columns be different. For example

A=[2 4;
6 12]

det(A)
0
Post by VASIQ Khan
inv(A)
Warning: Matrix is singular to working precision.

This is because three times first row gives the second row.

If you do det() on your matrix, you'll find it is zero also.

So your matrix rows or columns are not all linearly independent.
Sometimes it is hard to see it by just looking at the matrix,
specially if it is large one.

ps. you should not really need to explicit inverse of matrix if you
are trying to solve some equations.

--Nasser
John D'Errico
2016-08-06 13:02:04 UTC
Permalink
Post by Nasser M. Abbasi
it is not enough that all rows and columns be different. For example
True.
Post by Nasser M. Abbasi
If you do det() on your matrix, you'll find it is zero also.
det is a TERRIBLE way to identify if a matrix is singular.

Use rank instead.

Or test the condition number. If that is close to 1/eps,
then your matrix is effectively numerically singular.

Or check the singular values of your matrix.

But NEVER use det. It can easily steer you wrong.

For example, how non-singular is the matrix A here?

A = 1e-10*eye(100);

det(A)
ans =
0

det(A) == 0
ans =
1

But det(A) is computed as zero. Not just close to zero.
Flat out zero.

Admittedly, A is poorly scaled. So then try it with

A = 0.5*eye(1200);
det(A) == 0
ans =
1

So A is just a diagonal matrix with 1/2 on the diagonals
all the way down. Can you think of anything much less
singular than that? But det thinks it has a zero determinant.

It is pretty easy to go the other direction too.

A = 2*eye(1200);
det(A)
ans =
Inf

Det is just about the worst tool you can think of to test for
singularity. Hands down, flat out, bad. Unless of course,
you try this:

badSingTest = @(A) rand(1) < 0.5;

It will be correct roughly 50% of the time, no matter what
your matrix A contains. So even that seems a better choice
than det.

John

Loading...