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

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

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

    Continue reading...

Compartilhe esta Página