# Constructing matrix from eigenvalues, eigenvectors (Inconsistency with Matlab's eig())

Let $F_1$, $F_2$ be the foci points of an ellipse $\mathcal{E}\colon \mathbf{x}^TA\mathbf{x}=1$, $\mathbf{x}\in\mathbb{R}^2$, $A\in\mathbb{S}_{++}^{2}$. Let also $a$, $b$ be the semi-axes of $\mathcal{E}$. We would like to find the (symmetric positive-definite) matrix $A$.

I tried the following:

I first constructed the diagonal matrix $D=\operatorname{diag}\{a^{-2},b^{-2}\}$. Then I cunstructed the orthogonal matrix $U=[\mathbf{u}_1\:\:\mathbf{u}_2]$, where $\mathbf{u}_1=F_1F_2$ and $\mathbf{u}_2\perp\mathbf{u}_1$, specificaly $\mathbf{u}_2 = (-u_{12},u_{11})^T$.

Finally I got $A=UDU^T$. But when I use Matlab's eig() function to get again the eigenvalues and the eigenvectors, while I get correctly the eigenvalues, I get the opposite of the eigenvectors.

What is the error here? Thanks a lot!

• Do you mean "opposite sign"? If so, there's no error, since eigenvectors are unique only up to multiplication by scalars. In particular, if $Ax=\lambda x$, then $A(-x) = \lambda (-x)$. – Christian Clason Aug 7 '14 at 13:49
• Yes, this is what I mean. So, is there any way of getting the correct eigenvectors? – nullgeppetto Aug 7 '14 at 13:51
• Both are correct eigenvectors. If you want to have (say) $u_{11}\geq 0$, just multiply $u_1$ by $\mathsf{sign}(u_{11})$. – Christian Clason Aug 7 '14 at 13:53
• Thanks @ChristianClason, but isn't it significant which exactly are the eigenvectors? Since they determine a new basis... – nullgeppetto Aug 7 '14 at 13:55
• They're not really a new basis; just a rescaling of the same basis; they span exactly the same subspace (which is all eigenvectors care about). – Christian Clason Aug 7 '14 at 13:58

As indicated in several of the comments, if $\mathbf{v}$ is an eigenvector of $A$, then so is $\alpha\mathbf{v}$ for any $\alpha \ne 0$. Given an eigenvalue $\lambda$, there are thus infinitely many eigenvectors. Whatever solver you are using normalizes the eigenvectors, reducing this set to two possibilities; $\pm \mathbf{v}$ where $|\mathbf{v}|=1$. The solver has no way of knowing which of these two you want.
This raises the question, do you care which you get? In terms of specifying the ellipse, or spanning the relevant space, the answer is no. If $\{\mathbf{v}_i\}$ is the set of eigenvectors, then any combination of sign changes on these vectors, $\{\pm \mathbf{v}_i\}$, spans the same subspace and equivalently defines the same ellipse when you construct your matrix $A$ from them.
There are cases, however, in which it matters which you get. For example, if you wanted to obtain the angular velocity of the ellipse given a time-series of matrices $\{A_i\}$, you would do so using the eigenvectors of each $A_i$. The matrix whose columns are the eigenvectors of $A$ defines a rotation, and in this case taking the opposite eigenvector will give a different rotation (although symmetric with respect to the ellipse).