/* cheb/test.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include double f_T0 (double x, void * p) { p = 0; return 1.0; } double f_T1 (double x, void * p) { p = 0; return x; } double f_T2 (double x, void * p) { p = 0; return 2*x*x - 1; } double f_sin (double x, void * p) { p = 0; return sin(x); } double f_DP (double x, void * p) { p = 0; return 2.0; } double f_P (double x, void * p) { p = 0; return 2.0*x + 3.0; } double f_IP1 (double x, void * p) { p = 0; return 30*(x+5.0)/10.0; /* first order approximation to integral over -5,5 */ } double f_IP2 (double x, void * p) { p = 0; return x*x + 3*x - 10.0; } void test_dim (const size_t n, const double a, const double b, gsl_function * F, gsl_function * DF, gsl_function *IF) { double tol = 100.0 * GSL_DBL_EPSILON; double x; gsl_cheb_series * cs = gsl_cheb_alloc(n); gsl_cheb_series * csd = gsl_cheb_alloc(n); gsl_cheb_series * csi = gsl_cheb_alloc(n); gsl_cheb_init(cs, F, a, b); for(x=a; xc, "gsl_cheb_coeffs"); } for (i = 0; iorder; i++) { double c_exp = (i == 0) ? 2.0 : 0.0; gsl_test_abs (cs->c[i], c_exp, tol, "c[%d] for T_0(x)", i); } gsl_cheb_init(cs, &F_T1, -1.0, 1.0); for (i = 0; iorder; i++) { double c_exp = (i == 1) ? 1.0 : 0.0; gsl_test_abs (cs->c[i], c_exp, tol, "c[%d] for T_1(x)", i); } gsl_cheb_init(cs, &F_T2, -1.0, 1.0); for (i = 0; iorder; i++) { double c_exp = (i == 2) ? 1.0 : 0.0; gsl_test_abs (cs->c[i], c_exp, tol, "c[%d] for T_2(x)", i); } gsl_cheb_init(cs, &F_sin, -M_PI, M_PI); gsl_test_abs (cs->c[0], 0.0, tol, "c[0] for F_sin(x)"); gsl_test_abs (cs->c[1], 5.69230686359506e-01, tol, "c[1] for F_sin(x)"); gsl_test_abs (cs->c[2], 0.0, tol, "c[2] for F_sin(x)"); gsl_test_abs (cs->c[3], -6.66916672405979e-01, tol, "c[3] for F_sin(x)"); gsl_test_abs (cs->c[4], 0.0, tol, "c[4] for F_sin(x)"); gsl_test_abs (cs->c[5], 1.04282368734237e-01, tol, "c[5] for F_sin(x)"); for(x=-M_PI; x