'How can I calculate the eigenvalues of a symbolic matrix in Python?

import sympy
p1, p2, p3 = sympy.symbols('p1, p2, p3')

A  = sympy.Matrix([(p1+p2+p3) + 5, p2, p3],[p1, (p1+p2+p3) + 8, p3],[p1, p2, (p1+p2+p3) + 8] )

print(A.eigenvals())

I get an error of the values not being integers. What is the proper way to calculate this?



Solution 1:[1]

You need another [ and ] inside the Matrix:

A  = Matrix([[(p1+p2+p3) + 5, p2, p3],[p1, (p1+p2+p3) + 8, p3],[p1, p2, (p1+p2+p3) + 8]])

will construct the matrix without raising an error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucas Roberts