Issue regarding the result from symbolic computation
Show older comments
Hello,
Currently, I am trying to use symbolic computation in the process of solving the eigenvalue problem.
I need to do this because I need the solution of the eigendecomposition problem to be expressed using ingredients of the original matrix.
However, the result of algebraic expression from symbolic computation is not reliable.
For instance,
syms a11 a12 a22
A = [a11 a12 0; a12 a22 0; 0 0 0];
[R, EV] = eig(A); % Calculate eigenvalues and eigenvectors
[EV,ind] = sort(diag(EV),'descend');
R2= R(:,ind);
gives
R2 = [(a11/2 + a22/2 + (a11^2 - 2*a11*a22 + 4*a12^2 + a22^2)^(1/2)/2)/a12 - a22/a12 (a11/2 + a22/2 - (a11^2 - 2*a11*a22 + 4*a12^2 + a22^2)^(1/2)/2)/a12 - a22/a12 0;
1 1 0
;
0 0 1;];
However, this is not correct as if I give it a11 = 1, a12 = 0, a22 = 0, the matrix is
R2 =
NaN NaN 0
1 1 0
0 0 1
Although, the correct result is
R2 =
1 0 0
0 1 0
0 0 1
It is obvious that I get NaN values as the algebraic expression has the term with zero division.
Moreover, in the case a11 = 1/2, a12 = 1/2, a22 = 1/2, the result from symbolic computation is
R2 =
1 -1 0
1 1 0
0 0 1
Although, the correct result is
R2 =
0.7071 -0.7071 0
0.7071 0.7071 0
0 0 1.0000
Does anyone know the solution to circumvent this issue?
Accepted Answer
More Answers (1)
John D'Errico
on 15 Nov 2024
Edited: John D'Errico
on 15 Nov 2024
If you have this:
a11 = 1/2; a12 = 1/2; a22 = 1/2;
A = [a11 a12 0; a12 a22 0; 0 0 0]
The eigenvectors were found as:
[V,D] = eig(A)
[Vs,Ds] = eig(sym(A))
Vs =
[-1, 0, 1]
[ 1, 0, 1]
[ 0, 1, 0]
Ds =
[0, 0, 0]
[0, 0, 0]
[0, 0, 1]
Is the set of eigenvectors still a valid set? YES. Eigenvectors can be arbitrarily scaled, so that is v is an eigenvector, then k*v is still just as validly an eigenvector. Note that the symbolic eig likes to scale its eigenvectors differently from the numerical version. Complain to the author, not to us.
Regardless, you should see the result from the symbolic compiutation is as valid as the result from the numerical one.
In the fully symbolic case, doing exactly as you said, we see:
syms a11 a12 a22
A = [a11 a12 0; a12 a22 0; 0 0 0];
[Vs,Ds] = eig(A)
Now substitute
subs(Vs,[a11,a12,a22],[1,0,0])
and we get a 0/0 result, which is properly a NaN. However, if I plug in those values for a11,a12, and a22, first, then we get a reasonable result.
[Vs,Ds] = eig(subs(A,[a11,a12,a22],[1 0 0]))
Vs =
[0, 0, 1]
[1, 0, 0]
[0, 1, 0]
Ds =
[0, 0, 0]
[0, 0, 0]
[0, 0, 1]
1 Comment
John D'Errico
on 15 Nov 2024
Edited: John D'Errico
on 15 Nov 2024
Note that Answers is bugged as it often is lately, so symbolic results are not properly displayed.
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!