This is really upsetting:
sage: plot(lambda x: x^(1/3), -5, 5)
-
---------------------------------------------------------------------------
<type 'exceptions.TypeError'> Traceback (most recent call last)
/home/ghitza/colby/ma311/<ipython console> in <module>()
/opt/sage/local/lib/python2.5/site-packages/sage/plot/plot.py in
__call__(self, funcs, *args, **kwds)
~ 3349 xmax = args[1]
~ 3350 args = args[2:]
- -> 3351 G = self._call(funcs, (xmin, xmax), *args, **kwds)
~ 3352 else:
~ 3353 print "there were %s extra arguments (besides
%s)" % (n, funcs)
/opt/sage/local/lib/python2.5/site-packages/sage/plot/plot.py in
_call(self, funcs, xrange, parametric, polar, label, **kwds)
~ 3419 del options['plot_division']
~ 3420 while i < len(data) - 1:
- -> 3421 if abs(data[i+1][1] - data[i][1]) > max_bend:
~ 3422 x = (data[i+1][0] + data[i][0])/2
~ 3423 try:
<type 'exceptions.TypeError'>: 'float' object is unsubscriptable
- -------------------------------------------------------------------------
Yes, it's related to tickets #2038 and #2045, but much worse, because in
this case not only is the error message "unfriendly", but it's also
unwarranted: the cube root is a well-defined function on all of RR, so
it should be possible to get a plot of it on the interval [-5,5].
This probably got broken when (-1)^(1/3) stopped being -1.
Alex
- --
Alexandru Ghitza
Assistant Professor
Department of Mathematics
Colby College
Waterville, ME 04901
http://bayes.colby.edu/~ghitza/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHulB+dZTaNFFPILgRApr2AJ4p1Vc9PimTKNsFUS/Lw32tSbAvDgCfYjsF
ol3u1oW3kpRM9dK/o08+UAw=
=ZkrJ
-----END PGP SIGNATURE-----
1. I agree that the error message sucks.
2. You might want to do:
sage: plot(x^(1/3),(0,5)) + plot(-(-x)^(1/3),(-5,0))
3. Even with Python floats, (-1)^(0.3333) would never work in Python,
so just directly plotting x^(1/3) for negative x isn't going to work:
In [1]: a = float(-1); b = float(0.333333333333333333333333333333333)
In [2]: a**b
---------------------------------------------------------------------------
<type 'exceptions.ValueError'> Traceback (most recent call last)
/Users/was/build/sage-2.10.2.alpha0/devel/sage-review/sage/modular/<ipython
console> in <module>()
<type 'exceptions.ValueError'>: negative number cannot be raised to a
fractional power
sage: RR(-1)^(RR(1/3))
0.500000000000000 + 0.866025403784439*I
This computes the principal value cube root, which by convention gives
us the root in the upper half-plane.
But when you are plotting the cube root as a function like that, you
really do want the real root if at all possible. One idea would be to
have some sort of "real only" option which would try to keep all
results real. I'm not sure how this would be implemented...
-Bobby
--
Bobby Moretti
mor...@u.washington.edu
Nice!
This is faster:
sage: plot(lambda x: RR(x).nth_root(3), -5, 5, plot_points=20)
For lots of discussion of this issue, see the thread:
http://groups.google.com/group/sage-support/browse_thread/thread/5e650e35bd354c17/415d26fe242fd162
One thing to note about Mathematica: they used to have a RealOnly
package that would make (-1)^(1/3) be -1 (I believe this was in even the
last version of Mma). But even that package is now deprecated.
Jason
When f is a Sage object and one does
sage: plot(f,...)
the plot function first tries f.plot(...).
I think I might not be opposed to f.plot(...) for symbolic objects being
a bit "smarter" in cases like x^(1/3) and drawing something that
seems like the best choice for "plotting symbolic expression f
on the interval (a,b)". For example, it could do something sensible
with powers like x^(1/3) that appear in the symbolic expression.
This is of course a VERY slippery slope -- the subtle bugs
and confusion that could arise from making the value of
(-3)^(1/3) different when plotting x^(1/3) from everything else
make me shudder.
-- William
Are you sure? You do realize that
Plot[x^(1/3), {x,-5,5}]
in Mathematica 6.0 also doesn't work (in the sense that it completely
ignores all the negative values of x).
You could argue probably successfully that Mathematica hasn't
caught on at all in "secondary and low-level postsecondary
markets"...
-- William