1
$\begingroup$

Consider the following matrix: $ \left[ \begin{array}{ccc} -0.05 & 0.45 & 0 \\ 0.05 & -0.45 & 0 \end{array} \right] $

Row reducing the above matrix in Matlab using the rref() function produces what I would expect (just adding top row to bottom row and scaling top row): $ \left[ \begin{array}{ccc} 1.0 & -9.0 & 0 \\ 0 & 0 & 0 \end{array} \right] $

But if I remove the last column of just zeros, and row reduce that matrix, I get a 2x2 identity matrix: $ \left[ \begin{array}{ccc} -0.05 & 0.45 \\ 0.05 & -0.45 \end{array} \right] \sim \left[ \begin{array}{ccc} 1 & 0 \\ 0 & 1 \end{array} \right] $

I can't see how removing the last column changes anything; adding the top row to the bottom row will still produce the result above, just without the last column of $0$'s. But I'm quite sure Matlab is right and I'm not, so what am I missing here?

Edit: I have managed to reproduce the above and I believe it's all due to rounding errors. If you input $ M = \left[ \begin{array}{ccc} 0.95 & 0.45 \\ 0.05 & .55 \end{array} \right] $ and then do $ A = M - eye(2) $. rref(A) will now give the $2 \times 2$ identity matrix. If I enter the result of $M-eye(2)$ directly, that is $B= \left[ \begin{array}{ccc} -0.05 & 0.45 \\ 0.05 & -0.45 \end{array} \right] $, then rref(B) returns the expected $ \left[ \begin{array}{ccc} 1 & -9 \\ 0 & 0 \end{array} \right] $ .

Here's a screenshot as an example:

enter image description here

  • 0
    @J.M. I am using M$A$TL$A$$B$ 7.11.0 (R2010b).2011-10-20

1 Answers 1

3

This is already documented in MATLAB.

Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.

You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with

N-eye(2)  ans =     -5.000000000000004e-002    4.500000000000000e-001     5.000000000000000e-002   -4.500000000000000e-001 

Here, the trouble is already visible in the (1,1) element of the matrix. But also

 [1 1]*(N-eye(2))  ans =     -4.163336342344337e-017    5.551115123125783e-017 

gives you the error between seemingly identical elements.

The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.