MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Brian
on 3 Nov 2012

I've been experiencing an error while working in Matlab. When I try to run the program I'm using, an error message appears saying "Warning, matrix is singular to working precision". The program still runs, but all the values it is supposed to calculate evaluate to "Nan", which usually indicates that the mathematical procedure to calculate it failed to work properly. I think it occurs when the program tries to perform Gaussian elimination on the 44 by 44 matrix the program generates. I double-checked the matrix and most of the entries are zero, but I don't think it can be singular since its main diagonal doesn't have any zero entries. Does anyone know where this problem originates from and how to fix it?

Edit: Strangely, the error has changed after I switched to a smaller set of inputs. It now reads "matrix is close to singular or badly scaled", and automatically gives a RCOND value of 6.622407e-021. I'm not sure what the value means. The matrix description I gave above has not changed, except it is now 26 by 26 in size.

*No products are associated with this question.*

Answer by Walter Roberson
on 3 Nov 2012

Consider this matrix:

[1 2 3 4; 2 4 6 8; 3 6 9 12; 4 8 12 16];

The matrix has no 0's on its main diagonal, but it is quite singular.

What does rank() report for the matrix? What does rcond() report ?

Brian
on 3 Nov 2012

Thanks for the reply. Sorry, I forgot to mention that the other diagonal of my matrix does have zeroes, so the determinant would be "nonzero # - zero", thus nonsingular, unless I'm missing something else.

How do I edit a program to display rank and rcond? The program I am using was not written by me (teacher wrote it for the class to use), and I'm new to Matlab and unfamiliar with programming in general.

Edit: Strangely, the error has changed after I switched to a smaller set of inputs. It now reads "matrix is close to singular or badly scaled", and automatically gives a RCOND value of 6.622407e-021. I'm not sure what the value means. The matrix description I gave above has not changed.

Answer by Star Strider
on 3 Nov 2012

You are dealing with ` Sparse Matrices` and they require special procedures. If you are solving linear equations for instance, consider using

## 2 Comments

## Brian

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52641#comment_109147

Nevermind everyone, I figured out that the data I was entering into the input file was flawed. Thanks to Roberson and Strider regardless.

## Jonathan Epperl

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52641#comment_109150

Just for future reference: The diagonal of a matrix doesn't give you any information on "how singular" the matrix is, unless it is diagonally dominant, i.e.

or

in which case the eigenvalues lie on the same side of the complex plane as the diagonal element and the matrix is thus non-singular.