Ask Your Question

Solving polynomial equations with arbitrary coefficients

asked 2015-01-19 21:14:40 +0200

Phoenix gravatar image

This is my first time with Sage and no where on the documentation do I see how to solve a polynomial equation (say a quadratic) with arbitrary complex coefficients. Say I want to solve "x^2 - 7ax + (5+2I)" for x when a \in \mathbb{C}.

How does this happen?

I tried declaring "a" as a complex number using var('a', domain = CC) but that too didn't work. I am using ".factor()" to factorize.

edit retag flag offensive close merge delete


I'm not sure this is supported. Note that at least in some cases (maybe not yours) for some a there would only be one (double point) solution.

kcrisman gravatar imagekcrisman ( 2015-01-19 21:28:36 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-19 21:58:16 +0200

vdelecroix gravatar image


Here is what I get

sage: a, x= var('a,x')
sage: p = x^2 - 7*a*x + 5+2*I
sage: (p == 0).solve([x])
[x == 7/2*a - 1/2*sqrt(49*a^2 - 8*I - 20), x == 7/2*a + 1/2*sqrt(49*a^2 - 8*I - 20)]

For the last step, note that you can also do

sage: solve(p == 0, [x])
[x == 7/2*a - 1/2*sqrt(49*a^2 - 8*I - 20), x == 7/2*a + 1/2*sqrt(49*a^2 - 8*I - 20)]

But you will not obtain this expression through factor (whose signification is somehow ambiguous).


edit flag offensive delete link more


@Vincent Thanks! But is there anyway to make sage understand if "a" is an integer? Like the following doesn't work, m,k= var('m,k') and then saying w = exp( (2 pi *Im)/k); w^k . for $m$ being an integer, w^k = 1. But sage doesn't understand that.

Phoenix gravatar imagePhoenix ( 2015-01-20 05:00:57 +0200 )edit

Have you tried assume(a,'integer')?

rws gravatar imagerws ( 2015-01-20 10:24:27 +0200 )edit

There is no such feature called "assume". I am getting an error! Any way to declare a few variables as integers and then to do all the manipulations?

Phoenix gravatar imagePhoenix ( 2015-01-21 02:32:04 +0200 )edit

Which error did you get ? The assume function does exist.

tmonteil gravatar imagetmonteil ( 2015-01-21 10:32:41 +0200 )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


Asked: 2015-01-19 21:14:40 +0200

Seen: 758 times

Last updated: Jan 19 '15