A vector v is an eigenvector of A with eigenvalue λ exactly when multiplying A by v is the same as multiplying v by the scalar λ. In code, you just need to check whether Av equals λv (up to any tolerance if using floats).
1. Background Knowledge
- An eigenvector of a matrix A is a nonzero vector v such that applying the linear transformation A to v only scales it, not change its direction:
Av=λv.
Here, λ is the corresponding eigenvalue.
-
If you write A as an m×n matrix and v as an n×1 vector, then Av is just standard matrix–vector multiplication. The equation A\mathbf{v}=\lambdav is a vector equality: all components must match.
-
In this problem, you are not asked to find eigenvalues or eigenvectors; you are given A, v, and λ, and you only need to verify whether the eigenvector relationship holds.
2. Algorithm / Approach
Conceptual approach:
- Compute the matrix–vector product u=Av.
- Compute the scaled vector w=\lambdav.
- Compare u and w entry by entry:
- If they are equal (or within a small tolerance for floating-point), then v is an eigenvector with eigenvalue λ.
- Otherwise, it is not.
If the problem uses integers and exact equality, you can use a simple equality check. If it uses floats, use a small tolerance (e.g., check that the absolute difference of each component is less than some epsilon).
3. Step-by-Step Strategy
- Read inputs
- Matrix A of size n×n (or possibly m×n).
- Vector v of size n.
- Scalar λ.
- Compute Av
For each row i of A:
ui=j=1∑nAij⋅vj
Store results in array u.
- Compute λv
For each index i:
wi=λ⋅vi
Store results in array w.
- Compare vectors
- For each index i, check if u[i] equals w[i].
- If using floats, check abs(u[i] - w[i]) <= eps for some small eps, e.g. 1e-6.
- Return / print result
- If all components match, output something like "True" / 1 / "YES" depending on the platform.
- Otherwise, output "False" / 0 / "NO".
Example skeleton (Python-like pseudocode):
def is_eigenvector(A, v, lam, eps=1e-9):
n = len(v)
# compute A v
u = [0.0] * n
for i in range(n):
for j in range(n):
u[i] += A[i][j] * v[j]
# compute λ v
w = [lam * v[i] for i in range(n)]
# compare
for i in range(n):
if abs(u[i] - w[i]) > eps:
return False
return True
4. Common Pitfalls
-
Forgetting nonzero condition: By definition, an eigenvector must be nonzero. Some problems implicitly assume the given vector is nonzero; check the statement. If not, you may need to treat the zero vector as “not an eigenvector.”
-
Dimension mismatch: Ensure the length of v matches the number of columns of A. Otherwise, Av is not defined.
-
Floating-point precision:
-
Using exact equality (==) with floats can fail due to rounding.
-
Prefer comparing with a small tolerance eps.
-
Confusing direction vs. value: Av must equal λv component-wise. It is not enough that they just “look proportional” unless you explicitly compute λv and compare.
5. Time & Space Complexity
-
Time complexity
-
Computing Av takes O(n2) for an n×n matrix.
-
Computing λv takes O(n).
-
Comparing vectors takes O(n).
-
Overall: O(n2).
-
Space complexity
-
You need space for vectors u and w, each of size n.
-
Overall auxiliary space: O(n) (besides the input storage).