Andrew Latham
Andrew Latham

Reputation: 6132

Solve Generalized Eigenvalue Problem in Numpy

I am looking to solve a problem of the type: Aw = xBw where x is a scalar (eigenvalue), w is an eigenvector, and A and B are symmetric, square numpy matrices of equal dimension. I should be able to find d x/w pairs if A and B are d x d. How would I solve this in numpy? I was looking in the Scipy docs and not finding anything like what I wanted.

Upvotes: 17

Views: 23874

Answers (2)

Saullo G. P. Castro
Saullo G. P. Castro

Reputation: 58985

For real symmetric or complex Hermitian dense matrices, you can use scipy.linalg.eigh() to solve a generalized eigenvalue problem. To avoid extracting all the eigenvalues you can specify only the desired ones by using subset_by_index:

from scipy.linalg import eigh

eigvals, eigvecs = eigh(A, B, eigvals_only=False, subset_by_index=[0, 1, 2])

One could use eigvals_only=True to obtain only the eigenvalues.

Upvotes: 20

RomanHotsiy
RomanHotsiy

Reputation: 5148

Have you seen scipy.linalg.eig? From the documentation:

Solve an ordinary or generalized eigenvalue problem of a square matrix.

This method have optional parameter b:

scipy.linalg.eig(a, b=None, ...
b : (M, M) array_like, optional
Right-hand side matrix in a generalized eigenvalue problem. 
          Default is None, identity matrix is assumed.

Upvotes: 14

Related Questions