Bill Page wrote: > On Thu, May 14, 2009 at 11:06 AM, Jason Grout wrote: >> Bill Page wrote: >>> Consider the problem to define >>> >>> f(x) = x^(1/3) >>> >>> so that it takes the real branch for x < 0. The best I have been able >>> to come up with so far is: >>> >>> sage: f = lambda x: >>> RealField(53)(x).sign()*(RealField(53)(x).sign()*x)^(1/3) >>> sage: plot(f,(-2,2)) >>> >> plot(lambda x: RR(x).nth_root(3), -5, 5, plot_points=20) >> >> This is from a mailing list discussion last year (Feb 2008?) on the same >> issue. In fact, there have been several discussions of this. Search >> sage-devel for "plotting cube roots", for example. >> > > Ok thanks. I recall the discussion and I can indeed write: > > sage: f=lambda x:RR(x).nth_root(3) > sage: f(-2.0) > -1.25992104989487 > > but I think I'll let my earlier comment stand: > >>> I think there should be a more obvious way.
Of course, you're welcome to suggest a way. Note that in earlier threads, having a switch that determines which root to pick has been negatively viewed. What about changing the name of the above function to: RR(x).real_root(3) ? That would certainly be easier to find and would be a bit more descriptive. Of course, right now, there is an nth_root function for complex numbers that also would have to be addressed. Or what about making real_root a method for any number (or real_nth_root, or make nth_root take an argument for a target domain, like RR or RDF)? Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---