[sage-support] Re: Plotting x^x
On Wed, May 21, 2008 at 11:45 AM, mark mcclure <[EMAIL PROTECTED]> wrote: > > On May 21, 1:07 pm, "William Stein" <[EMAIL PROTECTED]> wrote: > >> Since I know a bit more about how to optimize code in Sage, >> I redid your function but using more tricks. The result draws >> the above in 0.09 seconds (yep!). > > And Marshall wrote: >> Arg, you beat me to it. I have a solution that takes about twice as >> long as yours; I didn't you could use _fast_float_ like that: > > Hey thanks guys! Maybe, I'll learn these little tricks sometime, too. > > Mark Much better would be for Sage to improve so these tricks aren't needed. I see that happening :-) William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
On May 21, 1:07 pm, "William Stein" <[EMAIL PROTECTED]> wrote: > Since I know a bit more about how to optimize code in Sage, > I redid your function but using more tricks. The result draws > the above in 0.09 seconds (yep!). And Marshall wrote: > Arg, you beat me to it. I have a solution that takes about twice as > long as yours; I didn't you could use _fast_float_ like that: Hey thanks guys! Maybe, I'll learn these little tricks sometime, too. Mark --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
Arg, you beat me to it. I have a solution that takes about twice as long as yours; I didn't you could use _fast_float_ like that: import math mypi = float(pi) def f(x,k): if x > 0: tz = math.exp(x*(math.log(x))) return[x,tz*math.cos(2*mypi*k*x),tz*math.sin(2*mypi*k*x)] if x < 0: tz = math.exp(x*(math.log(-x))) return[x,tz*math.cos(mypi*(2*k+1)*x),tz*math.sin(mypi*(2*k +1)*x)] else: return [0, 1, 0] dx = float(0.02) pic = line([[0,1,0],[0,1,0]]); for k in srange(-3,4,float(1)): pts = [f(x,k) for x in srange(-4.0,2.0,dx)] pic = pic + line3d(pts) -M. Hampton On May 21, 12:07 pm, "William Stein" <[EMAIL PROTECTED]> wrote: > On Wed, May 21, 2008 at 9:18 AM, mark mcclure <[EMAIL PROTECTED]> wrote: > > > On May 16, 2:44 am, Dan Pillone <[EMAIL PROTECTED]> wrote: > > >> Is there a way to plot x^x correctly? > > > A lovely article by Mark Meyerson entitled "The x^x Spindle" > > appeared in Mathematics Magazine back in June of 96. The > > article shows how to interpret the graph of x^x in 3-space, > > using the complex values of x^x. This may be plotted in > > sage as follows: > > > def f(x,k): > >if x != 0: > >z = exp(x*(maxima.log(x) + 2*I*pi*k)) > >return [x, real(z), imag(z)] > >else: > >return [0, 1, 0] > > dx = 0.02 > > pic = line([[0,1,0],[0,1,0]]); > > for k in range(-3,4): > >points = [f(x*dx,k) for x in range(-4/dx,2/dx)] > >pic = pic + line(points) > > pic.show(frame_aspect_ratio=[2,1,1], figsize=8) > > > The above commands take *way* too long, presumably due to the > > repeated calls to maxima's complex log function. Sage's log > > function doesn't work. I was able to perform the loop in > > maxima, but I was unable to get the result back into sage for > > plotting. > > > The result is quite nice, though. There are countably many > > Yep. > > Since I know a bit more about how to optimize code in Sage, > I redid your function but using more tricks. The result draws > the above in 0.09 seconds (yep!). > > See attached or > > https://www.sagenb.org/home/pub/1831/ > > -- William > > > different threads, corresponding to the different branches of > > the complex log; they all spiral about the x-axis. You can > > see the graph here: > >https://www.sagenb.org/home/pub/1830/ > > > The published notebook also shows a plot of x^x for x>0 > > together with points of the form (-p/q)^(-p/q) for odd q. > > These points all lie where one of the threads pierces the > > x-re(z) plane. > > > > Plot_branches_of_x_x_efficiently.sws > 81KDownload > > Picture 3.png > 41KViewDownload --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
On May 16, 2:44 am, Dan Pillone <[EMAIL PROTECTED]> wrote: > > Is there a way to plot x^x correctly? A lovely article by Mark Meyerson entitled "The x^x Spindle" appeared in Mathematics Magazine back in June of 96. The article shows how to interpret the graph of x^x in 3-space, using the complex values of x^x. This may be plotted in sage as follows: def f(x,k): if x != 0: z = exp(x*(maxima.log(x) + 2*I*pi*k)) return [x, real(z), imag(z)] else: return [0, 1, 0] dx = 0.02 pic = line([[0,1,0],[0,1,0]]); for k in range(-3,4): points = [f(x*dx,k) for x in range(-4/dx,2/dx)] pic = pic + line(points) pic.show(frame_aspect_ratio=[2,1,1], figsize=8) The above commands take *way* too long, presumably due to the repeated calls to maxima's complex log function. Sage's log function doesn't work. I was able to perform the loop in maxima, but I was unable to get the result back into sage for plotting. The result is quite nice, though. There are countably many different threads, corresponding to the different branches of the complex log; they all spiral about the x-axis. You can see the graph here: https://www.sagenb.org/home/pub/1830/ The published notebook also shows a plot of x^x for x>0 together with points of the form (-p/q)^(-p/q) for odd q. These points all lie where one of the threads pierces the x-re(z) plane. Mark --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
On May 19, 2008, at 7:08 PM, Dan Pillone wrote: > > Hi, > > Yes, I know that for lots of negative real numbers x^x is not defined, > but for some values of x, such as x=-1 or x=-1/3 there is a real > number answer and I don't see anything plotted. Why isn't anythng > plotted at those discrete set of values? They were less than 1 pixel wide :). On a more serious note, what happens is it picks a list of values between your two enpoints, evaluates the function at those points, and connects the dots. The chance that one of the chosen points is such that x^x is defined is extraordinarily slim (especially since the values are represented in floating point). - Robert > > Dan > > On May 16, 5:37 pm, Robert Bradshaw <[EMAIL PROTECTED]> > wrote: > >> >> This is because x^x is not real-valued for negative x (except at a >> discrete set of values). Unlike the cube root case, one can't even >> pick a branch that makes it real-valued. >> >> - Robert > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
Hi, Yes, I know that for lots of negative real numbers x^x is not defined, but for some values of x, such as x=-1 or x=-1/3 there is a real number answer and I don't see anything plotted. Why isn't anythng plotted at those discrete set of values? Dan On May 16, 5:37 pm, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > > This is because x^x is not real-valued for negative x (except at a > discrete set of values). Unlike the cube root case, one can't even > pick a branch that makes it real-valued. > > - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Plotting x^x
On May 15, 2008, at 11:44 PM, Dan Pillone wrote: > Hi, > > I am running SAGE as a VM on a windows computer. > > This is somewhat related to plotting the cube root of x, but I can't > find any method to plot the graph of x^x correctly. The best plot I > get is only correct for nonnegative values of x. Likewise, > > plot(lambda x: RR(x).nth_root(x)) > > (which was the suggestion for cube roots) doesn't work for here. > > Is there a way to plot x^x correctly? This is because x^x is not real-valued for negative x (except at a discrete set of values). Unlike the cube root case, one can't even pick a branch that makes it real-valued. - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---