Computer Science Canada

Complex power to real number

Author:  Saad [ Sat Jun 16, 2007 2:33 pm ]
Post subject:  Complex power to real number

I've been working on my own complex number class but ive come to encountered 1 problem.
Does anyone know how to calculate a complex number raised to a power of a real number?

ie z = (a+bi)^x

where x = real power and z = new complex number

Saad

Author:  PaulButler [ Sat Jun 16, 2007 6:14 pm ]
Post subject:  RE:Complex power to real number

You can use de Moivre's formula.

Just know that with a real power, you may (will?) find two values for z.

If I remember correctly (and I hope I do, because I have an exam on this next week Neutral ), it goes something like this:

c++:

float r, i; // real, imaginary components of base
float p; // power
// convert to polar form
float t, b; // angle, distance from (0, 0)
b = sqrt((r * r) + (i * i)); // Pythagorean theorem
t = arctan(i / r); // assuming range of (-pi / 2, pi / 2) for arctan
if(r < 0){
  t = pi - t;
}
if(i < 0){
  t = (2 * pi) - t;
}
// raise to power
t = t * p;
b = pow(b,  p);
// if there is more than one value, I think you could just take -b here and do the same stuff with it that is done below to get it the other
// put back in rectangular form
r = b * cos(t);
i = b * sin(t);


I really have a feeling that I made a mistake or two so that code could use some testing before it gets any use, but it should at least demonstrate how it works.


: