Ask Your Question
0

Is there a simple way to deal with computing real nth roots for n a natural number?

asked 2013-11-12 19:07:58 +0200

anonymous user

Anonymous

I am trying to use the nth root for natural numbers in computations and display the result as a decimal to four places. I can't find a simple reference for these functions. Is there an nroot(x,n) function?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-11-12 21:07:00 +0200

kcrisman gravatar image

updated 2013-11-13 08:54:19 +0200

Usually this comes up in plotting. See the Sage reference and search the page for "cube root".

sage: a = 2
sage: b = a.n()
sage: b
2.00000000000000
sage: b.nth_root(3)
1.25992104989487
sage: _^3 # _ means the previous output
2.00000000000000

There is an nth_root for real numbers like this, but be careful if you want to try this for plain old integers:

sage: a.nth_root(3)
---------------------------------------------------------------------------
<snip>
ValueError: 2 is not a 3rd power
edit flag offensive delete link more

Comments

"# _ means the previous input" or output? equivalent to "ans" in MATLAB. And we can use a.nth_root(3, truncate_mode = 1). --> (1, False).

gundamlh gravatar imagegundamlh ( 2013-11-13 04:04:08 +0200 )edit

Yes, output of course - I'll edit that.

kcrisman gravatar imagekcrisman ( 2013-11-13 08:54:11 +0200 )edit
-1

answered 2013-11-12 19:52:00 +0200

Shashank gravatar image

I don't think there is one but you can define one using a couple of lines of code

def nroot(x,n):
    return x**(1/n).n()
nroot(8,3)
edit flag offensive delete link more

Comments

Not so easy when you try def nroot(x,n): return x**(1/n).n() nroot(-8,3) You don't get the real root- but instead: 1.00000000000000 + 1.73205080756888*I There's the rub. :(

Martin Flashman gravatar imageMartin Flashman ( 2013-11-12 20:55:35 +0200 )edit

It is supposed to be complex. You cannot have real cube root for -8.

Shashank gravatar imageShashank ( 2013-11-12 21:01:39 +0200 )edit

You can't? I always thought -2 cubed was -8 ... :-) But it is true that Sage returns a sort of "primitive nth root" (whatever that means) by default.

kcrisman gravatar imagekcrisman ( 2013-11-12 21:08:10 +0200 )edit

Sorry about that.

Shashank gravatar imageShashank ( 2013-11-12 21:09:46 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-11-12 19:07:58 +0200

Seen: 11,719 times

Last updated: Nov 13 '13