Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Factoring a symbolic polynomial

 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?

Factoring a symbolic polynomial

 

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)]))) 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μ

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

μ^3

However, this is not the simplification I desire. I want this: this: $$(a_1\lambda - \mu)(a_2\lambda - \mu)(a_3\lambda - \mu) \mu) - (u_1^2 + u_2^2 + u_3^2)\mu + (a_1 \mu_1^2 + a_2 u_2^2 u_2^2 + a_3 u_3^2)\lambda$$

Is there a way to obtain that sort of factorization?

Factoring a symbolic polynomial

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)])))

1)])))

U = Matrix([ [0, Matrix([[0, -uVars[2], uVars[1]], uVars[1]],
            [uVars[2], 0, -uVars[0]], -uVars[0]],
            [-uVars[1], uVars[0], 0] ])
a = Matrix([ [aVars[0], 0]])
a = Matrix([[aVars[0], 0, 0], 0],
            [0, aVars[1], 0], 0],
            [0, 0, aVars[2]] ])
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:

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?