Matrix is close to singular or badly scaled

Hello,
I am receiving the following error when I attempt a simple matrix division within MATLAB. It follows the form of Ax = B. The line of code I have put in to find x is
x = inv(A) * B
It is returning the error:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.938882e-018. > In example at 4
x =
1.0e+019 *
1.1621
-0.6298
7.0903
The values of the A and B matrices are below.
A = [-180 -152 16; -20 -172 -12; -160 20 28]
B = [-13960; -87501; -52408]
I know what the answer for the x matrix should be, but I need the code to make MATLAB do it, and it is miles out. Can anyone help?

1 Comment

Please consider using the mldivide ('\') operator instead of using inv(); it would be A\B
http://www.mathworks.com/help/techdoc/ref/mldivide.html

Sign in to comment.

Answers (2)

A = [-180 -152 16; -20 -172 -12; -160 20 28]
det(A)
% >> 0
A is singular. Then you cannot create the inverse. What do you expect as answer for x then?!
Richard
Richard on 17 Nov 2011
The answer that satisfies all three equations is
x = [50 40 70]
Can you give any indication of how to make this work or improve it? Many thanks.

1 Comment

No. This x does not satisfy the equations:
A = [-180 -152 16; -20 -172 -12; -160 20 28];
B = [-13960; -87501; -52408];
x = [50; 40; 70]; % Column vector!
disp(A * x);
% >> [-13960; -8720; -5240]
A*x is definitely not B.
As I said already: A is singular. Because there is no inverse of a singular matrix, you cannot calculate inv(A)*B. In consequence you can neither make it working nor inmprove it.
Please check the values again for typos.

Sign in to comment.

Asked:

on 17 Nov 2011

Community Treasure Hunt

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

Start Hunting!