(complex) root of unity
01-16-2021, 02:47 PM (This post was last modified: 01-16-2021 02:53 PM by salvomic.)
Post: #1
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
(complex) root of unity
hi,
first of try by myself to write a formule, I wonder if there is already for the Prime a program or app to get "all the complex root of unity (or any complex number) (see https://en.wikipedia.org/wiki/Root_of_unity), in other words, I need a program or routine to calculate all real and complex roots of any real or complex number, returned in a list or matrix...

Thanks a lot,
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 02:57 PM
Post: #2
 rprosperi Super Moderator Posts: 5,998 Joined: Dec 2013
RE: (complex) root of unity
(01-16-2021 02:47 PM)salvomic Wrote:  ...I need a program or routine to calculate all real and complex roots of any real or complex number, returned in a list or matrix...

Roots of a number?

Perhaps if you provide an example it would be more clear?

--Bob Prosperi
01-16-2021, 03:24 PM
Post: #3
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
Is the example I report correct?

See the attachment.

Attached File(s) Thumbnail(s)

01-16-2021, 03:40 PM
Post: #4
 Albert Chan Senior Member Posts: 2,355 Joined: Jul 2018
RE: (complex) root of unity
Assumed n is positive integer.

Cas> rootsOfOne(n) := e^(2*pi*i*range(n)/n)
Cas> rootsOfOne(3)

[1, 1/2*√3*i-1/2, -1/2*√3*i-1/2]

Cas> rootsOfz(z,n) := z^(1/n) * rootsOfOne(n)
Cas> approx(rootsOfz(3+4i, 3))

[ 1.62893714592 +0.520174502305*i,
−1.26495290636 +1.15061369838*i,
−0.363984239564-1.67078820069*i]

Cas> Ans .^ 3

[3.+4.*i, 3.+4.*i, 3.+4.*i]
01-16-2021, 03:53 PM
Post: #5
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 02:57 PM)rprosperi Wrote:  Roots of a number?

Perhaps if you provide an example it would be more clear?

e.g. the three roots of 3√1 or the four of 4√-3 or the two of √(1+i) ...

Like the function in Math1 pac for HP 41CX; input img and real part of the complex number, then the nRth exponent, to get the n roots...
See here the three roots of unity, but I need something to get the roots of any complex number.

Code:
 Z "img" Y "real" X nRth XEQ "Z↑1/N"

The solution of robmio below could be ok, with some semplications, however...

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 03:56 PM
Post: #6
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 03:24 PM)robmio Wrote:  Is the example I report correct?

See the attachment.

yes, at least this works, however better to simplify...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 03:58 PM
Post: #7
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 03:40 PM)Albert Chan Wrote:  Assumed n is positive integer.

Cas> rootsOfOne(n) := e^(2*pi*i*range(n)/n)
Cas> rootsOfOne(3)

[1, 1/2*√3*i-1/2, -1/2*√3*i-1/2]

Cas> rootsOfz(z,n) := z^(1/n) * rootsOfOne(n)
Cas> approx(rootsOfz(3+4i, 3))

[ 1.62893714592 +0.520174502305*i,
−1.26495290636 +1.15061369838*i,
−0.363984239564-1.67078820069*i]

Cas> Ans .^ 3

[3.+4.*i, 3.+4.*i, 3.+4.*i]

well, thanks,
I'll try this.
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 05:27 PM
Post: #8
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 03:40 PM)Albert Chan Wrote:  Assumed n is positive integer.
...

something like this, then
Code:
 EXPORT rootsOfOne(n) BEGIN RETURN e^(2*PI*i*range(n)/n); END; EXPORT rootsOfZ(z, n) BEGIN RETURN z^(1/n) * rootsOfOne(n); END;

but: rootOFOne(3) I get "Error: Bad argument type"

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 05:42 PM
Post: #9
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
it seems that within a program the HP PRIME does not recognize the "range" command
01-16-2021, 05:47 PM
Post: #10
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
if you rewrite the program as CAS, it works.
01-16-2021, 06:02 PM (This post was last modified: 01-16-2021 06:05 PM by salvomic.)
Post: #11
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 05:47 PM)robmio Wrote:  if you rewrite the program as CAS, it works.

yes, actually.
Now:
Code:
 #cas rootsOfOne(n):= BEGIN RETURN e^(2*PI**range(n)/n); END; rootsOfZ(z, n):= BEGIN RETURN z^(1/n) * rootsOfOne(n); END; #end

it works, but I get first a warning "Recursive" (see attached images).
Then, trying with "3+4i" I get a little square in the matrix (second item): I don't know what's the reason...

Salvo

Attached File(s) Thumbnail(s)

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 06:12 PM
Post: #12
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
The small square in the HP PRIME G2 with firmware 20200121 replaces the three dots that appear in the HP Prime Virtual Calculator lists or vectors

Code:
 #cas rootsOFOne(n):= BEGIN RETURN e^(2**π*range(n)/n); END; rootsOfZ(z, n):= BEGIN RETURN z^(1/n)*rootsOFOne(n); END; #end
01-16-2021, 06:17 PM
Post: #13
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 06:12 PM)robmio Wrote:  The small square in the HP PRIME G2 with firmware 20200121 replaces the three dots that appear in the HP Prime Virtual Calculator lists or vectors

yes, ok, I had this problem in another program of mine and I solved there shorting the decimal places.
Is there a way to avoid that?
Using Approx the small square is still there, without showing the second value of the root...

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 06:28 PM
Post: #14
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
see what happens if I use HP Prime Virtual Calculator on PC: instead of the square there are three dots. The square is a feature of HP PRIME G2 with filrmware 20200121

Attached File(s) Thumbnail(s)

01-16-2021, 06:37 PM
Post: #15
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 06:28 PM)robmio Wrote:  see what happens if I use HP Prime Virtual Calculator on PC: instead of the square there are three dots. The square is a feature of HP PRIME G2 with filrmware 20200121

yes, I'm seeing.
I wonder if it is possible to show also the second item, without the dots (or the square)...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
01-16-2021, 06:40 PM
Post: #16
 robmio Member Posts: 169 Joined: Jan 2020
RE: (complex) root of unity
To see the second value, the third, and so on, use the "Show" option
01-16-2021, 06:48 PM
Post: #17
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: (complex) root of unity
(01-16-2021 06:40 PM)robmio Wrote:  To see the second value, the third, and so on, use the "Show" option

oh, well, I've forgot that
thanks
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
12-26-2021, 11:45 AM
Post: #18
 Jon Higgins Junior Member Posts: 1 Joined: Dec 2021
RE: (complex) root of unity
Hello salvomic,

Re, your post: "I need a program or routine to calculate all real and complex roots of any real or complex number, returned in a list or matrix..."

You might be interested in this solution for your problem that I stumbled across:

In CAS, For the fourth root of unity, use POLYROOT like this and enter unity as the complex number 1+0*i:

POLYROOT(X^4-(1+0*i))sto L1 .......(1)

Press “Enter”:

The results are in L1: (-1, -i, i, 1); scroll up and down to see them on the "contents" line.

In fact POLYROOT(X^n-1)sto L1 works for the case of n.th roots of unity.

For n.th roots of any complex number stored in a List, use the format above in (1).

Note that I did try and implement this in a program, but I couldn't get it to work.

(I am new here and this is my first post!)

Attached File(s)