Ask Your Question

Simplifying symbolic characteristic polynomial

asked 2015-02-28 03:04:44 -0500

mforets gravatar image

updated 2015-02-28 05:40:09 -0500

I have a simple code,

sage: theta=var('theta')
sage: assume(theta,'real')
sage: M=matrix([[1,0],[cos(theta),-i*sin(theta)]])/sqrt(2)
sage: show(M)
sage: cp = characteristic_polynomial((M.conjugate_transpose())*M)
sage: show(cp)

When I type cp.[TAB], I get no options to .simplify() the expression, neither to solve it, and typing this solve(cp,x) gives an error. What is the problem?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-28 05:48:21 -0500

updated 2015-02-28 05:56:38 -0500

The matrix you define has coefficients in the Symbolic Ring.

sage: theta = SR.var('theta')
sage: assume(theta,'real')
sage: M = matrix([[1,0],[cos(theta),-i*sin(theta)]])/sqrt(2)
sage: M
[              1/2*sqrt(2)                         0]
[   1/2*sqrt(2)*cos(theta) -1/2*I*sqrt(2)*sin(theta)]
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring

The characteristic polynomial you compute has coefficients in the Symbolic Ring.

sage: cp = characteristic_polynomial((M.conjugate_transpose())*M)
sage: cp
x^2 + (-1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2)*x + 1/4*sin(theta)^2
sage: R = cp.parent()
sage: R
Univariate Polynomial Ring in x over Symbolic Ring

You can get the list of its coefficients:

sage: coeffs = cp.coefficients()
sage: coeffs
[1/4*sin(theta)^2, -1/2*cos(theta)^2 - 1/2*sin(theta)^2 - 1/2, 1]

You apply simplify_trig to each coefficient.

sage: simp_coeffs = [a.simplify_trig() for a in coeffs]
sage: simp_coeffs
[1/4*sin(theta)^2, -1, 1]

You can then transform the list back into a polynomial.

sage: R(simp_coeffs)
x^2 - x + 1/4*sin(theta)^2

Or you could define x as the generator of the polynomial ring over the Symbolic Ring and do this:

sage: x = polygen(SR)
sage: sum(a.simplify_trig()*x^k for k,a in enumerate(coeffs))
x^2 - x + 1/4*sin(theta)^2

All in one line from your definition of cp:

sage: cp.parent()([a.simplify_trig() for a in cp.coefficients()])
x^2 - x + 1/4*sin(theta)^2
edit flag offensive delete link more


great answer, thanks

mforets gravatar imagemforets ( 2015-03-07 12:03:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-02-28 03:04:44 -0500

Seen: 342 times

Last updated: Feb 28 '15