# Solving polynomial equations with arbitrary coefficients

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 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.

Sort by » oldest newest most voted

Hello,

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

Vincent

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.

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?

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