/*************************************************** * Program to demonstrate Cheby_Ser() 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: * * * * Chebyshev polynomial coefficients for degree 2 * * A(0) = -1 * * A(1) = 0 * * A(2) = 2 * * * * Chebyshev polynomial coefficients for degree 3 * * A(0) = 0 * * A(1) = -3 * * A(2) = 0 * * A(3) = 4 * * * * Chebyshev polynomial coefficients for degree 4 * * A(0) = 1 * * A(1) = 0 * * A(2) = -8 * * A(3) = 0 * * A(4) = 8 * * * * Chebyshev polynomial coefficients for degree 5 * * A(0) = 0 * * A(1) = 5 * * A(2) = 0 * * A(3) = -20 * * A(4) = 0 * * A(5) = 16 * * * * Chebyshev polynomial coefficients for degree 6 * * A(0) = -1 * * A(1) = 0 * * A(2) = 18 * * A(3) = 0 * * A(4) = -48 * * A(5) = 0 * * A(6) = 32 * * * * Chebyshev polynomial coefficients for degree 7 * * A(0) = 0 * * A(1) = -7 * * A(2) = 0 * * A(3) = 56 * * A(4) = 0 * * A(5) = -112 * * A(6) = 0 * * A(7) = 64 * * * * Chebyshev polynomial coefficients for degree 8 * * A(0) = 1 * * A(1) = 0 * * A(2) = -32 * * A(3) = 0 * * A(4) = 160 * * A(5) = 0 * * A(6) = -256 * * A(7) = 0 * * A(8) = 128 * * * * Chebyshev polynomial coefficients for degree 9 * * A(0) = 0 * * A(1) = 9 * * A(2) = 0 * * A(3) = -120 * * A(4) = 0 * * A(5) = 432 * * A(6) = 0 * * A(7) = -576 * * A(8) = 0 * * A(9) = 256 * * * * Chebyshev polynomial coefficients for degree 10 * * A(0) = -1 * * A(1) = 0 * * A(2) = 50 * * A(3) = 0 * * A(4) = -400 * * A(5) = 0 * * A(6) = 1120 * * A(7) = 0 * * A(8) = -1280 * * A(9) = 0 * * A(10) = 512 * * * ***************************************************/ #include #include #define SIZE 10 double B[SIZE+1][SIZE+1]; int i, n; /******************************************************* * Chebyshev series coefficients evaluation subroutine * * ---------------------------------------------------- * * The order of the polynomial is n. The coefficients * * are returned in the array B[i,j), i is the degree of * * the polynomial, j is the coefficient order. * *******************************************************/ void Cheby_Ser() { int i, j; // Establish t0 and t1 coefficients B[0][0] = 1; B[1][0] = 0; B[1][1] = 1; // Return if order is less than two if (n < 2) return; for (i = 2; i < n+1; i++) { for (j = 1; j < i+1; j++) // Basic recursion relation B[i][j] = 2 * B[i - 1][j - 1] - B[i - 2][j]; B[i][0] = -B[i - 2][0]; } } void main() { printf("\n"); for (n = 2; n < SIZE+1; n++) { Cheby_Ser(); printf(" Chebyshev polynomial coefficients for degree %d\n\n",n); for (i = 0; i < n+1; i++) printf(" A(%d) = %5.0f\n",i,B[n][i]); if (n < SIZE) getchar(); } printf("\n"); } // End of file chebyser.cpp