home *** CD-ROM | disk | FTP | other *** search
- ntrtcx(a,b,n,c,d)
-
- /* subroutine to determine the nth roots of a complex number. */
-
- int n;
- float a,b,c[],d[];
-
- {
- int ak,jn,k,l,p,zn;
- float s,sx,theta,x,z;
- double pi,pi2;
- extern double atan(),cos(),pow(),sin(),sqrt();
-
- p = n;
- s = 0.0;
- pi = 3.141592653589796;
- pi2 = pi * 2;
- if(n < 1)
- {
- c[0] = 0.0;
- d[0] = 0.0;
- return;
- }
- if(n == 1)
- {
- c[0] = a;
- d[0] = b;
- return;
- }
- theta = atan(b/a);
- if(a < 0.) theta = theta + pi;
- theta = theta/p;
- s = sqrt(a*a + b*b);
- x = 1.0/p;
- sx = pow(s,x);
- c[0] = sx * cos(theta);
- d[0] = sx * sin(theta);
- jn = n - 1;
-
- for(k = 1; k <= jn; k++)
- {
- ak = k;
- z = theta + (2.0 * ak * pi)/p;
- zn = z/pi2;
- z = z-(zn*pi2);
- c[k] = sx * cos(z);
- d[k] = sx * sin(z);
- }
- }