Calculation of complex numbers with rational exponents

Yesterday I created this piece of code that could calculate z ^ n, where z is a complex number and n is any positive integer.

--snip-- float real = 0; float imag = 0; // d is the power the number is raised to [(x + yi)^d] for (int n = 0; n <= d; n++) { if (n == 0) { real += pow(a, d); } else { // binomial theorem switch (n % 4) { case 1: // i imag += bCo(d, n) * pow(a, d - n) * pow(b, n); break; case 2: // -1 real -= bCo(d, n) * pow(a, d - n) * pow(b, n); break; case 3: // -i imag -= bCo(d, n) * pow(a, d - n) * pow(b, n); break; case 0: // 1 real += bCo(d, n) * pow(a, d - n) * pow(b, n); break; } } } --snip-- int factorial(int n) { int total = 1; for (int i = n; i > 1; i--) { total *= i; } return total; } // binomial cofactor float bCo(int n, int k) { return (factorial(n)/(factorial(k) * factorial(n - k))); } 

I use the binomial theorem to extend z ^ n and I know whether to consider each term as a real or imaginary number, depending on the degree of the imaginary number.

What I want to do is compute z ^ n, where n is any positive real number (fractions). I know that the binomial theorem can be used for powers that are not integers, but I'm not sure how to handle complex numbers. Since I ^ 0.1 has a real and imaginary component, I canโ€™t just sort it in a real or imaginary variable, and I donโ€™t even know how to program something that could calculate it.

Does anyone know of an algorithm that can help me with this, or maybe even a better way to handle complex numbers that will make this possible?

Oh, I'm using java.

Thanks.

+4
source share
4 answers

Consider the complex number z such that z = x + iy .

Thus, the polar form z equals = re ^ itheta where:

  • r - value z or sqrt (x2 + y2) and
  • thetaatan y over x .

Once you do this, you can use DeMoivre's theorem to calculate z ^ n in the following way:

z ^ n = r ^ n e ^ i n theta

or more simply as

<T411>

For more information, read the polar form of the complex number .

+4
source

First of all, it can have several solutions. See Wikipedia: compound number / exponentiation .

Similar considerations show that we can define rational real powers in the same way as for real numbers, so z 1 / n is the root n: th of z. The roots are not unique, so itโ€™s already clear that complex powers are ambiguous, so careful processing of powers is required; for example, (8 1/3 ) 4 โ‰  16, since there are three cubic roots out of 8, so this expression is often reduced to 8 4/3 is the simplest.

I think you should break it into polar notation and go from there.

+7
source

I am not very good at math, so I probably misunderstood your task. But as I understand it - apache commons math can help you: http://commons.apache.org/math/userguide/complex.html

Example:

 Complex first = new Complex(1.0, 3.0); Complex second = new Complex(2.0, 5.0); Complex answer = first.log(); // natural logarithm. answer = first.cos(); // cosine answer = first.pow(second); // first raised to the power of second 
0
source

a ^ n is defined when n is not an integer and a is not a positive number.

If z is a complex number, you can still specify z ^ a = exp (log z), but you need to figure out what z means when z is not a positive number.

And there is no unique choice .

0
source

Source: https://habr.com/ru/post/1313605/


All Articles