Power of complex number

I need to take a complex number to a non integer power in some code I am writing and was wondering if there was a library out there that was capable of doing this. I have been deriving it myself to write the function but it is turning into a rather ugly math problem that would be convenient not to need to solve. My approach is basically to convert the normal a+i*b to the polar form A*e^(i*phi) raise that to a power then convert it back to Cartesian coordinates.

Thanks for any ideas.
If I'm not mistaken it's:

e^(i*x) = cos(x) + i*sin(x)

So, it also is:

[e^(i*x)]^y = e^(i*x*y) = cos(y*x) + i*sin(y*x)

Now, for cos, sin, exp (e^) etc include cmath (or math.h)

EDIT:
Basically, it's:

a + i*b = A*cos(u) + i*A*sin(u) (where u = arctan(b/a) and A=sqrt(a^2 + b^2) )

So, it also is:
(a + i*b)^y = [A*cos(u) + i*A*sin(u)]^y = (A^y)*cos(y*u) + i*(A^y)*sin(y*u) = a' + i*b'

And now find a' and b' from:
(1) (a')^2 + (b')^2 = (A^y)^2 = A^(2*y)
(2) tan(y*u)=b'/a'

(you can also find tan and arctan in cmath/math.h)
Last edited on
Thank you for your response, I was able to solve it. Part of the reason I was asking is that libraries often times have this sort of thing optimized better than I can do by hand as a non computer science phd (EG: any sort of BLAS or FFT library). And every operation counts when you are using this on a large dataset. Anyway here is the formula for anyone else with the same problem.

for (a+i*b)^n
Real component = (a^2+b^2)^(n/2)*cos(n*arctan(b/a))
Imaginary component =(a^2+b^2)^(n/2)*sin(n*arctan(b/a))

(Note: only use this when you need non integer exponents, the integer exponent solution is much faster)
Last edited on
Topic archived. No new replies allowed.