Issue regarding the result from symbolic computation
57 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ArxIv
el 15 de Nov. de 2024 a las 16:03
Comentada: ArxIv
el 18 de Nov. de 2024 a las 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?
0 comentarios
Respuesta aceptada
Paul
el 16 de Nov. de 2024 a las 4:48
Editada: Paul
el 16 de Nov. de 2024 a las 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))
V = simplify(V)
disp(char(V))
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))
But that "trick" doesn't work as well for V(:,1)
limit(V(:,1),a12,0),disp(char(ans))
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].
syms a11 a22 real
sort([a11,a22],'descend'),disp(char(ans))
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?
assumeAlso(a11 > a22);
sort([a11,a22],'descend'),disp(char(ans))
2 comentarios
John D'Errico
el 16 de Nov. de 2024 a las 12:52
Editada: John D'Errico
el 16 de Nov. de 2024 a las 12:54
@Paul has made some very valid points in terms of your expectations for the eigenvectors.
Más respuestas (1)
John D'Errico
el 15 de Nov. de 2024 a las 16:47
Editada: John D'Errico
el 15 de Nov. de 2024 a las 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]
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 comentario
John D'Errico
el 15 de Nov. de 2024 a las 16:51
Editada: John D'Errico
el 15 de Nov. de 2024 a las 16:55
Note that Answers is bugged as it often is lately, so symbolic results are not properly displayed.
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!