Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 986
Andrew Latham Avatar asked Jul 15 '14 07:07

Andrew Latham


People also ask

What is a Generalised eigenvalue problem?

The standard eigenvalue problem is defined by Ax = λx, where A is the given n by n matrix. The generalized eigenvalue problem is Ax = λBx where A and B are given n by n matrices and λ and x is wished to be determined. For historical reasons the pair A, B is called a pencil.

How do you find the generalized eigenvalue?

If A is an n × n matrix and λ is an eigenvalue with algebraic multiplicity k, then the set of generalized eigenvectors for λ consists of the nonzero elements of nullspace((A − λI)k). to find generalized eigenvector v2 = (0,1,0). 4. Finally, (A − I)3 = 0, so we get v3 = (1,0,0).

How do you solve eigen value problems?

If X is the non-trivial column vector solution of the matrix equation AX = λX, where λ is a scalar, then X is the eigenvector of matrix A and the corresponding value of λ is the eigenvalue of matrix A. Suppose the matrix equation is written as A X – λ X = 0. Let I be the n × n identity matrix. A X – λ I X = 0.


2 Answers

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.

like image 140
Saullo G. P. Castro Avatar answered Sep 23 '22 11:09

Saullo G. P. Castro


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.
like image 41
RomanHotsiy Avatar answered Sep 23 '22 11:09

RomanHotsiy