Post Reply 
(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
(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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 02:57 PM
Post: #2
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
Find all posts by this user
Quote this message in a reply
01-16-2021, 03:24 PM
Post: #3
RE: (complex) root of unity
Is the example I report correct?

See the attachment.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
01-16-2021, 03:40 PM
Post: #4
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]
Find all posts by this user
Quote this message in a reply
01-16-2021, 03:53 PM
Post: #5
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 03:56 PM
Post: #6
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 03:58 PM
Post: #7
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 05:27 PM
Post: #8
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 05:42 PM
Post: #9
RE: (complex) root of unity
it seems that within a program the HP PRIME does not recognize the "range" command
Find all posts by this user
Quote this message in a reply
01-16-2021, 05:47 PM
Post: #10
RE: (complex) root of unity
if you rewrite the program as CAS, it works.
Find all posts by this user
Quote this message in a reply
01-16-2021, 06:02 PM (This post was last modified: 01-16-2021 06:05 PM by salvomic.)
Post: #11
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 06:12 PM
Post: #12
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
Find all posts by this user
Quote this message in a reply
01-16-2021, 06:17 PM
Post: #13
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 06:28 PM
Post: #14
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)
   
Find all posts by this user
Quote this message in a reply
01-16-2021, 06:37 PM
Post: #15
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
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2021, 06:40 PM
Post: #16
RE: (complex) root of unity
To see the second value, the third, and so on, use the "Show" option
Find all posts by this user
Quote this message in a reply
01-16-2021, 06:48 PM
Post: #17
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 Smile
thanks
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
12-26-2021, 11:45 AM
Post: #18
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).

Please see the attachment.

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)
.docx  HPM_post_1.docx (Size: 59.01 KB / Downloads: 8)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 8 Guest(s)