Solution to a singular square matrix

224 Views Asked by At

Now I don't quite understand. I have this system below A2x=b and solving for x with linsolve or A2\b2 gives me NaN and det(A2) is zero -- A2 is a singular square matrix

A2 = [1 -1 0 0 0 0 0 0;
    0 1 1 0 0 0 0 0 ;
    0 0 -1 1 0 0 0 0 ; 
    0 0 0 1 1 0 0 0 ;
    0 0 0 0 1 -1 0 0;
    0 0 0 0 0 1 1 0 ;
    0 0 0 0 0 0 -1 1 ;
    1 0 0 0 0 0 0 1 ;];
b2 = [0; 150; 20; 410; 180; 210; 80; 230];
x = pinv(A2)*b2
det(A2)
x2 = A2\b2
A2 * x
AB2 = [A2 b2];
rref(AB2)

But it has infinite solutions,right? since the rref(AB2) below gives me the reduced row echelon of - one free variable but there is a solution, infinite ones:

     0     1     0     0     0     0     0     1   230
     0     0     1     0     0     0     0    -1   -80
     0     0     0     1     0     0     0    -1   -60
     0     0     0     0     1     0     0     1   470
     0     0     0     0     0     1     0     1   290
     0     0     0     0     0     0     1    -1   -80
     0     0     0     0     0     0     0     0     0

Why doesn't then linsolve and \ give me a solution vector? pinv() does, but that is not a solution but a pseudoinverse so the Ax =b doesn't give me exact b, but as good as it gets I guess. Am I understanding my reduced row echelon matrix wrong - is there no solution to this system??

1

There are 1 best solutions below

0
On

You may understand better the behaviour of each built-in function checking its documentation. You almost have the answer to this apparently strange behaviour you observed.

First, you noticed the det(A) is 0, so the matrix is singular. Actually, 'det(A)' is not the best way to check for matrix singularity. The rcond function mentions that:

Examine why the reciprocal condition number is a more accurate measure of singularity than the determinant.

rcond(A2)
   ans = 0

This indicates A2 is singular and inversion is not possible. The mldivide documentation indicates the behaviour of the \ operator for singular matrices:

When rcond is equal to 0, the singular warning appears.

x2 = A2\b2

Warning: Matrix is singular to working precision.

In this case, division by zero leads to computations with Inf and/or NaN, making the computed result unreliable.

Now, you also tried to compute the solution using the pinv function. Notice that the documentation on the \ operator also states that:

If the rank of A is less than the number of columns in A, then x = A\B is not necessarily the minimum norm solution. You can compute the minimum norm least-squares solution using x = lsqminnorm(A,B) or x = pinv(A)*B.

So, even though the system has infinitely many solutions, the pinv function returns the minimum norm least-squares solution (check it, for any other solution you may find, the norm of the vector is greater than the solution provided by the pinv function).

The pinv function states that:

(This) solution (is) exact, in the sense that norm(A2*x-b2) is on the order of roundoff error. [...] The solution x is special because norm(x2) is smaller than it is for any other solution [...].

The reduced row echelon matrix is not wrong. Your system has infinitely many solutions.