Issue regarding the result from symbolic computation

조회 수: 56 (최근 30일)
ArxIv
ArxIv 2024년 11월 15일 16:03
댓글: ArxIv 2024년 11월 18일 23:59
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?

채택된 답변

Paul
Paul 2024년 11월 16일 4:48
편집: Paul 2024년 11월 16일 11:43
Hi ArxIv,
Expectations might be too high for symbolic solutions of eigenvectors.
Consider a simpler, but very closely related problem:
a11 = 5;a22 = 10;
syms a12
A = [a11,a12;a12,a22];
[V,D] = eig(A);
diag(D)
disp(char(ans))
[15/2 - (4*a12^2 + 25)^(1/2)/2; (4*a12^2 + 25)^(1/2)/2 + 15/2]
V = simplify(V)
disp(char(V))
[-((4*a12^2 + 25)^(1/2) + 5)/(2*a12), ((4*a12^2 + 25)^(1/2) - 5)/(2*a12); 1, 1]
I believe that the eigenvalues will yield the correct result for any value of a12, as will the eigenvectors except for the problematic case if we attempt to evaluate them at a12 = 0. The question is if there exists a general expression for V that works for all possible values of a12. If not, then the ideal solution would be for eig to return a piecewise expression of some sort for V taking into account all possible special cases. Other functions, like int also typically do not identify and return piecewise solutions for special cases. I'd imagine it may be difficult to find all special cases for more complicated problems. So I guess eig does the best it can.
Sometimes, we can get the solution by taking the limit as a12 ->0, which works in this case for V(:,2)
limit(V(:,2),a12,0),disp(char(ans))
[0; 1]
But that "trick" doesn't work as well for V(:,1)
limit(V(:,1),a12,0),disp(char(ans))
[NaN; 1]
though it kind of does if we realize that V(1,1) is blowing up to infinity, and so the normalized eigenvector is, in fact, approaching [1;0].
Also, using sort on symbolic expressions is problematic.
syms a11 a22 real
sort([a11,a22],'descend'),disp(char(ans))
[a22, a11]
Is there any mathematical reason to expect a22 >= a11? What happens if we sub values for a11 and a22 into that result when the latter is smaller than the former?
In addition, sort apparently doesn't respect assumptions
assumeAlso(a11 > a22);
sort([a11,a22],'descend'),disp(char(ans))
[a22, a11]
  댓글 수: 2
John D'Errico
John D'Errico 2024년 11월 16일 12:52
편집: John D'Errico 2024년 11월 16일 12:54
@Paul has made some very valid points in terms of your expectations for the eigenvectors.
ArxIv
ArxIv 2024년 11월 18일 23:59
Thank you very much for your answers.
I learned a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2024년 11월 15일 16:47
편집: John D'Errico 2024년 11월 15일 17:01
If you have this:
a11 = 1/2; a12 = 1/2; a22 = 1/2;
A = [a11 a12 0; a12 a22 0; 0 0 0]
A = 3×3
0.5000 0.5000 0 0.5000 0.5000 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The eigenvectors were found as:
[V,D] = eig(A)
V = 3×3
-0.7071 0 0.7071 0.7071 0 0.7071 0 1.0000 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 3×3
0 0 0 0 0 0 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[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])
Error using sym/subs (line 156)
Division by zero.
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
John D'Errico
John D'Errico 2024년 11월 15일 16:51
편집: John D'Errico 2024년 11월 15일 16:55
Note that Answers is bugged as it often is lately, so symbolic results are not properly displayed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by