0

I solved most of this assignment using Python, but not sure how to input (or even understand) the remaining information. Aren't you supposed to find the eigenvector given some eigenvalue, thus it appears in reverse in the following:

Let the symmetric 3 × 3 matrix A be A = ((1 2 1), (2 5 0), (1 0 5))

If A has the following three eigenvectors, then find three corresponding eigenvalues:
v1 = ((-5), (2), (1)); v2 = ((0), (-1), (2)); v3 = ((1), (2), (1))

martineau
  • 119,623
  • 25
  • 170
  • 301
Saurus
  • 79
  • 1
  • 7
  • This sounds like a math problem rather than a programming one. Why would you even need to write code to solve this? Each eigenvector has one eigenvalue, but each eigenvalue can have multiple eigenvectors (even normalized ones). Finding the eigenvalue to an eigenvector is a matter of calculating (part of) the product of the matrix with the vector. – walnut Jan 02 '20 at 19:38

2 Answers2

1

Think about the definition of an eigenvector. An eigenvector v of a linear transformation represented by matrix A is a vector that only changes in magnitude, not direction, when that linear transformation is applied to it. The scalar change in magnitude of the eigenvector is its eigenvalue. You have a linear transformation, and you've been given its eigenvectors - to find the eigenvalues, all you need to do is apply the transformation to the eigenvectors and determine by what scalar each eigenvector got scaled.

Mark Snyder
  • 1,635
  • 3
  • 12
1

Given a matrix arr and a vector vec, if vec is eigenvector of arr, then:

np.dot(arr, vec) == lambda_ * vec

therefore, going through all the values of np.dot(arr, vec) / vec (eventually ignoring the null vector as potential eigenvector, and suppressing errors for potential division by zero), would reveal the eigenvalue:

import numpy as np


def find_eigenvalue(arr, vec):
    result = None
    if not np.all(np.isclose(vec, 0.0)):
        with np.errstate(divide='ignore', invalid='ignore'):
            for x, y in zip(np.dot(arr, vec), vec):
                if np.isclose(y, 0.0) and np.isclose(x, 0.0):
                    continue
                if result is None:
                    result = x / y
                elif not np.isclose(result, x / y):
                    result = None
                    break
    return result

which works as expected:



print(find_eigenvalue(arr, np.array([0, 0, 0])))
# None
print(find_eigenvalue(arr, np.array([1, 0, 0])))
# None
print(find_eigenvalue(arr, np.array([0, 1, 0])))
# None
print(find_eigenvalue(arr, np.array([0, 0, 1])))
# None
print(find_eigenvalue(arr, np.array([0, -1, 2])))
# 5
print(find_eigenvalue(arr, np.array([-5, 2, 1])))
# -0.0
print(find_eigenvalue(arr, np.array([1, 2, 1])))
# 6.0

Finally, note that np.linalg.svd() will also compute all these:

u, s, vh = np.linalg.svd(arr)

and s will contain the eigenvalues, and u and vh will contain the eigenvectors (more precisely the left-singular eigenvectors in u and the hermitian of the right-singular eigenvectors in vh).

norok2
  • 25,683
  • 4
  • 73
  • 99