Roots of unity: Difference between revisions

Added 11l
m (→‎{{header|REXX}}: simplified some code, used a more idiomatic way for computing numeric digits (precision), added/changed whitespace and comments.)
(Added 11l)
Line 7:
Given &nbsp; <big>'''n'''</big>, &nbsp; find the &nbsp; <big>'''n'''<sup>th</sup></big> &nbsp; [[wp:Roots of unity|roots of unity]].
<br><br>
 
=={{header|11l}}==
<lang 11l>F polar(r, theta)
R r * (cos(theta) + sin(theta) * 1i)
 
F croots(n)
R (0 .< n).map(k -> polar(1, 2 * k * math:pi / @n))
 
L(nr) 2..10
print(nr‘ ’croots(nr))</lang>
 
{{out}}
<pre>
2 [1, -1]
3 [1, -0.5+0.866025404i, -0.5-0.866025404i]
4 [1, 1i, -1, -1i]
5 [1, 0.309016994+0.951056516i, -0.809016994+0.587785252i, -0.809016994-0.587785252i, 0.309016994-0.951056516i]
6 [1, 0.5+0.866025404i, -0.5+0.866025404i, -1, -0.5-0.866025404i, 0.5-0.866025404i]
7 [1, 0.623489802+0.781831482i, -0.222520934+0.974927912i, -0.900968868+0.433883739i, -0.900968868-0.433883739i, -0.222520934-0.974927912i, 0.623489802-0.781831482i]
8 [1, 0.707106781+0.707106781i, 1i, -0.707106781+0.707106781i, -1, -0.707106781-0.707106781i, -1i, 0.707106781-0.707106781i]
9 [1, 0.766044443+0.64278761i, 0.173648178+0.984807753i, -0.5+0.866025404i, -0.939692621+0.342020143i, -0.939692621-0.342020143i, -0.5-0.866025404i, 0.173648178-0.984807753i, 0.766044443-0.64278761i]
10 [1, 0.809016994+0.587785252i, 0.309016994+0.951056516i, -0.309016994+0.951056516i, -0.809016994+0.587785252i, -1, -0.809016994-0.587785252i, -0.309016994-0.951056516i, 0.309016994-0.951056516i, 0.809016994-0.587785252i]
</pre>
 
=={{header|Ada}}==
1,481

edits