# Matlab, Mathematica & LAPACK returning 3 different eigenvectors

(I'm not sure which of math.se / stackoverflow / scicomp.se is the right place to ask this question)

I have a C++ code which generates a complex matrix and then calculates its eigenvalues and eigenvectors using LAPACK zgeev. As an example this is one of those matrices: I wanted to test my code so I entered the same matrix in Matlab and Mathematica but I got two other different results! They all give the same eigenvalues but different eigenvectors. Here are my results from three programs. (Note that Matlab gives eigenvectors in column but the other two in rows and Matlab only shows 5 first digits so imaginary parts are shown 0 but I have entered them in the script)   What is going on?!

Seems that you have a duplicate eigenvalue. Thus, you have two eigenpairs $(\lambda_1, x_1)$ and $(\lambda_2, x_2)$ where $\lambda_1 = \lambda_2$. Denote $\lambda = \lambda_1 = \lambda_2$. Let $\alpha$ and $\beta$ be arbitrary complex numbers. Then $$A (\alpha x_1 + \beta x_2) = \alpha A x_1 + \beta A x_2 = \alpha \lambda x_1 + \beta \lambda x_2 = \lambda (\alpha x_1 + \beta x_2).$$ It hence seems that $(\lambda, \alpha x_1 + \beta x_2)$ is also an eigenpair for arbitrary numbers $\alpha$ and $\beta$!
There are two possible issues going on here. Firstly as noted in the answer by knl any linear combination of eigenvectors corresponding to degenerate eigenvalues is also an eigenvector, as shown in that answer. However even for the non-degenerate case eigenvectors may vary between different invocations of a diagonaliser even if the input matrix is the same. This is because there is an arbitrary random phase which the routine is free to "pick", and may vary from call to call. To see this consider the eigenvalue equation $${\bf A} {\bf q}=\lambda {\bf q}$$ Here $(\lambda,{\bf q})$ is clearly the eigenpair. Let's multiply this from the left with a diagonal matrix ${\bf D}$ where all the diagonal elements are the same and of the form $D_{ii}=e^{i\phi}$. Such matrices commute with any other matrix so it follows that $${\bf DAq}={\bf A(Dq)}=\lambda ({\bf Dq})$$ Then let ${\bf q^{'}={\bf Dq}}$ we can see that $${\bf q^{'}}^{\dagger} {\bf q^{'}}={\bf q^{\dagger}D^{\dagger}Dq}={\bf q^{\dagger}q}$$ because of the form of ${\bf D}$. Thus ${\bf q^{'}}$ is also an eignevector of ${\bf A}$, and further has the same normalisation, and thus is a perfectly valid result for (in your case) zheev to return whatever the value of $\phi$.
Because of this about the only good way to check an eigenvector is to make sure ${\bf q^{\dagger}Aq}=\lambda$ to whatever tolerance is acceptable; visual inspection og the elements doesn't work. Even in the real case there is still a factor of -1 that can be applied.