X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



6829 Rate this article:
No rating

Finding the Nth Roots of a Real Number

This Help Article demonstrates how the FZ_ROOTS function can be used, and why it is preferable to using power notation, to find the Nth roots of a real number where N is a positive integer. The Help Article also provides a convenient wrapper function.

Discussion
Suppose IDL is being used to find a real root of a number. For example, examine the 5th roots of -1, which include (in complex form) (-1,0), (-0.309017, -0.951056), (-0.309017, 0.951057), (0.809017, -0.587786) and (0.809018, 0.587785). Using power notation:

        IDL> print, (-1)^(1./5)

IDL will return "-NaN" since it is unclear which of the five roots to return. One could argue that since IDL does not typically take a floating point value and return a complex number after an operation (unless it is expected as in the case of FFT), that IDL could assume the user expects a real result of -1. However this is still tricky since IDL doesn't actually "see" -1^(1/5). Instead, it "sees" -1^(0.2000000), and can not know to interpret this as simply (1/5).

The better method is to use the FZ_ROOTS function, which takes a polynomial over the real numbers and finds all of its roots (real and complex). Let's examine how this function can be used to find the Nth roots of a real number x, where N is a positive integer. Generally, this is the set of all complex numbers satisfying the equation

        y = x^(1/N)

which can be rewritten as the polynomial

        y^N - x = 0.

IDL's FZ_ROOTS routine requires the coefficient of each term in the polynomial, so the polynomial can be rewritten as

        1*y^N + 0*y^(N-1) + ... + 0*y - x = 0.

These coefficients can be placed into an (N+1)-element vector to get [1,0,0,...,0,x] which can then be passed to FZ_ROOTS to get back all the Nth roots of x.

So, to find the 5th roots of -1, the following polynomial equation will be used:

        y^5 - (-1) = 1*y^5 + 0*y^4 + 0*y^3 + 0*y^2 + 0*y + 1 = 0

to get the vector [1,0,0,0,0,1] to pass to FZ_ROOTS:

        IDL> print, fz_roots([1,0,0,0,0,1])

        (-1.00000, 0.000000) (-0.309017, -0.951056) (-0.309017, 0.951057)
    (0.809017, -0.587786) (0.809018, 0.587785)


Below is a convenient wrapper function that, given a real number x and an integer N, will construct the polynomial coefficient vector described above and then evaluate the Nth roots of x using FZ_ROOTS. The syntax for calling this function to print the Nth roots of x is:

        IDL> print, nth_roots(x, N)

Revisiting the example above, this gives:

        IDL> print, nth_roots(-1, 5)

        (-1.00000, 0.000000) (-0.309017, -0.951056) (-0.309017, 0.951057)
    (0.809017, -0.587786) (0.809018, 0.587785)

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »