Ask Your Question

Why does plot choke on x to the 1/3 power, when it will calculate it just fine?

asked 2020-10-20 00:04:35 +0200

cybervigilante gravatar image

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

edit retag flag offensive close merge delete


This question has been covered before, see here. 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.

dazedANDconfused gravatar imagedazedANDconfused ( 2020-10-20 00:39:00 +0200 )edit

Well, 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

cybervigilante gravatar imagecybervigilante ( 2020-10-20 01:01:58 +0200 )edit

Following 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.

dazedANDconfused gravatar imagedazedANDconfused ( 2020-10-20 02:38:18 +0200 )edit

Thanks, I need to look into rings like RR, which I only vaguely understand.

cybervigilante gravatar imagecybervigilante ( 2020-10-20 04:32:55 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-20 14:32:03 +0200

slelievre gravatar image

updated 2020-10-20 14:35:48 +0200

Use this:

sage: plot(real_nth_root(x, 3), (x, -10, 10))

Plot of real cube root

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-10-20 00:04:35 +0200

Seen: 219 times

Last updated: Oct 20 '20