 nth Root
 The nth Root
 The nth Root Symbol
 Using it
 Why «Root» … ?
 Properties
 Multiplication and Division
 Example:
 Addition and Subtraction
 Exponents vs Roots
 Example:
 nth Root of atothenthPower
 nth Root of atothemthPower
 Example:
 Example:
 How numpy. power is to get the root?
 What is numpy. power()?
 Syntax
 Parameters
 Return
 The change we are going to do in the power function
 Example 1
 Example 2
 Example 3
 Code
 Learn how to calculate the sqrt() and cbrt() using numpy
 Conclusion
 Example 01:
 Example 02:
 Example 03:
 Conclusion:
 About the author
 Nth Root Definition
 Nth Root Symbol
 How to find the Nth Root of a Number?
 When does the Nth Root exist?
 Properties of Nth Root
 Facts to Remember
 Simplifying Nth Root
 C++
 Java
 Python3
 C#
 PHP
 Javascript
 What is Nth Root?
 Nth Root Symbol
 Nth root of Unity
 How to Find nth Root of Unity?
 Nth Root of Unity in Complex Numbers
 Properties of Nth Root of unity
 Solved Examples on Nth Root
 FAQs on Nth Root
 Q1: What is the nth root?
 Q2: What is a Square Root?
 Q3: What is a Cube Root?
 Q4: What are the Cube Roots of Unity?
 Q5: What is the fourth root of unity?
nth Root
The «nth Root» used n times in a multiplication gives the original value
Instead of talking about the «4th», «16th», etc, we can just say the «».
The nth Root
 The «2nd» root is the square root
 The «3rd» root is the cube root
 etc!
