ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 30 Oct 2019 11:04:37 -0500Plotting polynomials defined over a number fieldhttps://ask.sagemath.org/question/48557/plotting-polynomials-defined-over-a-number-field/I have an element of a polynomial ring over a number field K. It's a pretty benign number field -- I have just adjoined a square root of 3, called 't'.
I want to be able to plot the polynomial (specifically, it's a polynomial of two variables, and I want an implicit plot of where it vanishes). How do I get Sage to coerce 't' to a real number and draw the plot? Of course this should involve fixing an embedding of my number field into RR, but it's just a square root, so this shouldn't be hard.
For a minimal example:
var('w')
K.<t> = NumberField(w^2-3)
R = PolynomialRing(K,2,'x,y')
R.inject_variables()
f = y - t*x
implicit_plot(f,(x,-3,3),(y,-3,3))
It (quite understandably) chokes with "TypeError: Unable to coerce -t to a rational". I would like to coerce t to be the positive real square root of 3 and draw the plot.Wed, 30 Oct 2019 10:50:29 -0500https://ask.sagemath.org/question/48557/plotting-polynomials-defined-over-a-number-field/Answer by rburing for <p>I have an element of a polynomial ring over a number field K. It's a pretty benign number field -- I have just adjoined a square root of 3, called 't'.</p>
<p>I want to be able to plot the polynomial (specifically, it's a polynomial of two variables, and I want an implicit plot of where it vanishes). How do I get Sage to coerce 't' to a real number and draw the plot? Of course this should involve fixing an embedding of my number field into RR, but it's just a square root, so this shouldn't be hard.</p>
<p>For a minimal example:</p>
<pre><code>var('w')
K.<t> = NumberField(w^2-3)
R = PolynomialRing(K,2,'x,y')
R.inject_variables()
f = y - t*x
implicit_plot(f,(x,-3,3),(y,-3,3))
</code></pre>
<p>It (quite understandably) chokes with "TypeError: Unable to coerce -t to a rational". I would like to coerce t to be the positive real square root of 3 and draw the plot.</p>
https://ask.sagemath.org/question/48557/plotting-polynomials-defined-over-a-number-field/?answer=48558#post-id-48558You have the right idea: do `f.change_ring(R)` with the argument `R` set to one of `K.embeddings(RR)`:
var('w')
K.<t> = NumberField(w^2-3)
R.<x,y> = PolynomialRing(K)
f = y - t*x
implicit_plot(f.change_ring(K.embeddings(RR)[0]),(x,-3,3),(y,-3,3))
You might also like:
implicit_plot(f.change_ring(K.embeddings(RR)[0]),(x,-3,3),(y,-3,3), color='blue') + implicit_plot(f.change_ring(K.embeddings(RR)[1]),(x,-3,3),(y,-3,3), color='red')Wed, 30 Oct 2019 11:04:37 -0500https://ask.sagemath.org/question/48557/plotting-polynomials-defined-over-a-number-field/?answer=48558#post-id-48558