Ask Your Question
0

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

asked 2020-10-19 17:04:35 -0600

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

Comments

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-19 17:39:00 -0600 )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-19 18:01:58 -0600 )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-19 19:38:18 -0600 )edit

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

cybervigilante gravatar imagecybervigilante ( 2020-10-19 21:32:55 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-10-20 07:32:03 -0600

slelievre gravatar image

updated 2020-10-20 07:35:48 -0600

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

Stats

Asked: 2020-10-19 17:04:35 -0600

Seen: 68 times

Last updated: Oct 20