/***************************************************** * Program to demonstrate complex series evaluation * * It is assumed that the coefficients are obtained * * from a subroutine. * * -------------------------------------------------- * * Reference: BASIC Scientific Subroutines, Vol. II * * By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * * * * C++ Version By J.-P. Moreau, Paris. * * (www.jpmoreau.fr) * * -------------------------------------------------- * * SAMPLE RUN: * * * * (Evaluate polynomial Z^5 + 5 Z^4 + 10 Z^3 + 10 Z^2 * * + 5 Z + 1 for complex argument Z=(1,0) ) * * * * Input the complex number as prompted: * * * * Real part = 1 * * Complex part = 0 * * * * Results are: * * * * Z1 = 32.000000 * * Z2 = 0.000000 * * * *****************************************************/ #include #include #define PI 4*atan(1) double A[6]; double u,u1,v,v1,x,y,z1,z2; int m,n; // Coefficients subroutine void Coeff() { m=5; A[0] = 1; A[1] = 5; A[2] = 10; A[3] = 10; A[4] = 5; A[5] = 1; } // Rectangular to polar conversion void RectPol() { u = sqrt(x*x+y*y); //Guard against ambiguous vector if (y==0.0) y = 1e-30; //Guard against divide by zero if (x==0.0) x = 1e-30; v = atan(y/x); if (x<0) v += PI; if (v<0) v += 2*PI; } // {Polar to rectangular conversion void PolRect() { x = u*cos(v); y = u*sin(v); } // Polar power void PolPower() { u1 = pow(u,n); v1 = n * v; v1 = v1 - 2*PI * int(v1/2.0/PI); } // Rectangular complex number power void RectPower() { // Rectangular to polar conversion RectPol(); // Polar power PolPower(); // Change variable for conversion u=u1 ; v=v1; // Polar to rectangular conversion PolRect(); } /******************************************************* * Complex series evaluation subroutine * * ---------------------------------------------------- * * The series coefficients are A(i), assumed real, the * * order of the polynomial is m. The subroutine uses * * repeated calls to the nth power (Z^N) complex number * * subroutine. Inputs to the subroutine are x, y, m and * * the A(i). Outputs are z1 (real) and z2 (imaginary). * *******************************************************/ void Complex_Series() { double a1, a2; z1 = A[0] ; z2 = 0.0; // Store x and y a1 = x ; a2 = y; for (n=1; n