Real nth root of real numbers (2024)

Real nth root of real numbers

collapse all in page

Syntax

Y = nthroot(X,N)

Description

example

Y = nthroot(X,N) returns the real nth root of X. If an element in X is negative, then the corresponding element in N must be an odd integer.

Examples

collapse all

Real Root of Negative Number

Open Live Script

Find the real cube root of -27.

nthroot(-27,3)
ans = -3

For comparison, calculate (-27)^(1/3). The result is the complex cube root of -27.

(-27)^(1/3)

Real Roots of Scalar

Open Live Script

Calculate several real nth roots of -8.

N = [5 3 -1];Y = nthroot(-8,N)
Y = 1×3 -1.5157 -2.0000 -0.1250

Real Roots of Vector

Open Live Script

Create a row vector of bases, X, and a column vector of roots to calculate, N.

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

Calculate the real nth roots of the elements in X. The result is a matrix containing all combinations of bases and roots. For example, Y(3,1) is the 3rd root of 4.

Y = nthroot(X,N)
Y = 3×3 4.0000 -3.0000 -5.0000 0.2500 -0.3333 -0.2000 1.5874 -1.4422 -1.7100

Element-Wise Roots of Matrix

Open Live Script

Create a matrix of bases, X, and a matrix of roots to calculate, N. Each element in X corresponds to an element in N.

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

Calculate the real nth roots of the elements in X.

Y = nthroot(X,N)
Y = 2×3 -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

XInput array
scalar | vector | matrix | multidimensional array | table | timetable

Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable. The elements of X must be real. Inputs X and N must either be the same size or have sizes that are compatible.

Data Types: single | double | table | timetable

NRoots to calculate
scalar | vector | matrix | multidimensional array | table | timetable

Roots to calculate, specified as a scalar, vector, matrix, multidimensional array, table, or timetable. The elements of N must be real. If an element in X is negative, the corresponding element in N must be an odd integer. Inputs X and N must either be the same size or have sizes that are compatible.

  • If X is a multidimensional array, N cannot be a table or timetable.

  • If X is a table or timetable, then N can be the same data type as X or a scalar, vector, matrix, or multidimensional array of a compatible size. If both inputs are tables or timetables, then see Rules for Table and Timetable Mathematics for the input requirements.

Data Types: single | double | table | timetable

Tips

  • While power is a more efficientfunction for computing the roots of numbers, in cases where both realand complex roots exist, power returns only thecomplex roots. In these cases, use nthroot to obtainthe real roots.

Extended Capabilities

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

The nthroot function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.

See Also

sqrt | power

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Real nth root of real numbers (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Real nth root of real numbers (2024)
Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 5999

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.