%% Calculate Nth Roots
% Calculate the nth root of a negative number.

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

% Check that the answer solves the equation y^n=x.

y^n

%
% Calculate the nth root of a complex number.

x = sym(1 + 1i);
y = nthroot(x,4)

% Find a numeric equivalent of the root.

vpa(y)

% Check that the answer solves the equation y^n=x.

y^4

%
% Calculate the nth roots of an array.

x = sym([-27,-8,-4
    27,64,-12])
n = sym([3,3,4
    3,2,-2])
y = nthroot(x,n)

% Check that the answer solves the equation y^n=x.

y.^n

%
% Use nthroot in further symbolic calculations.

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

%
% Copyright 2018 The MathWorks, Inc.