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.Mon, 29 Jan 2018 18:23:58 +0100plots of complex numbershttps://ask.sagemath.org/question/40831/plots-of-complex-numbers/Say I want to plot the 6 solutions of [the following complex equation](https://sagecell.sagemath.org/?z=eJwrSyzSUK9S1-TlKs7PKS3JzM8rVlCwVQByylIVNKrizGxtdS10FKqACtLyixQyFTLzFIoS89JTNQx0zDSteLkUgKA4I79cA64_OjNWEwBzHBo2&lang=sage).
What is the best practice?
**EDIT** by @tmonteil: to lower dependency between Sage services in the long term, here is the code provided in the sagecell:
var('z')
solutions = solve (z^6==-8, z)
for i in range(0,6):
show(solutions[i])Sun, 28 Jan 2018 23:20:47 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/Answer by dan_fulea for <p>Say I want to plot the 6 solutions of <a href="https://sagecell.sagemath.org/?z=eJwrSyzSUK9S1-TlKs7PKS3JzM8rVlCwVQByylIVNKrizGxtdS10FKqACtLyixQyFTLzFIoS89JTNQx0zDSteLkUgKA4I79cA64_OjNWEwBzHBo2&lang=sage">the following complex equation</a>.</p>
<p>What is the best practice?</p>
<p><strong>EDIT</strong> by <a href="/users/1305/tmonteil/">@tmonteil</a>: to lower dependency between Sage services in the long term, here is the code provided in the sagecell:</p>
<pre><code>var('z')
solutions = solve (z^6==-8, z)
for i in range(0,6):
show(solutions[i])
</code></pre>
https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40835#post-id-40835One possibility is:
sage: var( 'z' );
sage: f = z^6 + 8
sage: list_plot( f.roots(multiplicities=False, ring=CC) )
Launched png viewer for Graphics object consisting of 1 graphics primitive
Mon, 29 Jan 2018 00:29:35 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40835#post-id-40835Answer by tmonteil for <p>Say I want to plot the 6 solutions of <a href="https://sagecell.sagemath.org/?z=eJwrSyzSUK9S1-TlKs7PKS3JzM8rVlCwVQByylIVNKrizGxtdS10FKqACtLyixQyFTLzFIoS89JTNQx0zDSteLkUgKA4I79cA64_OjNWEwBzHBo2&lang=sage">the following complex equation</a>.</p>
<p>What is the best practice?</p>
<p><strong>EDIT</strong> by <a href="/users/1305/tmonteil/">@tmonteil</a>: to lower dependency between Sage services in the long term, here is the code provided in the sagecell:</p>
<pre><code>var('z')
solutions = solve (z^6==-8, z)
for i in range(0,6):
show(solutions[i])
</code></pre>
https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40834#post-id-40834The way you solved the equation is such that the solutions are symbolic expressions. It is hard to ask Sage to plot a symbolic expression (unless it represents a function, in which case it will plot its graph).
If the complex numbers are floating-point (e.g. elements of `CDF`), then plotting the is easily, thanks to the `points` function:
sage: points([CDF(1+I), CDF(-I), CDF(-2)])
Now, regarding your concrete example, the solutions are given as symbolic expressions representing equalities:
sage: solutions
[z == 1/2*I*sqrt(3)*sqrt(2)*(-1)^(1/6) + 1/2*sqrt(2)*(-1)^(1/6), z == 1/2*I*sqrt(3)*sqrt(2)*(-1)^(1/6) - 1/2*sqrt(2)*(-1)^(1/6), z == -sqrt(2)*(-1)^(1/6), z == -1/2*I*sqrt(3)*sqrt(2)*(-1)^(1/6) - 1/2*sqrt(2)*(-1)^(1/6), z == -1/2*I*sqrt(3)*sqrt(2)*(-1)^(1/6) + 1/2*sqrt(2)*(-1)^(1/6), z == sqrt(2)*(-1)^(1/6)]
So, what you want is to use their right hand side (use the `rhs` method) and turn them into elements of `CDF`, so that you can plot them with the `points` function.
Also, you can notice that when you want to iterate over the elements of a list `L`, you do not need to use the indexing of the elements, so, instead of typing:
for i in range(len(L)):
blah L[i]
You can do:
for l in L:
blah l
In short, you just have to type:
sage: points([CDF(s.rhs()) for s in solutions])
If you want a regular hexagon, you can require the x and y axes to have the same scale with the `aspect_ratio` option:
sage: points([CDF(s.rhs()) for s in solutions], aspect_ratio=1)
Note also that plots are Sage objects that can be added with eachother, e.g.
sage: points([CDF(s.rhs()) for s in solutions], aspect_ratio=1) + circle((0,0), CDF(8^(1/6)), color='red')
See: [this Sage cell](https://sagecell.sagemath.org/?z=eJw9jkEKwjAURPeCd5hdfjBquyndZKV4CbESYsRAScr_sYuc3nTj8g3zhlkdk6pK73eS52-JOQlg0WANoDoN1h5Hg9oKS46pCN0v1xvJiT9CWuOdGYKY8NcfBk6W4MuTXQtsr3GAj-znQNSZThtsC-NE_XnQjXyeM1vF4bXd-AHLPith&lang=sage)Mon, 29 Jan 2018 00:06:47 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40834#post-id-40834Answer by Sébastien for <p>Say I want to plot the 6 solutions of <a href="https://sagecell.sagemath.org/?z=eJwrSyzSUK9S1-TlKs7PKS3JzM8rVlCwVQByylIVNKrizGxtdS10FKqACtLyixQyFTLzFIoS89JTNQx0zDSteLkUgKA4I79cA64_OjNWEwBzHBo2&lang=sage">the following complex equation</a>.</p>
<p>What is the best practice?</p>
<p><strong>EDIT</strong> by <a href="/users/1305/tmonteil/">@tmonteil</a>: to lower dependency between Sage services in the long term, here is the code provided in the sagecell:</p>
<pre><code>var('z')
solutions = solve (z^6==-8, z)
for i in range(0,6):
show(solutions[i])
</code></pre>
https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40837#post-id-40837You may also draw a complex plot (black dots are the zeroes, red means real numbers or close to, and other rainbow colors means other argument, more white means high modulus:
sage: var('z')
z
sage: complex_plot(z^6 + 8, (-2,2), (-2,2), aspect_ratio=1)
Launched png viewer for Graphics object consisting of 1 graphics primitive
![image description](/upfiles/1517210052105545.png)Mon, 29 Jan 2018 08:11:12 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?answer=40837#post-id-40837Comment by Sébastien for <p>You may also draw a complex plot (black dots are the zeroes, red means real numbers or close to, and other rainbow colors means other argument, more white means high modulus:</p>
<pre><code>sage: var('z')
z
sage: complex_plot(z^6 + 8, (-2,2), (-2,2), aspect_ratio=1)
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
<p><img alt="image description" src="/upfiles/1517210052105545.png"></p>
https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?comment=40859#post-id-40859Yes, this is what I meant: postive real is red. The best way to confirm the meaning of colors is to plot the identity map:
sage: var('z'); complex_plot(z, (-2,2), (-2,2), aspect_ratio=1)Mon, 29 Jan 2018 18:23:58 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?comment=40859#post-id-40859Comment by tmonteil for <p>You may also draw a complex plot (black dots are the zeroes, red means real numbers or close to, and other rainbow colors means other argument, more white means high modulus:</p>
<pre><code>sage: var('z')
z
sage: complex_plot(z^6 + 8, (-2,2), (-2,2), aspect_ratio=1)
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
<p><img alt="image description" src="/upfiles/1517210052105545.png"></p>
https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?comment=40856#post-id-40856Note that this is not completely true: the red is more the positive reals, not the reals, since `z^6 + 8` and `z^6` are real for the same values of `z`, the real values of the function should be 12 rays emanating from 0, not only the 6 we can guess on the picture, see:
sage: I = CDF.gen()
sage: implicit_plot(lambda x,y : imag((x+I*y)^6+8), (-2,2), (-2,2), aspect_ratio=1)
See [this cell](http://sagecell.sagemath.org/?z=eJzzVLBVcHZx00tPzdPQ5OXKzC3IyUzOLIkvyMkv0chJzE1KSVSo0KlUsFLIzE1M19Co0PbUqtSMM9O20NRR0NA10jFCohOLC1KTS-KLEksy820NNQHkxhp4&lang=sage)Mon, 29 Jan 2018 18:16:20 +0100https://ask.sagemath.org/question/40831/plots-of-complex-numbers/?comment=40856#post-id-40856