Given a small integer n, print all the n’th roots of unity up to 6 significant digits. We basically need to find all roots of equation xn – 1.
Input : n = 1 Output : 1.000000 + i 0.000000 x - 1 = 0 , has only one root i.e., 1 Input : 2 Output : 1.000000 + i 0.000000 -1.000000 + i 0.000000 x2 - 1 = 0 has 2 distinct roots, i.e., 1 and -1
Any complex number is said to be root of unity if it gives 1 when raised to some power.
nth root of unity is any complex number such that it gives 1 when raised to the power n.
Mathematically, An nth root of unity, where n is a positive integer (i.e. n = 1, 2, 3, …) is a number z satisfying the equation z^n = 1 or , z^n - 1 = 0
We can use the De Moivre’s formula here ,
( Cos x + i Sin x )^k = Cos kx + i Sin kx Setting x = 2*pi/n, we can obtain all the nth roots of unity, using the fact that Nth roots are set of numbers given by, Cos (2*pi*k/n) + i Sin(2*pi*k/n) Where, 0 <= k < n
Using the above fact we can easily print all the nth roots of unity !
Below is the program for the same.
= 0 ? print(” + i “): print(” – i “);
printf(round(abs($img), 6) . “\n”);
// Driver Code
// This code is contributed by mits
1.000000 + i 0.000000 1.000000 + i 0.000000 -1.000000 + i 0.000000 1.000000 + i 0.000000 -0.500000 + i 0.866025 -0.500000 - i 0.866025
References : Wikipedia
This article is contributed by Ashutosh Kumar .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Program to find the Roots of Quadratic equation
- Bakhshali Approximation for computing square roots
- Seeds (Or Seed Roots) of a number
- Absolute difference between sum and product of roots of a quartic equation
- Find the number of primitive roots modulo prime
- Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula
- Find number of factors of N when location of its two factors whose product is N is given
- Square free semiprimes in a given range using C++ STL
- Count number of pairs in array having sum divisible by K | SET 2
- Count number of pairs of lines intersecting at a Point
- Maximum number of region in which N non-parallel lines can divide a plane
- 21 Matchsticks Problem
- Minimum Possible sum of digits in a positive multiple of N
- Find the smallest positive number which can not be represented by given digits