ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Jan 2015 10:32:41 +0100Solving polynomial equations with arbitrary coefficientshttps://ask.sagemath.org/question/25560/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. Mon, 19 Jan 2015 21:14:40 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/Comment by kcrisman for <p>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}.</p>
<p>How does this happen? </p>
<hr/>
<p>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. </p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25562#post-id-25562I'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.Mon, 19 Jan 2015 21:28:36 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25562#post-id-25562Answer by vdelecroix for <p>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}.</p>
<p>How does this happen? </p>
<hr/>
<p>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. </p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?answer=25563#post-id-25563Hello,
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).
VincentMon, 19 Jan 2015 21:58:16 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?answer=25563#post-id-25563Comment by tmonteil for <p>Hello,</p>
<p>Here is what I get</p>
<pre><code>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)]
</code></pre>
<p>For the last step, note that you can also do</p>
<pre><code>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)]
</code></pre>
<p>But you will not obtain this expression through factor (whose signification is somehow ambiguous).</p>
<p>Vincent</p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25591#post-id-25591Which error did you get ? The `assume` function does exist.Wed, 21 Jan 2015 10:32:41 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25591#post-id-25591Comment by rws for <p>Hello,</p>
<p>Here is what I get</p>
<pre><code>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)]
</code></pre>
<p>For the last step, note that you can also do</p>
<pre><code>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)]
</code></pre>
<p>But you will not obtain this expression through factor (whose signification is somehow ambiguous).</p>
<p>Vincent</p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25570#post-id-25570Have you tried `assume(a,'integer')`?Tue, 20 Jan 2015 10:24:27 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25570#post-id-25570Comment by Phoenix for <p>Hello,</p>
<p>Here is what I get</p>
<pre><code>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)]
</code></pre>
<p>For the last step, note that you can also do</p>
<pre><code>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)]
</code></pre>
<p>But you will not obtain this expression through factor (whose signification is somehow ambiguous).</p>
<p>Vincent</p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25567#post-id-25567@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 *I*m)/k); w^k . for $m$ being an integer, w^k = 1. But sage doesn't understand that.Tue, 20 Jan 2015 05:00:57 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25567#post-id-25567Comment by Phoenix for <p>Hello,</p>
<p>Here is what I get</p>
<pre><code>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)]
</code></pre>
<p>For the last step, note that you can also do</p>
<pre><code>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)]
</code></pre>
<p>But you will not obtain this expression through factor (whose signification is somehow ambiguous).</p>
<p>Vincent</p>
https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25583#post-id-25583There 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?Wed, 21 Jan 2015 02:32:04 +0100https://ask.sagemath.org/question/25560/solving-polynomial-equations-with-arbitrary-coefficients/?comment=25583#post-id-25583