nthroot

Real n-th root of a real number.

Category: Mathematics > Elementary Math

Syntax

Y = nthroot(X, n)

Returns the real n-th root of each element of X.

Description

The expression x^(1/3) returns a complex number for negative x, because it takes the principal complex root. nthroot(x, 3) instead returns the real cube root, so nthroot(-27, 3) is -3. An even root of a negative number has no real value.

Use it whenever a real answer is wanted from an odd root, and ^ or sqrt when the complex principal value is fine.

Input arguments

X
Real array.
n
Nonzero integer-valued scalar or array of a compatible size. A negative value gives the reciprocal root.

Output arguments

Y
Real array.

Example

Real cube root of a negative number

nthroot(-27, 3)
(-27)^(1/3)
nthroot([8 16], [3 4])
Output
ans = -3
ans = 1.5000 + 2.5981i
ans = 1×2

     2     2

See also

sqrt realsqrt power exp log