Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple roots in the complex plane with R

I've been trying to find a function that returns all complex solutions of an equation such as:

16^(1/4) = 2+i0,  -2+i0,  0+i2,  0-i2

As it stands, if I enter 16^(1/4) into the console, it only returns 2. I can write a function for this but I was wondering if there is a simple way to do this in R.

like image 765
N8TRO Avatar asked Feb 19 '13 20:02

N8TRO


People also ask

How do you find all complex roots?

We can find the roots of complex numbers easily by taking the root of the modulus and dividing the complex numbers' argument by the given root. This means that we can easily find the roots of different complex numbers and equations with complex roots when the complex numbers are in polar form.

What is complex roots in complex numbers?

Complex roots are the imaginary root of quadratic or polynomial functions. These complex roots are a form of complex numbers and are represented as α = a + ib, and β = c + id. The quadratic equation having a discriminant value lesser than zero (D<0) have imaginary roots, which are represented as complex numbers.

What are the roots of a complex function?

You will see that there are roots, but they are not x -intercepts because the function does not contain (x,y) pairs that are on the x -axis. We call these complex roots. By setting the function equal to zero and using the quadratic formula to solve, you will see that the roots are complex numbers.


1 Answers

You need polyroot():

polyroot(z = c(-16,0,0,0,1))
# [1]  0+2i -2-0i  0-2i  2+0i

Where z is a "vector of polynomial coefficients in increasing order".

The vector I passed to z in the example above is a compact representation of this equation:

-16x^0 + 0x^1 + 0x^2 + 0x^3 + 1x^4 = 0

                          x^4 - 16 = 0

                               x^4 = 16

                                 x = 16^(1/4)

Edit:

If polyroot's syntax bothers you, you just could write a wrapper function that presents you with a nicer (if less versatile) interface:

nRoot <- function(x, root) {
    polyroot(c(-x, rep(0, root-1), 1))
}
nRoot(16, 4)
# [1]  0+2i -2-0i  0-2i  2+0i
nRoot(16, 8)
# [1]  1.000000+1.000000i -1.000000+1.000000i -1.000000-1.000000i
# [4]  1.000000-1.000000i  0.000000+1.414214i -1.414214-0.000000i
# [7]  0.000000-1.414214i  1.414214+0.000000i
like image 190
Josh O'Brien Avatar answered Sep 28 '22 00:09

Josh O'Brien