Different eigenvectors when using eig and null functions
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
David Goodmanson
2020년 6월 8일
편집: David Goodmanson
2020년 6월 8일
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.
댓글 수: 3
David Goodmanson
2020년 6월 8일
Hi Mohammed,
I don't know what to say, because I just copied the code back into the editor and it works fine. I'm using 2019b. And the v1 and v2 calculations are your expressions preceded by 'double'. What do you get without using double?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!