# include # include # include # include "chebyshev_series.h" int main ( ); void test01 ( ); void test02 ( ); void test03 ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for CHEBYSHEV_SERIES_TEST. Discussion: CHEBYSHEV_SERIES_TEST tests the CHEBYSHEV_SERIES library. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 April 2014 Author: Manfred Zimmer */ { timestamp (); printf ( "\n" ); printf ( "CHEBYSHEV_SERIES_TEST:\n" ); printf ( " C version\n" ); printf ( " Test the CHEBYSHEV_SERIES libary.\n" ); test01 ( ); test02 ( ); test03 ( ); /* Terminate. */ printf ( "\n" ); printf ( "CHEBYSHEV_SERIES_TEST:\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp (); return 0; } /******************************************************************************/ void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 considers an even Chebyshev series for EXP(X). Discussion: Table 5 is from Clenshaw, and contains 18 terms of the Chebyshev series for exp(x) over [-1,+1]. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 April 2014 Author: Manfred Zimmer Reference: Charles Clenshaw, Mathematical Tables, Volume 5, Chebyshev series for mathematical functions, London, 1962. */ { int i; double s; double s1; double s2; double s3; double table5[18] = { 2.53213175550401667120, 1.13031820798497005442, 0.27149533953407656237, 0.04433684984866380495, 0.00547424044209373265, 0.00054292631191394375, 0.00004497732295429515, 0.00000319843646240199, 0.00000019921248066728, 0.00000001103677172552, 0.00000000055058960797, 0.00000000002497956617, 0.00000000000103915223, 0.00000000000003991263, 0.00000000000000142376, 0.00000000000000004741, 0.00000000000000000148, 0.00000000000000000004 }; double x; double y; printf ( "\n" ); printf ( "TEST01:\n" ); printf ( " ECHEBSER3 computes a Chebyshev series approximation\n" ); printf ( " and the first three derivatives.\n" ); printf ( "\n" ); printf ( " Errors of a Chebyshev series for exp(x)\n" ); printf ( "\n" ); printf ( " x err(y) err(y') err(y\") err(y\"')\n" ); printf ( "\n" ); for ( i = -10; i <= 10; i++ ) { x = ( double ) i / 10.0; s = echebser3 ( x, table5, 18, &s1, &s2, &s3 ); y = exp ( x ); s = s - y; s1 = s1 - y; s2 = s2 - y; s3 = s3 - y; printf ( "%7.4f %14g %14g %14g %14g\n", x, s, s1, s2, s3 ); } return; } /******************************************************************************/ void test02 ( ) /******************************************************************************/ /* Purpose: TEST02 considers an even Chebyshev series for COS(PI*X/2). Discussion: TABLE1 contains the even Chebyshev series coefficients for cos(pi*x/2) over [-1,+1]. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 April 2014 Author: Manfred Zimmer Reference: Charles Clenshaw, Mathematical Tables, Volume 5, Chebyshev series for mathematical functions, London, 1962. */ { int i; double s; double s1; double s2; double table1[11] = { +0.94400243153646953490, -0.49940325827040708740, +0.02799207961754761751, -0.00059669519654884650, +0.00000670439486991684, -0.00000004653229589732, +0.00000000021934576590, -0.00000000000074816487, +0.00000000000000193230, -0.00000000000000000391, +0.00000000000000000001 }; double x; double y; double y1; double y2; printf ( "\n" ); printf ( "TEST02:\n" ); printf ( " EVENCHEBSER2 computes an even Chebyshev series\n" ); printf ( " and its first two derivatives.\n" ); printf ( "\n" ); printf ( " Errors of an even Chebyshev series for cos(pi*x/2):\n" ); printf ( "\n" ); printf ( " x err(y) err(y') err(y\")\n" ); printf ( "\n" ); for ( i = 0; i <= 10; i++ ) { x = ( double ) i / 10.0; s = evenchebser2 ( x, table1, 11, &s1, &s2 ); y = cos ( M_PI_2 * x ); y1 = sin ( M_PI_2 * x ); y1 = - y1 * M_PI_2; y2 = - y * ( M_PI_2 * M_PI_2 ); s = s - y; s1 = s1 - y1; s2 = s2 - y2; printf ( "%7.4f %14g %14g %14g\n", x, s, s1, s2 ); } return; } /******************************************************************************/ void test03 ( ) /******************************************************************************/ /* Purpose: TEST03 considers an odd Chebyshev series for SINH(X). Discussion: TABLE5ODD contains the odd Chebyshev series coefficients for sinh(x) over -1 <= x <= 1. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 April 2014 Author: Manfred Zimmer Reference: Charles Clenshaw, Mathematical Tables, Volume 5, Chebyshev series for mathematical functions, London, 1962. */ { int i; double s; double s1; double s2; double table5odd[9] = { 1.13031820798497005442, 0.04433684984866380495, 0.00054292631191394375, 0.00000319843646240199, 0.00000001103677172552, 0.00000000002497956617, 0.00000000000003991263, 0.00000000000000004741, 0.00000000000000000004 }; double x; double y; double y1; printf ( "\n" ); printf ( "TEST03:\n" ); printf ( " ODDCHEBSER2 computes an odd Chebyshev series approximation.\n" ); printf ( " and its first two derivatives.\n" ); printf ( "\n" ); printf ( " Errors of an odd Chebyshev series y(x) approximating sinh(x):\n" ); printf ( "\n" ); printf ( " x err(y) err(y') err(y\")\n" ); printf ( "\n" ); for ( i = 0; i <= 10; i++ ) { x = ( double ) ( i ) / 10.0; s = oddchebser2 ( x, table5odd, 9, &s1, &s2 ); y = sinh ( x ); y1 = cosh ( x ); s = s - y; s1 = s1 - y1; s2 = s2 - y; printf ( "%7.4f %14g %14g %14g\n", x, s, s1, s2 ); } return; }