F
fgg
Hi,
I'm doing some calculations involving complex numbers, but I'm not
getting the expected results. Does anyone see any problem with the
function below? Maybe there's nothing wrong with it (I could just be
using the wrong value for the parameter "x", for example). Just wanted
to make sure I'm doing it the right way.
All I need is to find the real and imaginary parts of the resulting
complex number, and compute amplitude and phase. e.g.
z = coherence(20, 0.16, 320);
printf("coherence = %g + %g * i\n", creal(z), cimag(z));
printf("amplitude = %.4f\n", cabs(z));
printf("phase = %.4f\n", carg(z));
/* function */
complex coherence(double a, double b, double c)
{
complex num, den;
double x;
num = x * b * cexp(I * c) * cexp(I * a) * exp(a * b) - 1;
den = (exp(a * b) - 1) * (I + b);
return num/den;
}
Thanks in advance!
I'm doing some calculations involving complex numbers, but I'm not
getting the expected results. Does anyone see any problem with the
function below? Maybe there's nothing wrong with it (I could just be
using the wrong value for the parameter "x", for example). Just wanted
to make sure I'm doing it the right way.
All I need is to find the real and imaginary parts of the resulting
complex number, and compute amplitude and phase. e.g.
z = coherence(20, 0.16, 320);
printf("coherence = %g + %g * i\n", creal(z), cimag(z));
printf("amplitude = %.4f\n", cabs(z));
printf("phase = %.4f\n", carg(z));
/* function */
complex coherence(double a, double b, double c)
{
complex num, den;
double x;
num = x * b * cexp(I * c) * cexp(I * a) * exp(a * b) - 1;
den = (exp(a * b) - 1) * (I + b);
return num/den;
}
Thanks in advance!