Factoring a polynomial with respect to specific terms

Viewed 76
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?

0 Answers
Related