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.
The difference between a full and a sparse matrix in MATLAB is not really a mathematical one (because all calculations should work correctly either way), but more a matter of how the entries of the matrix are stored.
The MATLAB documentation links to this paper for more information and the following example is given there:
The command
A = [0 0 11; 22 0 0; 0 33 0]
generates a full matrix, which can be displayed as
A =
0 0 11
22 0 0
0 33 0
This means that all the zeros are actually stored explicitly in memory, because also the number $0$ needs the same amount of memory as every other number does.
If the full matrix is transformed to a sparse matrix with the command
S = sparse(A)
it is displayed (and stored in memory) as
S =
(2,1) 22
(3,2) 33
(1,3) 11
You can see here that only the nonzero entries of the matrix and in addition their positions inside the matrix are stored, whereas the zero elements are ignored and all entries of the matrix which are not present in the $(i,j)$-coordinates are implicitly assumed to be zero.
If a matrix has a large number of zeros, this way of storing it saves a lot of memory: If you have a $n\times n$ -matrix with $m$ nonzero elements, it needs $n^2$ units of memory to be stored as a full matrix, but $3m$ units of memory to be stored as a sparse matrix (assuming that storing the positions $(i,j)$ needs 2 units of memory). If $m$ is much smaller than $n^2$, i.e. the matrix is sparse, then you will see that $3m$ is of course also much smaller than $n^2$.
Best Answer
MatLab does a strange trick, namely: $$ A=P^{-1}LU, $$ so just pose: $$ B=P^{-1}LU, $$ and verify that $A=B$.