maxemilian
maxemilian

Reputation: 414

Negative complex exponentiation

I want to calculate complex number angles and magnitude and I good with them

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>

double pi = 4 * atan(1.0);

int main() {
    double complex z = cexp(I * -1 * pi * 1.2 - 1);
    printf("%f + %f * i\n", creal(z), cimag(z));

    double complex base = clog(z);
    printf("%f + %f * i\n", creal(base), cimag(base));
 
    double arg = carg(base);
    printf(" Angle of z in radian %f and as degree %f \n", arg, arg * 180 / pi);

    double magnitude = cabs(base);
    printf("Magnitude of z %f \n", magnitude);

    return 0;
}

this program prints

-0.297621 + 0.216234 * i
-1.000000 + 2.513274 * i
 Angle of z in radian 1.949480 and as degree 111.696984 
Magnitude of z 2.704912

But, This result don't have negative imaginary component. But all complex numbers have positive one. How can I get a value at the third quadrant of the complex plane?

Upvotes: 2

Views: 165

Answers (1)

tstanisl
tstanisl

Reputation: 14157

Take a look on cexp(I * -1*pi*1.2-1). The angle is -1.2*pi what is equivalent to -1.2pi + 2*pi = 0.8pi. This angle is pointing into the second quadrant where real part is negative and imaginary part is positive.

0.8 * pi ~= 2.51327412287

As in value of clog(z) from your example. Everything works fine. Some intuitive explanation why positive angles become negative is following example:

Turning 200 degrees right will place you in the same orientation as turning -160 degrees right.

To get a number in the 3rd quadrant the angle must between (pi ... 1.5 pi) plus 2kpi where k is arbitrary integer number. Try 1.2 * pi.

-0.297621 + -0.216234 * i
-1.000000 + -2.513274 * i
 Angle of z in radian -1.949480 and as degree -111.696984 
Magnitude of z 2.704912 

Upvotes: 2

Related Questions