/*************************************************** * Program to demonstrate the series * * inversion function * * ------------------------------------------------ * * 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: * * * * What is the degree of the input polynomial: 2 * * * * What is the degree of the inverted polynomial: 6 * * * * Input the polynomial coefficients: * * * * A( 0) = ? 1 * * A( 1) = ? .1 * * A( 2) = ? .01 * * * * The inverted polynomial coefficients are: * * * * B( 0) = 1.000000 * * B( 1) = -0.100000 * * B( 2) = 0.000000 * * B( 3) = 0.001000 * * B( 4) = -0.000100 * * B( 5) = 0.000000 * * B( 6) = 0.000001 * * * ***************************************************/ #include #include double A[10], B[10]; int i, m, n; /***************************************************** * Reciprocal power series procedure * * Reference: Computational analysis by Henrici * * -------------------------------------------------- * * The input series coefficients are A(i). The output * * series coefficients are B(i). The degree of the * * input polynomial is n. The degree of the inverted * * polynomial is m. The routine takes care of norma- * * lization using l = A(0). * *****************************************************/ void Reciprocal() { // Label used: e100 double l; int i,j; l = A[0]; for (i = 0; i < n+1; i++) { A[i] = A[i] / l; B[i] = 0.0; } // Clear arrays for (i = n + 1; i < m+1; i++) { A[i] = 0; B[i] = 0; } // Calculate the B(i) coefficients B[0] = 1; for (i = 1; i < m+1; i++) { j = 1; e100: B[i] = B[i] - A[j] * B[i - j]; j++; if (j <= i) goto e100; } // Un-normalize the A(i) and B(i) for (i = 0; i < m+1; i++) { A[i] = A[i] * l; B[i] = B[i] / l; } } void main() { printf("\n What is the degree of the input polynomial; "); scanf("%d",&n); printf("\n What is the degree of the inverted polynomial; "); scanf("%d",&m); printf("\n\n Input the polynomial coefficients;\n\n"); for(i = 0; i < n+1; i++) { printf(" A(%d) = ",i); scanf("%lf",&A[i]); } Reciprocal(); printf("\n The inverted polynomial coefficients are;\n\n"); for (i = 0; i < m+1; i++) printf(" B(%d) = %f\n",i,B[i]); printf("\n"); } // End of file recipro.cpp