Ask Your Question
1

Finding all complex nth roots

asked 2020-07-21 09:20:11 -0500

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
1

answered 2020-07-21 10:30:46 -0500

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

Stats

Asked: 2020-07-21 09:20:11 -0500

Seen: 69 times

Last updated: Jul 21