Ask Your Question

Finding all complex nth roots

asked 2020-07-21 16:20:11 +0100

DaveG gravatar image

I would love it if there were a command, let's say all_complex_roots, that returned a list or tuple or whatever of the 2 square roots, 3 cube roots, etc of a number. For instance, an input like all_complex_roots(1,4) would have the expected output [1,-1,I,-I] or some such.

Does such a command exist? I've seen workarounds, like finding all complex roots of the polynomial $X^4-1$, but is there something direct?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-21 17:30:46 +0100

slelievre gravatar image

Defining the function you need only takes a few lines:

def all_complex_roots(a, n):
    Return all complex `n`-th roots of `a`.
    x = polygen(QQbar)
    return (x^n - a).roots(multiplicities=False)

It is then ready to be used!

sage: all_complex_roots(1, 4)
[-1, 1, -1*I, 1*I]
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-07-21 16:20:11 +0100

Seen: 339 times

Last updated: Jul 21 '20