Re: [sage-support] Plot the zeros of a complex function

156 views
Skip to first unread message

William Stein

unread,
Jun 10, 2013, 11:02:12 AM6/10/13
to sage-s...@googlegroups.com
On Sun, Jun 9, 2013 at 3:25 PM, <computati...@gmail.com> wrote:
> Suppose I have a complex function f(z) with a continuous family of zeros (e.g., f(z)=z-|z|)
>
> Is there a way to easily plot the set of zeros of f in sage, regardless of how complicated the function f is?
>

You might find complex_plot useful. For example, for

f(z) = z - abs(z)
complex_plot(f, (-3,3), (-3,3))

you'll see a *black line* at the zero set of f(z).

In the notebook you mind find an interact like this useful:


z = var('z')
@interact
def _(f = z-abs(z), B=(2..10)):
show(complex_plot(f, (-B,B), (-B,B)))

Or just click on

http://sagecell.sagemath.org/?q=cdcdd7e5-73b4-4c87-87e2-1be300f86674

> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

computati...@gmail.com

unread,
Jun 10, 2013, 12:09:43 PM6/10/13
to sage-s...@googlegroups.com
Thanks, this is exactly what I was looking for!

In fact, I had tried out complex_plot but I must have been using a different color function or something, because the roots were much less apparent to me. Not sure why I couldn't figure this out on my own...

I suppose I have two follow-up questions now:
1. how can I improve the precision of the zero set (it seems to be drawn in low resolution right now)
2. what is the best way to "turn off" the other colors (draw non-zeros as white)

William Stein

unread,
Jun 10, 2013, 12:13:41 PM6/10/13
to sage-s...@googlegroups.com
On Mon, Jun 10, 2013 at 9:09 AM, <computati...@gmail.com> wrote:
> Thanks, this is exactly what I was looking for!
>
> In fact, I had tried out complex_plot but I must have been using a different
> color function or something, because the roots were much less apparent to
> me. Not sure why I couldn't figure this out on my own...
>
> I suppose I have two follow-up questions now:
> 1. how can I improve the precision of the zero set (it seems to be drawn in
> low resolution right now)

Use plot_points:

f(z) = z - abs(z)
complex_plot(f, (-3,3), (-3,3), plot_points=200)

> 2. what is the best way to "turn off" the other colors (draw non-zeros as
> white)

I don't know if this is possible or implemented at present.

computati...@gmail.com

unread,
Jun 10, 2013, 12:24:51 PM6/10/13
to sage-s...@googlegroups.com
Ah, that's unfortunate. Might be a fun summer project to try to implement, if I knew where to start.

On another note: I really like the @interact annotation. I'm messing around with it, because I would like to add another parameter to my plot - an integer representing an index in a discrete family of functions. But I keep getting python errors about my expression not being symbolic when I try to include an integer parameter (like n = var('n'), then passing in n=2). Any tips?

William Stein

unread,
Jun 10, 2013, 12:33:01 PM6/10/13
to sage-s...@googlegroups.com
On Mon, Jun 10, 2013 at 9:24 AM, <computati...@gmail.com> wrote:
> Ah, that's unfortunate. Might be a fun summer project to try to implement,
> if I knew where to start.

1. http://www.sagemath.org/development.html

2. SAGE_ROOT/devel/sage/sage/plot/complex_plot.pyx which I found by
doing search_src('complex_plot')

> On another note: I really like the @interact annotation. I'm messing around
> with it, because I would like to add another parameter to my plot - an
> integer representing an index in a discrete family of functions. But I keep
> getting python errors about my expression not being symbolic when I try to
> include an integer parameter (like n = var('n'), then passing in n=2). Any
> tips?

Just put

n = 2

instead? You have to post code for a more useful answer....

computati...@gmail.com

unread,
Jun 10, 2013, 12:42:05 PM6/10/13
to sage-s...@googlegroups.com
Okay, so the following works:


z = var('z')
n = 2
@interact
def _(f = ((z+1)^n-abs(z^n+1)), B=(2..10)):
    show(complex_plot(f, (-B,B), (-B,B)))

But the following doesn't:


z = var('z')

@interact
def _(f = ((z+1)^n-abs(z^n+1)), n = (2..10), B=(2..10)):
    show(complex_plot(f, (-B,B), (-B,B)))

William Stein

unread,
Jun 10, 2013, 12:55:28 PM6/10/13
to sage-s...@googlegroups.com
Try this:

z,n = var('z,n')

@interact
def _(f = ((z+1)^n-abs(z^n+1)), n = (2..10), B=(2..10)):
f = f.subs(n=n)
show(f)
show(complex_plot(f, (-B,B), (-B,B)))

computati...@gmail.com

unread,
Jun 10, 2013, 1:02:14 PM6/10/13
to sage-s...@googlegroups.com
Looks great, thanks for all the help!
I'll see about messing around with complex_plot a bit to support pure zero plots, if it amounts to something I'll get back in touch...
Reply all
Reply to author
Forward
0 new messages