How to resolve the algorithm Roots of unity step by step in the Sparkling programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Roots of unity step by step in the Sparkling programming language
Table of Contents
Problem Statement
The purpose of this task is to explore working with complex numbers.
Given n, find the nth roots of unity.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Roots of unity step by step in the Sparkling programming language
Source code in the sparkling programming language
function unity_roots(n) {
// nth-root(1) = cos(2 * k * pi / n) + i * sin(2 * k * pi / n)
return map(range(n), function(idx, k) {
return {
"re": cos(2 * k * M_PI / n),
"im": sin(2 * k * M_PI / n)
};
});
}
// pirnt 6th roots of unity
foreach(unity_roots(6), function(k, v) {
printf("%.3f%+.3fi\n", v.re, v.im);
});
You may also check:How to resolve the algorithm Tropical algebra overloading step by step in the Julia programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the PHP programming language
You may also check:How to resolve the algorithm Tau number step by step in the AWK programming language
You may also check:How to resolve the algorithm Sort a list of object identifiers step by step in the jq programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the Ring programming language