MATLAB: Different eigenvectors when using eig and null functions

eigenvectorsnull

Hello,
I'm running a simple script to calculate the eigenvalues and eigenvectors of a given matrix using two different MATLAB functions. The eigenvalues from the two functions are matching. However, the eigenvectors are different. Below is the script:
A = [3 2 ; 7 -1];
syms x;
a2a = sym(A);
polya2a = charpoly(a2a,x);
eigenvalues = solve(polya2a);
eig1 = eigenvalues(1,1);
eig2 = eigenvalues(2,1);
v1 = null(A-eig1*eye(2))
v2 = null(A-eig2*eye(2))
[eig1_m, eig2_m] = eig(A);
v1 and v2 that are using the null function is not matching the eigenvectors obtained from eig function. I appreicate your help. Thanks.

Best Answer

Hi Mohammed,
I tossed in some 'double' functions to make the comparison easier
A = [3 2 ; 7 -1];
syms x;
a2a = sym(A);
polya2a = charpoly(a2a,x);
eigenvalues = solve(polya2a);
eig1 = double(eigenvalues(1,1))
v1 = double(null(A-eig1*eye(2)))
eig2 = double(eigenvalues(2,1))
v2 = double(null(A-eig2*eye(2)))
[w, lambda] = eig(A) % rename some stuff
%-----
eig1 = -3.2426
v1 = 0.3051
-0.9523
eig2 = 5.2426
v2 = 0.6656
0.7463
lambda = 5.2426 0
0 -3.2426
w = 0.6656 -0.3051
0.7463 0.9523
Compared to the first way of doing things, the second way has the order of the eigenvalues reversed. So the first column of w, which corresponds to eigenvalue lambda = 5.2426, should be compared to v2. And the second column of w, which corresponds to eigenvalue lambda = -3.2426, should be compared to v1. Both cases agree.
There is no requirement on the overall scaling of eigenvectors and there can be a constant of proportionality between w(:,1) and v2 for example. In that case the constant equals 1, and it's -1 for w(:,2) vs v1.