2
import numpy as np
import sympy as sp
from sympy import *
init_printing()

uVars    = list(symbols(', '.join([f'u{n}' for n in range(1, 3 + 1)])))
aVars    = list(symbols(', '.join([f'a{n}' for n in range(1, 3 + 1)])))
lambda1, mu = symbols('lambda, mu')

U = np.array([ [0, -uVars[2], uVars[1]], [uVars[2], 0, -uVars[0]], [-uVars[1], uVars[0], 0] ])
a = np.array([ [aVars[0], 0, 0], [0, aVars[1], 0], [0, 0, aVars[2]] ])

I = np.eye(3)
L = a*lambda1 + U

preCharPoly = L - mu*I
preCharPoly_sym = sp.Matrix(preCharPoly)

factor(preCharPoly_sym.det())

The above code outputs the following polynomial:

enter image description here

However, I require the polynomial to be factored with respect to the variables lambda and mu as shown here: enter image description here

I have been examining the documentation at https://docs.sympy.org/latest/modules/simplify/simplify.html but cannot figure out how to do what is desired. How do I specify factor() or simplify() to perform their tasks with respect to lambda and mu?

KZ-Spectra
  • 139
  • 4
  • I think the answer is you looking for is [here](https://stackoverflow.com/questions/15401376/python-lambda-function-to-calculate-factorial-of-a-number) – Alihan ÖZ Jun 25 '20 at 09:47

0 Answers0