Katwre
Katwre

Reputation: 21

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?

Upvotes: 0

Views: 592

Answers (1)

Lucas Roberts
Lucas Roberts

Reputation: 1343

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.

Upvotes: 1

Related Questions