ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 Oct 2020 14:32:03 +0200Why does plot choke on x to the 1/3 power, when it will calculate it just fine?https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'
OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188
Tue, 20 Oct 2020 00:04:35 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/Comment by dazedANDconfused for <p>plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'</p>
<p>OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188</p>
https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53977#post-id-53977This question has been covered before, see [here](https://ask.sagemath.org/question/51005/how-to-correctly-plot-x13/). Remember your order of operation: exponentiation doesn't apply to the negative. You've taken a positive cube root and then made it negative. If you try `(-10)^(1/3).n()` then you get `1.07721734501594 + 1.86579517236206*I`.Tue, 20 Oct 2020 00:39:00 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53977#post-id-53977Comment by cybervigilante for <p>plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'</p>
<p>OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188</p>
https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53978#post-id-53978Well, the plot comes out fine if I use sgn twice, but it's a bit obtuse, easy to mistype, and strikes me as a bit of a cheat. ðŸ˜‹
`plot(sgn(x)*((sgn(x)*x)^(1/3)),-10,10)`
And it bothers me that the cube root of -8 is -2, a real number.
`-2*-2*-2 = -8`Tue, 20 Oct 2020 01:01:58 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53978#post-id-53978Comment by dazedANDconfused for <p>plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'</p>
<p>OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188</p>
https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53979#post-id-53979Following the answers, both `plot(sgn(x)*abs(x)^(1/3),(x,-10,10))`, which uses `sgn` once and the more natural `plot(lambda x: RR(x).nth_root(3), (-10, 10))` work. The `RR` is telling Sage that real roots are expected. See documentation [here](https://doc.sagemath.org/html/en/tutorial/tour_rings.html).Tue, 20 Oct 2020 02:38:18 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53979#post-id-53979Comment by cybervigilante for <p>plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'</p>
<p>OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188</p>
https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53980#post-id-53980Thanks, I need to look into rings like RR, which I only vaguely understand.Tue, 20 Oct 2020 04:32:55 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?comment=53980#post-id-53980Answer by slelievre for <p>plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'</p>
<p>OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188</p>
https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?answer=53984#post-id-53984Use this:
sage: plot(real_nth_root(x, 3), (x, -10, 10))
![Plot of real cube root](/upfiles/1603197325866109.png)Tue, 20 Oct 2020 14:32:03 +0200https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/?answer=53984#post-id-53984