I want to calculate the eigensystem of a real matrix, and then extract the real eigenvectors and eigenvalues, if such terms exist. However, I cannot know whether such a situation exists in advance, so it must be determined in real time based on the actual calculation results.
For example, see the following calculations:
In[7]:= gen1={{-1,2,-1},{-(3/2),3/2,-(1/2)},{-(1/2),3/2,-(3/2)}};
{val, vec}=Eigensystem[%,Cubics -> True]//ComplexExpand
gen2={
{0,0,0,-1},
{1,0,0,0},
{0,-1,0,0},
{0,0,-1,0}
};
{val, vec}=gen2//Eigensystem[#,Cubics -> True]&//ComplexExpand
Out[8]= {{-1,
I, -I}, {{1/2, 1/2, 1}, {3/2 - I/2, 3/2 + I/2, 1}, {3/2 + I/2,
3/2 - I/2, 1}}}
Out[10]= {{-((1 + I)/Sqrt[2]), (1 + I)/Sqrt[2], -((1 - I)/Sqrt[2]), (
1 - I)/Sqrt[
2]}, {{(1 - I)/Sqrt[2], I, (1 + I)/Sqrt[2], 1}, {-((1 - I)/Sqrt[2]),
I, -((1 + I)/Sqrt[2]), 1}, {(1 + I)/Sqrt[2], -I, (1 - I)/Sqrt[2],
1}, {-((1 + I)/Sqrt[2]), -I, -((1 - I)/Sqrt[2]), 1}}}
As you can see, in the first example, there are real eigenvalues and eigenvectors, but in the second example, there is no such result.