Ask Your Question
2

plots of complex numbers

asked 2018-01-28 23:20:47 +0100

Boston gravatar image

updated 2018-01-29 00:38:06 +0100

tmonteil gravatar image

Say I want to plot the 6 solutions of the following complex equation.

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])
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
3

answered 2018-01-29 00:06:47 +0100

tmonteil gravatar image

updated 2018-01-29 00:26:16 +0100

The 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

edit flag offensive delete link more
3

answered 2018-01-29 08:11:12 +0100

Sébastien gravatar image

updated 2018-01-29 08:14:34 +0100

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:

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

edit flag offensive delete link more

Comments

Note 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

tmonteil gravatar imagetmonteil ( 2018-01-29 18:16:20 +0100 )edit

Yes, 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)
Sébastien gravatar imageSébastien ( 2018-01-29 18:23:58 +0100 )edit
1

answered 2018-01-29 00:29:35 +0100

dan_fulea gravatar image

One 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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-28 23:20:47 +0100

Seen: 3,939 times

Last updated: Jan 29 '18