llambda, mu = var('λ, μ')
uVars = list(var(', '.join([f'u{n}' for n in range(1, 3 + 1)])))
aVars = list(var(', '.join([f'a{n}' for n in range(1, 3 + 1)])))
U = Matrix([ [0, -uVars[2], uVars[1]], [uVars[2], 0, -uVars[0]], [-uVars[1], uVars[0], 0] ])
a = Matrix([ [aVars[0], 0, 0], [0, aVars[1], 0], [0, 0, aVars[2]] ])
I = matrix.identity(3)
L = a*llambda + U
# Characteristic polynomial
charPoly = det((L - mu*I))
factor(charPoly)
The above code computes a characteristic polynomial and yields:
a1a2a3λ^3 - a1a2λ^2μ - a1a3λ^2μ - a2a3λ^2μ + a1u1^2λ + a2u2^2λ + a3u3^2λ + a1λμ^2 + a2λμ^2 + a3λμ^2 - u1^2μ - u2^2μ - u3^2*μ - μ^3
However, this is not the simplification I desire. I want this: $$(a_1\lambda - \mu)(a_2\lambda - \mu)(a_3\lambda - \mu) - (u_1^2 + u_2^2 + u_3^2)\mu + (a_1 \mu_1^2 + a_2 u_2^2 + a_3 u_3^2)\lambda$$
Is there a way to obtain that sort of factorization?