MATLAB: Not showing the right set of linearly independent eigenvectors

bugeigenvectormathematicsmatricesmatrixnumerical instability

I am using matlab R2013a.
Consider the matrix
A = [0 1 1 1 0;
0 0 0 0 1;
0 0 0 0 0;
0 0 0 0 0;
0 0 0 0 0];
Clearly, it's rank is 2; so nulity is 3. But while computing all its eigenvectors, it's showing as if it has only one linearly independent eigenvector. Theoretically, it has [1;0;0;0;0],[0;1;-1;0;0],[0;1;0;-1;0] as three linearly independent eigenvectors corresponding to the 0 eigenvalue.
So why is it so with the command [vA,d]=eig(A)?

Best Answer

To compute eigenvalues, the eig function tries to minimize A*V - V*D to numerical precision of double. Since eig uses floating point computation this can only approach zero, and not exactly zero (try printing A*V-V*D). In case of defective matrices this behavior is expected. You can try using Symbolic Math as a workaround as below
B = sym(A);
[V,D] = eig(B);
This will give you correct eigenvalues and eigenvectors but it will come with a computational penalty for large matrices. MATLAB documentation on eigenvalues of defective matrices can be found here.