Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the eigenvalues and eigenvectors of a matrix with SymPy?

Tags:

People also ask

How do you find the eigenvalues of a matrix in Sympy?

To find the eigenvalues of a matrix, use eigenvals . eigenvals returns a dictionary of eigenvalue: algebraic_multiplicity pairs (similar to the output of roots).

How do you find the eigenvalues and eigenvectors of a matrix?

Consider a square matrix n × n. 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.

How do you define a matrix in Sympy?

Matrix is created from appropriately sized List objects. You can also obtain a matrix by distributing list items in specified number of rows and columns. Matrix is a mutable object. The matrices module also provides ImmutableMatrix class for obtaining immutable matrix.


I want to calculate the eigenvectors x from a system A by using this: A x = λ x

The problem is that I don't know how to solve the eigenvalues by using SymPy. Here is my code. I want to get some values for x1 and x2 from matrix A

from sympy import *
x1, x2, Lambda = symbols('x1 x2 Lambda')
I = eye(2)
A = Matrix([[0, 2], [1, -3]])
equation = Eq(det(Lambda*I-A), 0)
D = solve(equation)
print([N(element, 4) for element in D]) # Eigenvalus in decimal form
print(pretty(D)) # Eigenvalues in exact form

X = Matrix([[x1], [x2]]) # Eigenvectors
T = A*X - D[0]*X # The Ax = %Lambda X with the first %Lambda = D[0]
print(pretty(solve(T, x1, x2)))