Roots of unity: Difference between revisions

added MiniScript example
(added MiniScript example)
Line 1,046:
solve(1 = x^4, x) = [x = %i, x = -1, x = -%i, x = 1]
solve(1 = x^5, x) = [x = %e^((2*%i*%pi)/5), x = %e^((4*%i*%pi)/5), x = %e^(-(4*%i*%pi)/5), x = %e^(-(2*%i*%pi)/5), x = 1]</lang>
 
=={{header|МiniScript}}==
<lang MiniScript>
complexRoots = function(n)
result = []
for i in range(0, n-1)
real = cos(2*pi * i/n)
if abs(real) < 1e-6 then real = 0
imag = sin(2*pi * i/n)
if abs(imag) < 1e-6 then imag = 0
result.push real + " " + "+" * (imag>=0) + imag + "i"
end for
return result
end function
 
for i in range(2,5)
print i + ": " + complexRoots(i).join(", ")
end for</lang>
 
{{out}}
<pre>2: 1 +0i, -1 +0i
3: 1 +0i, -0.5 +0.866025i, -0.5 -0.866025i
4: 1 +0i, 0 +1i, -1 +0i, 0 -1i
5: 1 +0i, 0.309017 +0.951057i, -0.809017 +0.587785i, -0.809017 -0.587785i, 0.309017 -0.951057i</pre>
 
=={{header|МК-61/52}}==
222

edits