2
votes

A= [1 2 3;3 4 5;5 6 7], B=[1;1;1].I need to solve the equation AX=B. Here am using Matlab code like X=linsolve(A,B). But, using this a warning is occurred...

"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.541976e-18."

How to correct it?

3
this is probably a better place for this kind of questions math.stackexchange.comuser2485710
Your matrix A is singular, and therefore there are infinite solutions.Luis Mendo
@LuisMendo how to convert singular matrix into nonsingular without changing the dataJaya
@user3148302 To make it nonsingular you need to change at least one entry. You can't make it nonsngular withouth changing the dataLuis Mendo
Try X=A\B.... or X=B/AJohn Alexiou

3 Answers

1
votes

You can't do what you want: "convert singular matrix into nonsingular without changing the data", but you can find one solution to your system Ax = B by using the pseudoinverse, pinv.

The answer is the same you get when using mldivide. The warning you got using mldivide (or \) is only a warning, not an error. Check this link, to see how you can suppress the warning if you need to work with singular matrices and get tired of the warnings.

x = pinv(A)*B;
x =
  -5.0000e-01
   1.2490e-16
   5.0000e-01

Which gives:

A*x
ans =
   1.00000
   1.00000
   1.00000

From Egons answer to a similar question:

But do remember that such a system does not have a unique solution, so both the pseudo-inverse and the backslash operator may (and in this case will) return very different solutions, whether any of them is acceptable really depends on your application.

1
votes

The three vectors [1,2,3],[3,4,5],[5,6,7] lie in a single plane. How do I know? It's because I can see that [3,4,5]-[1,2,3]=[2,2,2], and [3,4,5]+[2,2,2]=[5,6,7].

Thus, when the question is "what linear combination of these three vectors gets me to this point", there are infinitely many such solutions if the point is in the plane, and none if it is not. Just by inspection you can see

[1,1,1] = ( [3,4,5]-[1,2,3] ) / 2

Meaning a solution is [-0.5 0.5 0]

Or

[1,1,1] = ( [5,6,7] -  [3,4,5] ) / 2

Meaning a solution is [0 -0.5 0.5]

Etc.

You can't make a problem something it is not - and in this case it is ill conditioned so there are infinitely many solutions. Matlab handles it in this case, but warns you. Pencil and paper will lead you to the same conclusion. There is no unique answer.

1
votes

Assuming that you are aware that THE solution may not exist, you can simply ask for a second output argument. This will tell Matlat that you are aware of the problem and just want to get the best possible solution.

Here is how it is done:

[X, R] = linsolve(A,B)

Mentioned in the doc of course.