Documentation

nthroot

Nth root of symbolic numbers

Description

example

y = nthroot(x,n) returns the nth root of x with the phase angle closest to the phase of x. The output y has symbolic data type if any input argument is symbolic. The variables satisfy y.^n = x.

Examples

collapse all

Calculate the nth root of a negative number.

x = sym(-27);
n = -3;
y = nthroot(x,n)
y =

$-\frac{1}{3}$

Check that the answer solves the equation ${y}^{n}=x$.

y^n
ans = $-27$

Calculate the nth root of a complex number.

x = sym(1 + 1i);
y = nthroot(x,4)
y = ${\left(1+\mathrm{i}\right)}^{1/4}$

Find a numeric equivalent of the root.

vpa(y)
ans = $1.0695539323639858023756790408254+0.2127475047267430357507130792184 \mathrm{i}$

Check that the answer solves the equation ${y}^{n}=x$.

y^4
ans = $1+\mathrm{i}$

Calculate the nth roots of an array.

x = sym([-27,-8,-4
27,64,-12])
x =

$\left(\begin{array}{ccc}-27& -8& -4\\ 27& 64& -12\end{array}\right)$

n = sym([3,3,4
3,2,-2])
n =

$\left(\begin{array}{ccc}3& 3& 4\\ 3& 2& -2\end{array}\right)$

y = nthroot(x,n)
y =

$\left(\begin{array}{ccc}-3& -2& {\left(-1\right)}^{3/4} {4}^{1/4}\\ 3& 8& -\frac{\sqrt{12} \mathrm{i}}{12}\end{array}\right)$

Check that the answer solves the equation ${y}^{n}=x$.

y.^n
ans =

$\left(\begin{array}{ccc}-27& -8& -4\\ 27& 64& -12\end{array}\right)$

Use nthroot in further symbolic calculations.

syms x
y = solve(nthroot(x,-3) == -3, x)
y =

$-\frac{1}{27}$

syms x n
y = diff(nthroot(x,n),x)
y =

$\frac{\sqrt[n]{x}}{n x}$

Input Arguments

collapse all

Input array for taking root, specified as a symbolic or numeric array. When taking the root, the function acts element-wise.

If both x and n are nonscalar arrays, they must have the same size. If any element of x or n is symbolic and some elements are numeric, nthroot converts numeric arguments to symbolic before processing.

Example: [sym(-8),sym(8);sym(-27),sym(27)]

Input array for order of root, specified as a symbolic array or real array.

• If an element of x is not real and positive, meaning it is either negative or has a nonzero imaginary part, then the corresponding element of n must be a nonzero integer.

• If an element of x is real and positive, then the corresponding element of n can have any nonzero real value.

If both x and n are nonscalar arrays, they must have the same size. If any element of x or n are symbolic and some elements are numeric, nthroot converts numeric arguments to symbolic before processing.

Example: sym(-3)