Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

nthroot

Real nth root of real numbers

Syntax

Description

example

Y = nthroot(X,N) returns the real nth root of the elements of X. Both X and N must be real scalars or arrays of the same size. If an element in X is negative, then the corresponding element in N must be an odd integer.

Examples

collapse all

Find the real cube root of -27.

nthroot(-27, 3)
ans =

    -3

For comparison, also calculate (-27)^(1/3).

(-27)^(1/3)
ans =

   1.5000 + 2.5981i

The result is the complex cube root of -27.

Create a vector of roots to calculate, N.

N = [5 3 -1];

Use nthroot to calculate several real roots of -8.

Y = nthroot(-8,N)
Y =

   -1.5157   -2.0000   -0.1250

The result is a vector of the same size as N.

Create a matrix of bases, X, and a matrix of nth roots, N.

X = [-2 -2 -2; 4 -3 -5]
N = [1 -1 3; 1/2 5 3]
X =

    -2    -2    -2
     4    -3    -5


N =

    1.0000   -1.0000    3.0000
    0.5000    5.0000    3.0000

Each element in X corresponds to an element in N.

Calculate the real nth roots of the elements in X.

Y = nthroot(X,N)
Y =

   -2.0000   -0.5000   -1.2599
   16.0000   -1.2457   -1.7100

Except for the signs (which are treated separately), the result is comparable to abs(X).^(1./N). By contrast, you can calculate the complex roots using X.^(1./N).

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. X can be either a scalar or an array of the same size as N. The elements of X must be real.

Data Types: single | double

Roots to calculate, specified as a scalar or array of the same size as X. The elements of N must be real. If an element in X is negative, the corresponding element in N must be an odd integer.

Data Types: single | double

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Tips

  • While power is a more efficient function for computing the roots of numbers, in cases where both real and complex roots exist, power returns only the complex roots. In these cases, use nthroot to obtain the real roots.

See Also

|

Introduced before R2006a


Was this topic helpful?