Saurus
Saurus

Reputation: 79

Finding corresponding eigenvalues to a set of eigenvector

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))

Upvotes: 0

Views: 504

Answers (2)

norok2
norok2

Reputation: 26886

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).

Upvotes: 1

Mark Snyder
Mark Snyder

Reputation: 1655

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.

Upvotes: 1

Related Questions