So it is the general way of talking about roots
(so it could be 2nd, or 9th, or 324th, or whatever)
The nth Root Symbol
This is the special symbol that means «nth root»,
it is the «radical» symbol (used for square roots) with a little n to mean nth root.
Using it
We could use the nth root in a question like this:
Question: What is «n» in this equation?
= 5
Answer: I just happen to know that 625 = 5^{4} , so the 4th root of 625 must be 5:
= 5
Or we could use «n» because we want to say general things:
Example: When n is odd then
= a
(we talk about this later).
Why «Root» … ?
Properties
Now we know what an nth root is, let us look at some properties:
Multiplication and Division
We can «pull apart» multiplications under the root sign like this:
=
×
(Note: if n is even then a and b must both be ≥ 0)
This can help us simplify equations in algebra, and also make some calculations easier:
Example:
=
=
×
=
4
So the cube root of 128 simplifies to 4 times the cube root of 2.
It also works for division:
=
(a≥0 and b>0)
Note that b cannot be zero, as we can’t divide by zero
=
=
1/4
So the cube root of 1/64 simplifies to just one quarter.
Addition and Subtraction
But we cannot do that kind of thing for additions or subtractions!
+
a − b
−
a^{n} + b^{n}
a + b
Example: Pythagoras’ Theorem says
So we calculate c like this:
c = a^{2} + b^{2}
Which is not the same as c = a + b , right?
It is an easy trap to fall into, so beware.
It also means that, unfortunately, additions and subtractions can be hard to deal with when under a root sign.
Exponents vs Roots
An exponent on one side of «=» can be turned into a root on the other side of «=»:
If a^{n} = b then a =
Note: when n is even then b must be ≥ 0
Example:
5^{4} = 625 so 5 =
nth Root of atothenthPower
Did you see that −3 became +3 ?
Here it is in a little table:
nth Root of atothemthPower
What happens when the exponent and root are different values (m and n)?
Well, we are allowed to change the order like this:
=
So this: nth root of (a to the power m)
becomes (nth root of a) to the power m
Example:
=
= 3^{2}
= 9
Easier than squaring 27 then taking a cube root, right?
=
^{}
The new exponent is the fraction which may be easier to solve.
Example:
= ^{}
= 4^{2}
= 16
This works because the nth root is the same as an exponent of (1/n)
=
^{}
You might like to read about Fractional Exponents to find out why!
318, 2055, 319, 317, 1087, 2056, 1088, 2057, 3159, 3160
In this article, we will learn about the numpy nth root of a number. We are going to learn how to solve the nth root of any number. In python, we use numpy.sqrt() to find the of a number. And we use numpy.cbrt() to find the third root, the cube of a number. But If we want the 5th root or 6th root of a number. What will we do? How to find this root? You will get the solutions for all these questions at the end of the article.
If B is equal to A multiplied n times, then B’s nth root would be equal to A, which is the nth root. The number in a smaller subscript tells which root it is so. Suppose we want the square root of 16. Then we can easily say two times of 4 will give 16. Likewise, if we want the cube root of 8, we say three times of 2 will give 27. Now we go for 32 roots of 5; then we have to find out what number multiplied by itself gives us 32. This is the common idea to get the nth root of any number.
How numpy. power is to get the root?
We are going to use to get the root of a number. It is useful to calculate the power of a number. Here we are using it to find the root. Many of you are confused about how it is possible? We know that 2^{5} = 32. Now, if we want the root, we can interchange it as 32^{1/5}. Now we will get the root as 2. This is the change we will make in power() to get the root of a number.
What is numpy. power()?
An element in the second array is raised to the power of the element in the first array. The limit of both arrays must be the same and positive numbers.
Syntax
numpy.power(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'power'>
Parameters
 x1: base element
 x2: power element
 out: the result will be stored
 where: If the value is True calculate the univerfunction. Otherwise, leave the value.
 **kwargs: Allows to pass keyword variable length of the argument
Return
The bases in x1 are raised to the exponents in x2. This is a scalar if both x1 and x2 are scalars.
The change we are going to do in the power function
To calculate the power:
np.power(element1, element2)
To calculate the root:
np.power(element1, (1/element2))
Example 1
import numpy as np def nthroot(a,n): return np.power(a,(1/n)) a=81 n=7 result=nthroot(a,n) print(f'The {n}th root of {a} is:',result)
 Import numpy as np.
 Create a function named nthroot.
 The parameters of the function are a and n. a is the number. n is to represent which root it is for.
 Inside a function using np.power() to calculate the root.
 Giving the values of a and n.
 Printing the result
The 7th root of 81 is: 1.873444004574479
7 times of final result will give the value 81.
Example 2
import numpy as np a = int(input("Enter a number:")) n =int(input("Enter which root do you want:")) result=(np.power(a,(1/n))) print(f'The {n}th root of {a} is:',result)
 Import numpy as np
 Get the values of a and n from the user.
 Using np.power() to calculate the root.
 Finally printing the result
Enter a number:81 Enter which root do you want:6 The 6th root of 81 is: 2.080083823051904
6 times of final result will give the value 81.
Example 3
import numpy as np a=90 n=4 print ("number: ",a) print("The nth root you gave: ",n) result=(np.power(a,(1/n))) print(f'The {n}th root of {a} is:',result)
 Import numpy as np.
 Giving the values of a and n.
 Using np.power() to calculate the root.
 Printing the result
number: 90 The nth root you gave: 4 The 4th root of 90 is: 3.080070288241023
4 times the final result gives the value 90.
Until we saw how to get a root for a single element, now we will see how to get the root for the array of elements.
Code
import numpy as np arr = np.arange(5) n=4 print ("array is: ", arr) result = np.power(arr,(1/n)) print(f'The {n}th root of {arr[0]} is:',result[0]) print(f'The {n}th root of {arr[1]} is:',result[1]) print(f'The {n}th root of {arr[2]} is:',result[2]) print(f'The {n}th root of {arr[3]} is:',result[3]) print(f'The {n}th root of {arr[4]} is:',result[4])
 Import numpy as np
 Giving the n value as 4.
 So we are going to calculate the 4th root of the every array element.
 Array values are given from 0 to 4.Printing the 4th root of every array elements.
array is: [0 1 2 3 4] The 4th root of 0 is: 0.0 The 4th root of 1 is: 1.0 The 4th root of 2 is: 1.189207115002721 The 4th root of 3 is: 1.3160740129524924 The 4th root of 4 is: 1.4142135623730951
Learn how to calculate the sqrt() and cbrt() using numpy
import numpy as np square_root=np.sqrt(16) print("The square root of 16 is:",int(square_root)) cube_root=np.cbrt(27) print("The cube root of 27 is:",int(cube_root))
 Import numpy as np
 Calculating square root using a builtin function np.sqrt()
 Next calculating the cube root using a builin function np.cbrt()
 Printing the result.
The square root of 16 is: 4 The cube root of 27 is: 3
1. Which function in numpy is useful to calculate the nth root of a number?
numpy.power() is useful to calculate the nth root of a number.
2. How to calculate the square root of a number using numpy?
numpy.sqrt() is useful to calculate the square root of a number.
3. How to calculate the cube root of a number using numpy?
cbrt() is useful to calculate the square root of a number.
Conclusion
Here we learned about the numpy nth root of a number briefly. We have used numpy.power() to get the root of a number. We hope this article is beneficial for all. Try to solve all the python programs on your own. Learn python in a python pool.
We have calculated the square root of many values in many situations within mathematics. We have also learned that the power of the square root is always “1/2”. But, what about the other powers? Therefore, we have decided to cover the general power of a root on a value, i.e., the “nth” value. This nth root can be taken as any natural number in general.
Therefore, we will learn some examples to create a mathematical expression with the “nth” root in a latex document. Let’s take a quick start on the Ubuntu 20.04 system.
Start from the system login. Open the Ubuntu’s console application by its activity area search bar. Write terminal and press Enter. The application will be shown on your screen. Click on the application to open it. Within a few seconds, your terminal will be shown.
Write “texmaker” and hit the “Enter” key to open the Latex editor for files in the query area.
Example 01:
As we know that the “nth” root is a value that has no exact value as 1,2,3, and so on. But, we also know that the nth root must contain some natural value from the numbers. To start this example, you must prepare your document first.
We will be doing our work within the \begin and \end command. So, we have been using the \sqrt command in the text area bounded by the “$” sign at both its ends. The dollar sign is used to represent the mathematical expression. The \sqrt contains two parameters. Ist one is the root value in the square brackets. While the other one is the base value within the curly brackets.
We have been presented with the belowshown output on our latex DVI file screen on running this code. You can see the root symbol on the value “x”, while the “n” has been shown as the nth root of base value “x”.
Example 02:
Let’s have a new illustration to get the expression of an “nth” root in the latex command. Open the same old latex document to make it updated. Let’s suppose you want to take an “nth” root of the value “xy” in the mathematical expression. Therefore, you have to use the same \sqrt command once more. You have to write “xy” in the place of argument value within the curly brackets.
Also, you must add the value “n” as root within the square brackets after the \sqrt command in the expression. The expression must be added between the dollar symbol.
Let’s run the above code after its execution. The output for this updated latex code shows us the nth root of a value “xy” in a standard document format.
Example 03:
You can see we have got the quadratic formula under the nth root.
You can also take an “nth” root of fractional values within the same mathematical expression. Therefore, we have been using three \frac commands to add three fractional values and adding nth root on all these fractional values separately using the \sqrt command.
The dollar sign has been used before and after every \sqrt command. Let’s save our newly made code to see the results.
You can see how the DVI file format presents a standard type of fractional mathematical expression taking nth root on each.
Conclusion:
This article has tried to cover simple and easy examples to present the “nth” root for mathematical expression in latex files. The \sqrt and \frac commands have been most used in this article. All the examples are fully usable at any Latex version on any operating system, most preferably on Ubuntu 20.04 Linux system. We hope that our readers will learn something from this article.
About the author
Hello, I am a freelance writer and usually write for Linux and other technology related content
In Mathematics, the nth root of a number x is a number y which when raised to the power n, obtains x:
Here, n is a positive integer, sometimes known as the degree of the root. A root of degree 2 is known as a square root, whereas the root of degree 3 is known as a . Roots of higher degree are also referred to using ordinary as in fourth root, fifth root, twentieth root, etc. The calculation of the nth root is a root extraction.
(Image will be uploaded soon)
Nth Root Definition
Let n be an integer greater than 1, then y is the nth root of x if and only if yⁿ = x.
Nth Root Symbol
It is a radical symbol used for square roots with a little n to define the nth root.
In order to understand the definition of the nth root more precisely, the student needs to be aware of a few other topics that will play a major role in the understanding of the nth root. These topics are explained briefly below.
Real numbers are referred to as the combination of rational and irrational numbers. All the arithmetic functions are said to be performed on these numbers and they can also be represented on the number line.
While, on the other hand, imaginary numbers are those that cannot be expressed on a number line, and are usually used to represent complex numbers. Real numbers can be both positive or negative and are usually denoted using the letter R. the natural numbers, fractions, and decimals fall under this category.
Irrational numbers refers to the real numbers that cannot be expressed in the form of a fraction. It cannot be denoted in the form of a ratio p/q, where the letters p and q refer to integers and q is not equal to zero. One can say that it is the opposite of the rational numbers.
Irrational numbers are normally expressed in the form R∖Q. The backward slash refers to the ‘set minus’. It is also often expressed in the form of RQ, which refers to the difference between a set of real numbers and a set of irrational numbers.
Complex numbers are referred to as numbers that can be expressed in the form of a + ib. a, b are the real numbers, while i refers to the imaginary numbers. For instance, 2+3i is a complex number where 2 is a real number while 3i denotes the imaginary number.
A square root of the number r can be referred to as x, which when squared, gives the result r.
It is to be noted that every positive real number possesses two square roots, one that is positive and one that is negative. For instance, the number 25 has two square roots, one is 5 and the other is 5. The positive square root is also denoted as the principal square root.
As the square root of every number is non negative, the negative numbers do not possess a square root. But every negative real number has two imaginary square roots associated with them. For example, the square root of 25 will be 5i and 5i. The i here represents the number whose square is supposed to be 1.
The cube root of a given number x can be a number r whose cube will be x.
How to find the Nth Root of a Number?
Ans: The nth root of a number can be calculated using the Newton method. Let us understand how to find the nth root of a number, ‘A’ using the Newton method.
Start with the initial guess x, and then repeat using the
When does the Nth Root exist?
In a real
If n is an even whole number, the nth root of x exists whenever x is positive, and for all x.
If n is an odd whole number, the nth root of x exists for all x.
Things get more complicated in the complex number system.
Every number has a square root, cube root, fourth root, fifth root, and so on.
The fourth root of a number 81 are 3, 3, 3i, 3i, because
3⁴ = 81
3⁴ = 81
(3i)⁴ = 3⁴ i⁴ = 81
(3i)⁴ = (3)⁴ i⁴ = 81
Properties of Nth Root

Expressing the degree of the nth root in its exponent form as in y¹ makes it easier to manipulate roots and power.

There is exactly one positive nth root in every positive real number. Hence, the rules of operation with surds including positive radicand x, and y are straightforward within a real number.

Subtleties can take place while calculating the nth root of a negative or complex number. For example,
Facts to Remember

The nth root of 0 is 0 for all positive integers n, as 0 is equal to 0.

The nth root of 1 is known as roots of unity and plays an important role in different areas of Mathematics such as number theory, the theory of equation, etc.
Simplifying Nth Root
Ans: Let us learn to simplify the nth root through the examples below:
I am looking for an efficient algorithm to find nth root of a number. The answer must be an integer. I have found that newtons method and bisection method are popular methods. Are there any efficient and simple methods for integer output?
asked Dec 22, 2013 at 13:40
20 gold badges71 silver badges104 bronze badges
#include <math.h>
inline int root(int input, int n)
{
return round(pow(input, 1./n));
}
This works for pretty much the whole integer range (as IEEE754 8byte double
s can represent the whole 32bit int
range exactly, which are the representations and sizes that are used on pretty much every system). And I doubt any integer based algorithm is faster on nonancient hardware. Including ARM. Embedded controllers (the microwave washing machine kind) might not have floating point hardware though. But that part of the question was underspecified.
answered Dec 22, 2013 at 13:44
int root(int a, int n) {
int v = 1, bit, tp, t;
if (n == 0) return 0; //error: zeroth root is indeterminate!
if (n == 1) return a;
tp = iPow(v,n);
while (tp < a) { // first power of two such that v**n >= a
v <<= 1;
tp = iPow(v,n);
}
if (tp == a) return v; // answer is a power of two
v >>= 1;
bit = v >> 1;
tp = iPow(v, n); // v is highest power of two such that v**n < a
while (a > tp) {
v += bit; // add bit to value
t = iPow(v, n);
if (t > a) v = bit; // did we add too much?
else tp = t;
if ( (bit >>= 1) == 0) break;
}
return v; // closest integer such that v**n <= a
}
// used by root function...
int iPow(int a, int e) {
int r = 1;
if (e == 0) return r;
while (e != 0) {
if ((e & 1) == 1) r *= a;
e >>= 1;
a *= a;
}
return r;
}
answered Sep 12, 2015 at 17:55
1 silver badge2 bronze badges
I question your use of «algorithm» when speaking of C programs. Programs and algorithms are not the same (an algorithm is mathematical; a C program is expected to be implementing some algorithm).
But on current processors (like in recent x8664 laptops or desktops) the FPU is doing fairly well. I guess (but did not benchmark) that a fast way of computing the nth root could be,
inline unsigned root(unsigned x, unsigned n) {
switch (n) {
case 0: return 1;
case 1: return x;
case 2: return (unsigned)sqrt((double)x);
case 3: return (unsigned)cbrt((double)x);
default: return (unsigned) pow (x, 1.0/n);
}
}
I am not sure that nth root of a negative number makes sense in general. So my root
function takes some unsigned x
and returns some unsigned
number.
answered Dec 22, 2013 at 13:50
Here is an efficient general implementation in C, using a simplified version of the «shifting nth root algorithm» to compute the floor of the nth root of x:
uint64_t iroot(const uint64_t x, const unsigned n)
{
if ((x == 0)  (n == 0)) return 0;
if (n == 1) return x;
uint64_t r = 1;
for (int s = ((ilog2(x) / n) * n)  n; s >= 0; s = n)
{
r <<= 1;
r = (ipow(r1, n) <= (x >> s));
}
return r;
}
It needs this function to compute the nth power of x (using the method of exponentiation by squaring):
uint64_t ipow(uint64_t x, unsigned n)
{
if (x <= 1) return x;
uint64_t y = 1;
for (; n != 0; n >>= 1, x *= x)
if (n & 1)
y *= x;
return y;
}
and this function to compute the floor of base2 logarithm of x:
int ilog2(uint64_t x)
{
#if __has_builtin(__builtin_clzll)
return 63  ((x != 0) * (int)__builtin_clzll(x))  ((x == 0) * 64);
#else
int y = (x == 0);
for (unsigned k = 64 / 2; k != 0; k /= 2)
if ((x >> k) != 0)
{ x >>= k; y += k; }
return y;
#endif
}
Note: This assumes that your compiler understands GCC’s __has_builtin
test and that your compiler’s uint64_t
type is the same size as an unsigned long long
.
answered Oct 26, 2018 at 2:58
Todd Lehman
1 gold badge26 silver badges32 bronze badges
You can try this C function to get the nth_root of an unsigned integer :
unsigned initial_guess_nth_root(unsigned n, unsigned nth){
unsigned res = 1;
for(; n >>= 1; ++res);
return nth ? 1 << (res + nth  1) / nth : 0 ;
}
// return a number that, when multiplied by itself nth times, makes N.
unsigned nth_root(const unsigned n, const unsigned nth) {
unsigned a = initial_guess_nth_root(n , nth), b, c, r = nth ? a + (n > 0) : n == 1 ;
for (; a < r; b = a + (nth  1) * r, a = b / nth)
for (r = a, a = n, c = nth  1; c && (a /= r); c);
return r;
}
Example of output :
24 == (int) pow(15625, 1.0/3)
25 == nth_root(15625, 3)
0 == nth_root(0, 0)
1 == nth_root(1, 0)
4 == nth_root(4096, 6)
13 == nth_root(18446744073709551614, 17) // 64bit 20 digits
11 == nth_root(340282366920938463463374607431768211454, 37) // 128bit 39 digits
Here is the github source.
answered Apr 28, 2022 at 15:35
2 silver badges3 bronze badges
What’s the best algorithm to do this myself?
asked Sep 5, 2011 at 13:14
Can you use something like this?
Math.pow(n, 1/root);
Math.pow(25, 1/2) == 5
answered Sep 5, 2011 at 13:16
Digital Plane
7 gold badges56 silver badges59 bronze badges
The n
th root of x
is the same as x
to the power of 1/n
. You can simply use Math.pow
:
var original = 1000;
var fourthRoot = Math.pow(original, 1/4);
original == Math.pow(fourthRoot, 4); // (ignoring floatingpoint error)
answered Sep 5, 2011 at 13:16
Note that it does not handle negative nicely — here is a discussion and some code that does
function nthroot(x, n) {
try {
var negate = n % 2 == 1 && x < 0;
if(negate)
x = x;
var possible = Math.pow(x, 1 / n);
n = Math.pow(possible, n);
if(Math.abs(x  n) < 1 && (x > 0 == n > 0))
return negate ? possible : possible;
} catch(e){}
}
4 gold badges54 silver badges83 bronze badges
answered Sep 5, 2011 at 13:17
28 gold badges173 silver badges235 bronze badges
You could use
Math.nthroot = function(x,n) {
//if x is negative function returns NaN
return this.exp((1/n)*this.log(x));
}
//call using Math.nthroot();
answered Mar 7, 2016 at 11:42
3 silver badges12 bronze badges
For the special cases of square and cubic root, it’s best to use the native functions Math.sqrt
and Math.cbrt
respectively.
As of ES7, the exponentiation operator **
can be used to calculate the nth root as the ^{1}/_{n}th power of a nonnegative base:
let root1 = Math.PI ** (1 / 3); // cube root of π
let root2 = 81 ** 0.25; // 4th root of 81
This doesn’t work with negative bases, though.
let root3 = (32) ** 5; // NaN
answered Sep 17, 2016 at 16:28
GOTO 0
21 gold badges124 silver badges155 bronze badges
The n
th root of x
is a number r
such that r
to the power of 1/n
is x
.
In real numbers, there are some subcases:
 There are two solutions (same value with opposite sign) when
x
is positive andr
is even.  There is one positive solution when
x
is positive andr
is odd.  There is one negative solution when
x
is negative andr
is odd.  There is no solution when
x
is negative andr
is even.
Since Math.pow
doesn’t like a negative base with a noninteger exponent, you can use
function nthRoot(x, n) {
if(x < 0 && n%2 != 1) return NaN; // Not well defined
return (x < 0 ? 1 : 1) * Math.pow(Math.abs(x), 1/n);
}
nthRoot(+4, 2); // 2 (the positive is chosen, but 2 is a solution too)
nthRoot(+8, 3); // 2 (this is the only solution)
nthRoot(8, 3); // 2 (this is the only solution)
nthRoot(4, 2); // NaN (there is no solution)
answered Feb 29, 2016 at 1:01
62 gold badges430 silver badges508 bronze badges
Well, I know this is an old question. But, based on SwiftNinjaPro’s answer, I simplified the function and fixed some NaN issues. Note: This function used ES6 feature, arrow function and template strings, and exponentation. So, it might not work in older browsers:
Math.numberRoot = (x, n) => {
return (((x > 1  x < 1) && n == 0) ? Infinity : ((x > 0  x < 0) && n == 0) ? 1 : (x < 0 && n % 2 == 0) ? `${((x < 0 ? x : x) ** (1 / n))}${"i"}` : (n == 3 && x < 0) ? Math.cbrt(x) : (x < 0) ? ((x < 0 ? x : x) ** (1 / n)) : (n == 3 && x > 0 ? Math.cbrt(x) : (x < 0 ? x : x) ** (1 / n)));
};
Math.numberRoot(64, 3); // Returns 4
Example (Imaginary number result):
Math.numberRoot(729, 6); // Returns a string containing "3i".
answered Sep 3, 2019 at 18:13
Here’s a function that tries to return the imaginary number. It also checks for a few common things first, ex: if getting square root of 0 or 1, or getting 0th root of number x
function root(x, n){
if(x == 1){
return 1;
}else if(x == 0 && n > 0){
return 0;
}else if(x == 0 && n < 0){
return Infinity;
}else if(n == 1){
return x;
}else if(n == 0 && x > 1){
return Infinity;
}else if(n == 0 && x == 1){
return 1;
}else if(n == 0 && x < 1 && x > 1){
return 0;
}else if(n == 0){
return NaN;
}
var result = false;
var num = x;
var neg = false;
if(num < 0){
//not using Math.abs because I need the function to remember if the number was positive or negative
num = num*1;
neg = true;
}
if(n == 2){
//better to use square root if we can
result = Math.sqrt(num);
}else if(n == 3){
//better to use cube root if we can
result = Math.cbrt(num);
}else if(n > 3){
//the method Digital Plane suggested
result = Math.pow(num, 1/n);
}else if(n < 0){
//the method Digital Plane suggested
result = Math.pow(num, 1/n);
}
if(neg && n == 2){
//if square root, you can just add the imaginary number "i=√1" to a string answer
//you should check if the functions return value contains i, before continuing any calculations
result += 'i';
}else if(neg && n % 2 !== 0 && n > 0){
//if the nth root is an odd number, you don't get an imaginary number
//neg*neg=pos, but neg*neg*neg=neg
//so you can simply make an odd nth root of a negative number, a negative number
result = result*1;
}else if(neg){
//if the nth root is an even number that is not 2, things get more complex
//if someone wants to calculate this further, they can
//i'm just going to stop at *n√1 (times the nth root of 1)
//you should also check if the functions return value contains * or √, before continuing any calculations
result += '*'+n+√+'1';
}
return result;
}
answered Jul 24, 2019 at 20:29
I have written an algorithm but it is slow when you need many numbers after the point:
NRoot(orginal, nthRoot, base, numbersAfterPoint);
The function returns a string.
var original = 1000;
var fourthRoot = NRoot(original, 4, 10, 32);
console.log(fourthRoot);
//5.62341325190349080394951039776481
answered Aug 7, 2020 at 3:10
The ultra short version: const nthroot=(x,root)=>x**(1/root);
answered Mar 9 at 16:33
2 silver badges9 bronze badges
Input : A = 81 N = 4 Output : 3 3^4 = 81
according to newton’s method x(K+1) = x(K) – f(x) / f’(x) here f(x) = x^(N) – A so f’(x) = N*x^(N  1) and x(K) denoted the value of x at Kth iteration putting the values and simplifying we get, x(K + 1) = (1 / N) * ((N  1) * x(K) + A / x(K) ^ (N  1))
Using above relation, we can solve the given problem. In below code we iterate over values of x, until difference between two consecutive values of x become lower than desired accuracy.
Below is the implementation of above approach:
C++
using
namespace
std;
double
nthRoot(
int
A,
int
N)
double
xPre =
rand
() % 10;
double
eps = 1e3;
double
delX = INT_MAX;
while
(delX > eps)
xK = ((N  1.0) * xPre +
(
double
)A/
pow
(xPre, N1)) / (
double
)N;
delX =
abs
(xK  xPre);
xPre = xK;
int
N = 4;
int
A = 81;
double
nthRootValue = nthRoot(A, N);
cout <<
"Nth root is "
<< nthRootValue << endl;
Java
static
double
nthRoot(
int
A,
int
N)
double
xPre = Math.random() %
10
;
double
eps =
0.001
;
double
delX =
2147483647
;
double
xK =
0.0
;
while
(delX > eps)
xK = ((N 
1.0
) * xPre +
(
double
)A / Math.pow(xPre, N 
1
)) / (
double
)N;
delX = Math.abs(xK  xPre);
xPre = xK;
int
N =
4
;
int
A =
81
;
double
nthRootValue = nthRoot(A, N);
System.out.println(
"Nth root is "
Python3
xPre
=
random.randint(
1
,
101
)
%
10
eps
=
0.001
delX
=
2147483647
while
(delX > eps):
xK
=
((N

1.0
)
*
xPre
+
A
/
pow
(xPre, N

1
))
/
N
delX
=
abs
(xK

xPre)
xPre
=
xK;
A
=
81
nthRootValue
=
nthRoot(A, N)
print
(
"Nth root is "
, nthRootValue)
C#
static
double
nthRoot(
int
A,
int
N)
Random rand =
new
Random();
double
xPre = rand.Next(10);;
double
eps = 0.001;
double
delX = 2147483647;
double
xK = 0.0;
while
(delX > eps)
xK = ((N  1.0) * xPre +
(
double
)A / Math.Pow(xPre, N  1)) / (
double
)N;
delX = Math.Abs(xK  xPre);
xPre = xK;
static
void
Main()
int
N = 4;
int
A = 81;
double
nthRootValue = nthRoot(A, N);
Console.WriteLine(
"Nth root is "
+Math.Round(nthRootValue*1000.0)/1000.0);
PHP
function
nthRoot(
$A
,
$N
)
$xPre
= rand() % 10;
$eps
= 0.001;
$delX
= PHP_INT_MAX;
while
(
$delX
>
$eps
)
$xK
= ((int)(
$N
 1.0) *
$xPre
+
$A
/
$N
 1)) /
$N
;
$delX
=
abs
(
$xK

$xPre
);
$xPre
=
$xK
;
$N
= 4;
$A
= 81;
$nthRootValue
= nthRoot(
$A
,
$N
);
Javascript
function
nthRoot(A, N)
let xPre = Math.random() % 10;
let eps = 0.001;
let delX = 2147483647;
let xK = 0.0;
while
(delX > eps)
xK = ((N  1.0) * xPre +
A / Math.pow(xPre, N  1)) / N;
delX = Math.abs(xK  xPre);
xPre = xK;
let N = 4;
let A = 81;
let nthRootValue = nthRoot(A, N);
document.write(
"Nth root is "
+Math.round(nthRootValue*1000.0)/1000.0);
Time Complexity: O(log(eps)), where eps is the desired accuracy.
Space Complexity: O(1)
N^{th} root of unity is the root of unity when taken which on taking to the power n gives the value 1. N^{th} root of any number is defined as the number which on taking to the power of n results in the original number. For example, if we take n^{th} root of any number say a and the result is b, and then b is raised to n power will get a.
We define n^{th} root of any number as suppose we take n^{th} power of any number ‘a’
a^{n} = b
then, n^{th} root of ‘b’ is ‘a’ we represent this as,
^{n}√b = a
We can also check for n^{th} root of unity as,
z^{n} = 1
then, n^{th} root of ‘1‘ is ‘z‘ we represent this as,
^{n}√1 = z
In this article, we will learn about, n^{th} root of any number, n^{th} root o unity, and others in detail.
What is Nth Root?
We define n^{th} root of any number as the number which when taken to n^{th} power results in the original number, i.e.on multiplying the n^{th }of any number n times we get the original number.
We can mathematically express this as if n^{th} root of x is y then,
^{n}√x = y
⇒ y^{n} = x
This can also be represented as,
Example: Find the third root of 8
We know that,
2^{3} = 2×2×2 = 8
^{3}√8 = ^{3}√(2×2×2) = 2
Thus, the third root of 8 is 2
N^{th} Root Symbol
The n^{th} root of any number is represented using the symbol, ^{n}√x, here, we find the n^{th} root of x.
In the expression ^{n}√x, x is called the radicand of the term and n is the index of the term. We can also represent this as the exponent of x in fraction, i.e.
^{n}√x = (x)^{1/n}
Nth root of Unity
N^{th} root of unity is the specific case of n^{th} root of any number we define n^{th }root of unity as the number which when multiplying n times gives n. As we know for real numbers if any number is multiplied by 1 we get, the number itself, and 1 when multiplied by itself a finite number of times results in 1. Thus, in the case of real numbers the n^{th} root of unity is always 1 but, if we consider complex number things gets more interesting when we consider the complex number “i”, “ω” and other roots of unity comes to play.
Thus, we have various roots of unity. The solution to the equation,
z^{n} = 1
gives the n^{th} root of unity.
We can easily solve this equation using complex numbers.
How to Find n^{th} Root of Unity?
N^{th} root of unity can be easily found by finding the solution to the equation,
z^{n} = 1
In polar form, we write this equation as,
z^{n} = cos 0 + i sin 0
In general form,
z^{n} = cos (0+2mπ) + i sin (0+2mπ) (where m∈N)
Taking n^{th} root on both sides,
Using DeMoivre’s Theorem
This can be represented in Euler Form,
z = e^{(i2mπ/n)}
This is the n^{th} root of unity for m ∈ N
N^{th} Root of Unity in Complex Numbers
We know that the general form of a complex number is x + iy.
Comparing the n^{th} root of unity to a general complex number we get,
Squaring and adding (i) and (ii) we get,
x^{2} + y^{2} = cos^{2}(2mπ/n) + sin^{2}(2mπ/n) = 1
The above equation is the equation of the circle with the centre at origin (0,0) and radius 1.
If we represent the complex number as ω,
ω = e^{(i2mπ/n)}
Taking power n both sides,
(ω)^{n} = e^{(i2mπ/n)n}
⇒ ω^{n} = e^{i2mπ}
This gives the n^{th} root of unity taking n ≥ 0, we get the root of unity as,
These roots can be represented in a unit circle in a complex plane as,
Properties of Nth Root of unity
 N^{th} root of unity is the points on the circumference of the circle in the complex plane with the center on the origin and a radius of 1 unit.
 1 and 1 are the 2nd roots of unity.
 1, 1. i, and 1 are the 4th roots of unity.
 i = √(1) and i^{2} = 1, i^{4} = 1
 1, ω = (1/2 + i√(3)/2), ω^{2} =(1/2 – i√(3)/2) are the three roots of the unity.
 Multiplying two imaginary cube roots of unity results in 1.
 The sum of all three cube roots of unity, i.e.
1 + ω + ω^{2} = 0
 All the n^{th} roots of unity are in GP i.e. 1, ω^{2}, ω^{3}, ω^{4}, …., ω^{n1}, are in GP
 The product of all the roots of unity is,
Solved Examples on Nth Root
Example 1: Find ^{5}√(243)
As we know,
(3)^{5} = 243
Thus,^{5}√(243) = (3)^{5}
Thus, ^{5}√(243) = 3.
Example 2: Simplify ^{4}√(16x^{8})
As 16 = 2×2×2×2 = 2^{4}
Thus, ^{4}√(16x^{8}) = ^{4}√(2^{4}x^{8})
⇒ ^{4}√(16x^{8}) = 2^{4/4}x^{8/2}
⇒ ^{4}√(16x^{8}) = 2x^{2}
Example 3: Simplify ^{4}√(x^{24})
⇒ ^{4}√(x^{24}) = (1)^{1/4} ×(x^{24})^{1/4}
⇒ ^{4}√(x^{24}) = ix^{8}
FAQs on Nth Root
Q1: What is the n^{th} root?
The n^{th} root of unity is the number which when multiplied n times gives the original number. If the n^{th} root of unity is x^{1/n} = b, then
b^{n} = 1
Q2: What is a Square Root?
The square root of the number is the number which when multiplied by itself gives the original number. It is represented by the symbol √, Now the square root of (x) is represented as, √(x). For example, the square root of 4 is,
√(4) =√(2×2) = 2
Q3: What is a Cube Root?
The cube root of the number is the number which when multiplied by itself thrice gives the original number. It is represented by the symbol ^{3}√, Now the cube root of (x) is represented as, ^{3}√(x). For example, the cube root of 8 is,
√(8) = √(2×2×2) = 2
Q4: What are the Cube Roots of Unity?
Cube root of unity is the number which when multiplied with itself three times gives results as 1. We can represent this as,
^{3}√(1) = 1, ω, ω^{2}
Here, 1, ω, and ω^{2} are the cube root of unity.
Q5: What is the fourth root of unity?
Fourth root of unity is the number which when multiplied with itself four times gives results as 1. We can represent this as,
^{4}√(1) = 1, 1, i, i
Here, 1, 1, i, and i are the fourth roots of the unity.