Factoring a symbolic polynomial

asked 2020-06-25 07:48:56 +0200

Nalt gravatar image

updated 2020-07-03 00:27:06 +0200

slelievre gravatar image

The following code:

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)

computes a characteristic polynomial and yields:

a1*a2*a3*λ^3 - a1*a2*λ^2*μ - a1*a3*λ^2*μ - a2*a3*λ^2*μ
+ a1*u1^2*λ + a2*u2^2*λ + a3*u3^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?

edit retag flag offensive close merge delete

Comments

1

I don't think there is an easy way to achieve this. Even Mathematica doesn't know what to do with this expression (If you have it installed, you can try with charPoly._mathematica_().Factor()._sage_(), but you need to use plain text variables). Sometimes it is a bit more powerful than Maxima, but not in this case.

Florentin Jaffredo gravatar imageFlorentin Jaffredo ( 2020-07-03 13:43:45 +0200 )edit