c - GSL Polar Complex Numbers Appear to be extremely different -


using minunit.h test built-in gsl structs.

i have written following test:

static char * test_gsl_polar_complex_number_struct() {   double r = 0.325784;   double theta = 0.421329;    gsl_complex test_polr_complex_number = gsl_complex_polar ( r, theta );     printf("expected r: %f, actual r: %f\n", r, gsl_real(test_polr_complex_number));   mu_assert("real part of polar complex number not match expected",    gsl_real(test_polr_complex_number) == r);    return 0; } 

i getting failing test following output:

expected r: 0.325784, actual r: 0.297293 expected theta: 0.421329, actual theta: 0.133237 real part of polar complex number not match expected 

it of note exact same test executes without errors on rectangular complex struct.

you have wrong expectations. function gsl_complex_polar() initializes complex number components given in polar complex form:

this function returns complex number z = r \exp(i \theta) = r (\cos(\theta) + \sin(\theta)) polar representation (r,theta)

(gsl documentation)

that's fine, gsl_real() macro returns real part of complex number. that's not same thing r component of polar representation. in fact, docs quoted tell is: r cos(theta).


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -