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 -~----------~----~----~----~------~----~------~--~---