3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <gsl/gsl_math.h>
23 #include <gsl/gsl_errno.h>
24 #include <gsl/gsl_chebyshev.h>
26 /*-*-*-*-*-*-*-*-*-*-*-* Allocators *-*-*-*-*-*-*-*-*-*-*-*/
29 gsl_cheb_alloc(const size_t order)
31 gsl_cheb_series * cs = (gsl_cheb_series *) malloc(sizeof(gsl_cheb_series));
34 GSL_ERROR_VAL("failed to allocate gsl_cheb_series struct", GSL_ENOMEM, 0);
40 cs->c = (double *) malloc((order+1) * sizeof(double));
43 GSL_ERROR_VAL("failed to allocate cheb coefficients", GSL_ENOMEM, 0);
46 cs->f = (double *) malloc((order+1) * sizeof(double));
49 GSL_ERROR_VAL("failed to allocate cheb function space", GSL_ENOMEM, 0);
56 void gsl_cheb_free(gsl_cheb_series * cs)
63 /*-*-*-*-*-*-*-*-*-*-*-* Initializer *-*-*-*-*-*-*-*-*-*-*-*/
65 int gsl_cheb_init(gsl_cheb_series * cs, const gsl_function *func,
66 const double a, const double b)
71 GSL_ERROR_VAL("null function interval [a,b]", GSL_EDOM, 0);
78 double bma = 0.5 * (cs->b - cs->a);
79 double bpa = 0.5 * (cs->b + cs->a);
80 double fac = 2.0/(cs->order +1.0);
82 for(k = 0; k<=cs->order; k++) {
83 double y = cos(M_PI * (k+0.5)/(cs->order+1));
84 cs->f[k] = GSL_FN_EVAL(func, (y*bma + bpa));
87 for(j = 0; j<=cs->order; j++) {
89 for(k = 0; k<=cs->order; k++)
90 sum += cs->f[k]*cos(M_PI * j*(k+0.5)/(cs->order+1));