# How to check if a vector is an eigenvector of a matrix using mathematica?

Here is a vector

$$\begin{pmatrix}i\\7i\\-2\end{pmatrix}$$

Here is a matrix

$$\begin{pmatrix}2& i&0\\-i&1&1\\0 &1&0\end{pmatrix}$$

Is there a simple way to determine whether the vector is an eigenvector of this matrix?

Here is some code for your convenience.

h = {{2, I, 0 },
{-I, 1, 1},
{0, 1, 0}};

y = {I, 7 I, -2};

• Could also do h.y/y. Dividing by y divides element-wise, and so if it's an eigenvector, each element of the resulting vector should be the same (which is the eigenvalue). – march Nov 27 '17 at 19:24
• @march: Division by zero (not in this case, but in general)...? – Henrik Schumacher Nov 27 '17 at 19:32
• @HenrikSchumacher. Sure, it's not completely general, which is partly why I didn't write it as an answer. – march Nov 27 '17 at 19:33
• @march It's still a good idea. – Henrik Schumacher Nov 27 '17 at 19:35
• Solve the eigenvalue/vector equation: Solve[h.y == lambda*y, lambda]. It is an eigenvector iff solution set is nonempty. – Daniel Lichtblau Nov 27 '17 at 20:33

## 7 Answers

You could use MatrixRank. Here is a function that does this:

eigenvectorQ[matrix_, vector_] := MatrixRank[{matrix . vector, vector}] == 1


For your example:

eigenvectorQ[h, y]


False

• Slick... (and an upvote) – Daniel Lichtblau Nov 28 '17 at 16:31
• That is the right way – yarchik Nov 29 '17 at 7:26

For problems with exact coordinates, one could code up the definition of eigenvector. The function eigV finds the eigenvalue for a given vector in the form L == value or returns False if there is none; the function eigQ returns True if there exists an eigenvalue for

ClearAll[eigQ, eigV];
eigV[m_, v_] := Reduce@Thread[(m - SparseArray[{i_, i_} :> L, Dimensions[m]]).v == 0];
eigV[m_][v_] := eigV[m, v]; (* operator form *)
eigQ[m_, v_] := Resolve@Exists[L, eigV[m, v]];
eigQ[m_][v_] := eigQ[m, v]; (* operator form *)


Examples:

eigQ[h] /@ {y, {-I (-2 + Sqrt[3]), 1 - Sqrt[3], 1}}
(*  {False, True}  *)

eigV[h] /@ {y, {-I (-2 + Sqrt[3]), 1 - Sqrt[3], 1}}
(*  {False, L == 1 - Sqrt[3]}  *)


Or simply

eigQ[h, y]
(*  False  *)


For approximate problems, one would have to account for rounding error.

• Note: It's simpler to use Daniel Lichtblau's form for the equation: eigV[m_, v_] := Reduce[m.v == L*v] (brain spasm sent me on the roundabout way, I guess). – Michael E2 Nov 27 '17 at 22:20
• Why not just Resolve@Exists[α, #1.#2 == α #2] & @@ {h, y}? – aardvark2012 Nov 28 '17 at 3:21
• @aardvark2012 Fair enough. I had something like that at one point. But I was enamored with eigV; for some reason, it appealed to me. Maybe the eigenvalue as a certificate of proof, I suppose. – Michael E2 Nov 28 '17 at 3:46

You already have several good answers. An alternative is to use a Rayleigh quotient,

r = First[y.h.ConjugateTranspose[{y}]/Norm[y]];


The vector y is an eigenvector of h if and only if the matrix $$h-r1_{3\times3}$$ is singular:

MatrixRank[h - IdentityMatrix[Length[y]] R]<Length[y]
(*False*)


or

Det[h - IdentityMatrix[Length[y]] R] == 0
(*False*)


If you are using floating point numbers, you should change this condition into

MatrixRank[h - IdentityMatrix[Length[y]] R,Tolerance->epsilon]<Length[y]


or

Abs[Det[h - IdentityMatrix[Length[y]] R]] < epsilon


where epsilon is some small number.

As a matter of fact, the MatrixRank method is slightly faster than the Det one. It seems to me that it is also faster than the methods suggested by other users, but confirming this would require a more thorough analysis.

• For full masochistic effect you should have him calculate the determinant by cofactor expansion. ;) – Mehrdad Nov 29 '17 at 5:32

Yes! We just check whether $h.y = (u + I v) y$ holds for some real $u, v \in \mathbb{R}$.

h = {{2, I, 0}, {-I, 1, 1}, {0, 1, 0}};
y = {I, 7 I, -2};
expr = Norm[h.y - (u + I v) y, 2]^2 // ComplexExpand;
Minimize[expr, {u, v}]


{623/6, {u -> 17/18, v -> 0}}

Answer: Nope, it's not.

Either

Reduce[h . y == x * y, x]


or

Reduce[(h - IdentityMatrix[Length[h]] x) . y == 0, x]


depending on whether you would rather type $y$ once or twice.

MemberQ[myeigens = Normalize/@Eigenvectors[h], Normalize[y]]|| MemberQ[myeigens, -Normalize[y]]


(* False *)

• And what if you have eigenvalues with multiplicities? – Henrik Schumacher Nov 27 '17 at 19:30
• Won't you find the match in that case? – David G. Stork Nov 27 '17 at 19:45
• Not necessarily. The eigenspace to an eigenvalue with higher multiplicity may have dimension greater than 1 and Eigenvectors just picks a basis. So, it will likely happen that neither Normalize[y] nor -Normalize[y] coincides with one of the basis vectors. – Henrik Schumacher Nov 27 '17 at 19:50
• Here, a counter example: MemberQ[Eigenvectors[DiagonalMatrix[{1, 1}]], Normalize[{1, -1}] || -Normalize[{1, -1}]] – Henrik Schumacher Nov 27 '17 at 19:53
• @HenrikSchumacher: But the eigenvectors of DiagonalMatrix[{1,1}] are {1,0} and {0,1}, so of course your code will yield False. – David G. Stork Nov 27 '17 at 22:22

How about this:

eigenVectorQ[mat_, vec_] := Abs[Dot[#1\[Conjugate], #2]] == Norm[#1] Norm[#2] &[mat.vec, vec]


Then eigenVectorQ[h, y] returns False.