The two cases are mathematically different.
Case 1:
h = {
{e1, 2, x},
{2, 2, x},
{x, x, 2}
};
Eigenvalues[h, Cubics -> True] /. x -> 0
The value of x
is substituted after the Eigenvalues are computed. Mathematica computes assuming x
is not zero, along with other symbols, as maybe required for the algorithm.
Case 2:
h = {
{e1, 2, x},
{2, 2, x},
{x, x, 2}
};
x = 0;
Eigenvalues[h, Cubics -> True]
The matrix changes and is qualitatively different from that of Case 1.
However, the two results are the same. You are not able to see it because Mathematica is not able to Simplify the expression in Case 1. If you substitute some random value of e1
and check you will notice that the third element of Case 1 matches with the first element of Case 2 (which is the constant value 2).
Also, if you substitute some other value of x
your answers would match visibly.
A note of precaution in general (may not be applicable for this):
You should know the mathematical assumptions Mathematica takes into account in implementing its algorithm.
For example you may do Solve[y/x==0,y]
and get y=0
as the solution. However, Mathematica assumes that x
is not equal to 0
. So in this case if you were to substitute the value of x
after you solve it will still be y=0
. However, if you substitute before using Solve
you will get an error.
Edit:
As mentioned in the comment for this answer---The values of Case 1 may not correspond to the same index element in Case 2 always and depends on the value of e2
substituted. However, the three values would match. Also note that the CharacteristicPolynomial
for the two cases are the same.