Clear Filters
Clear Filters

Symbolic eigenvectors returned by eig are incorrect

6 views (last 30 days)
Hi Community,
I am trying to work with symbolic eigenvalues and eigenvectors and a small, 5-by-5, matrix.
I am able to recover correct eigenvalues, that satisfy the definition, but when I compute the eigenvectors they do not satisfy the definition of eigenvectors.
According to the documentation (https://uk.mathworks.com/help/symbolic/eig.html), given [vecR, lambda] = eig(A), if vecR is the same size as A, then the matrix A has a full set of linearly independent eigenvectors that satisfy A*vecR = vecR*lambda.
Firstly, I check that all eigenvectors are linearly independent and follow that with check of eigenvalues according to the definition. Yet, 'Check 1' in eigenvectors fail. Do you have any ideas why?
Full code is attached below.
Thanks in advance.
clc; clear;
% Define variables
syms U R T E Gamma Ma
% Define Jacobian
A = [0, 0, R, 0, 0; 0, 0, R*U, 0, 0; T/(Gamma*Ma^2), 0, 0, 0, R/(Gamma*Ma^2); ...
0, 0, 0, 0, 0; 0, 0, R*(E + T/(Gamma*Ma^2)), 0, 0];
%% Find eigenvalues and right eigenvectors
[vecR, lambda, p] = eig(A);
if (length(A) == length(p))
fprintf('All eigenvectors are linearly independent. \n')
end
All eigenvectors are linearly independent.
%% Check eigenvalues
% Check 1
fprintf('Checking eigenvalues ... ')
Checking eigenvalues ...
msg = 'Eigenvalues do not satisfy the characteristic polynomial!';
assert(~any(det(A - lambda)), msg)
fprintf('[PASS] \n')
[PASS]
%% Check eigenvectors
% Check 1
fprintf('Checking right eigenvectors ... ')
Checking right eigenvectors ...
dummy1 = A*vecR;
dummy2 = vecR*lambda;
cond = isequaln(dummy1, dummy2);
msg = 'Right eigenvectors do not satisfy the eigenvalue problem!';
assert(cond, msg)
Error using assert
Right eigenvectors do not satisfy the eigenvalue problem!
fprintf('[PASS] \n')
  1 Comment
Christine Tobler
Christine Tobler on 25 Apr 2023
Calling
>> simplify(dummy1 - dummy2)
ans =
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
seems to show that the eigenvectors are correct, the problem would be that isequaln doesn't recognize that the two symbolic expressions in dummy1 and dummy2 are equal.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 25 Apr 2023
clc; clear;
% Define variables
syms U R T E Gamma Ma
% Define Jacobian
A = [0, 0, R, 0, 0; 0, 0, R*U, 0, 0; T/(Gamma*Ma^2), 0, 0, 0, R/(Gamma*Ma^2); ...
0, 0, 0, 0, 0; 0, 0, R*(E + T/(Gamma*Ma^2)), 0, 0];
%% Find eigenvalues and right eigenvectors
[vecR, lambda, p] = eig(A);
if (length(A) == length(p))
fprintf('All eigenvectors are linearly independent. \n')
end
All eigenvectors are linearly independent.
%% Check eigenvalues
% Check 1
fprintf('Checking eigenvalues ... ')
Checking eigenvalues ...
msg = 'Eigenvalues do not satisfy the characteristic polynomial!';
assert(~any(det(A - lambda)), msg)
fprintf('[PASS] \n')
[PASS]
%% Check eigenvectors
% Check 1
fprintf('Checking right eigenvectors ... ')
Checking right eigenvectors ...
dummy1 = A*vecR;
dummy2 = vecR*lambda;
Checking with isequaln is not the right tool to use. Check that the difference between the two is all zero.
cond = all(simplify(dummy1-dummy2) == 0, 'all');
msg = 'Right eigenvectors do not satisfy the eigenvalue problem!';
assert(cond, msg)
fprintf('[PASS] \n')
[PASS]
  2 Comments
Kamil Dylewicz
Kamil Dylewicz on 25 Apr 2023
Thanks! That seems to be doing the trick for the right eigenvectros. I am trying to do the same exercise for the left eigenvectors but it does not work. Since eig does not support left eigenvector computations for symbolic matrices, I computed eigenvectors of transpose(A) instead to retrive left eigenvectros of A but they fails the checks. Can you advise me on that problem as well?
clc; clear;
% Define variables
syms U R T E Gamma Ma
% Define Jacobian
A = [0, 0, R, 0, 0; 0, 0, R*U, 0, 0; T/(Gamma*Ma^2), 0, 0, 0, R/(Gamma*Ma^2); ...
0, 0, 0, 0, 0; 0, 0, R*(E + T/(Gamma*Ma^2)), 0, 0];
%% Find eigenvalues and right/left eigenvectors
[vecR, lambda, p] = eig(A);
if (length(A) == length(p))
fprintf('All eigenvectors are linearly independent. \n')
end
All eigenvectors are linearly independent.
[vecL, lam_ch] = eig(transpose(A));
%% Check eigenvalues
% Check 1
fprintf('Checking eigenvalues ... ')
Checking eigenvalues ...
msg = 'Eigenvalues do not satisfy the characteristic polynomial!';
assert(~any(det(A - lambda)), msg)
fprintf('[PASS] \n')
[PASS]
% Check 2
fprintf('Comparing right and left eigenvalues ... ')
Comparing right and left eigenvalues ...
msg = 'Right and left eigenvalues do not match!';
cond = all(simplify(lambda - lam_ch) == 0, 'all');
assert(cond, msg)
fprintf('[PASS] \n')
[PASS]
%% Check eigenvectors
% Check 1
fprintf('Checking right eigenvectors ... ')
Checking right eigenvectors ...
dummy1 = A*vecR;
dummy2 = vecR*lambda;
cond = all(simplify(dummy1 - dummy2) == 0, 'all');
msg = 'Right eigenvectors do not satisfy the eigenvalue problem!';
assert(cond, msg)
fprintf('[PASS] \n')
[PASS]
% Check 2
fprintf('Checking left eigenvectors ... ')
Checking left eigenvectors ...
dummy1 = vecL*A;
dummy2 = lambda*vecL;
cond = all(simplify(dummy1 - dummy2) == 0, 'all');
msg = 'Left eigenvectors do not satisfy the eigenvalue problem!';
assert(cond, msg)
Error using assert
Left eigenvectors do not satisfy the eigenvalue problem!
fprintf('[PASS] \n')
Christine Tobler
Christine Tobler on 25 Apr 2023
The following works for me:
[vecL, lam_ch] = eig(A.');
dummy1 = vecL.'*A;
dummy2 = lam_ch*vecL.';
cond = all(simplify(dummy1 - dummy2) == 0, 'all')
Note .' corresponds to calling transpose

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!