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 /* For efficiency there are separate implementations of each of these
30 gsl_cheb_eval (const gsl_cheb_series * cs, const double x)
36 double y = (2.0 * x - cs->a - cs->b) / (cs->b - cs->a);
39 for (i = cs->order; i >= 1; i--)
42 d1 = y2 * d1 - d2 + cs->c[i];
46 return y * d1 - d2 + 0.5 * cs->c[0];
50 gsl_cheb_eval_n (const gsl_cheb_series * cs, const size_t n, const double x)
56 size_t eval_order = GSL_MIN (n, cs->order);
58 double y = (2.0 * x - cs->a - cs->b) / (cs->b - cs->a);
61 for (i = eval_order; i >= 1; i--)
64 d1 = y2 * d1 - d2 + cs->c[i];
68 return y * d1 - d2 + 0.5 * cs->c[0];
73 gsl_cheb_eval_err (const gsl_cheb_series * cs, const double x,
74 double *result, double *abserr)
80 double y = (2. * x - cs->a - cs->b) / (cs->b - cs->a);
85 for (i = cs->order; i >= 1; i--)
88 d1 = y2 * d1 - d2 + cs->c[i];
92 *result = y * d1 - d2 + 0.5 * cs->c[0];
94 /* Estimate cumulative numerical error */
96 for (i = 0; i <= cs->order; i++)
98 absc += fabs(cs->c[i]);
101 /* Combine truncation error and numerical error */
103 *abserr = fabs (cs->c[cs->order]) + absc * GSL_DBL_EPSILON;
109 gsl_cheb_eval_n_err (const gsl_cheb_series * cs,
110 const size_t n, const double x,
111 double *result, double *abserr)
117 double y = (2. * x - cs->a - cs->b) / (cs->b - cs->a);
122 size_t eval_order = GSL_MIN (n, cs->order);
124 for (i = eval_order; i >= 1; i--)
127 d1 = y2 * d1 - d2 + cs->c[i];
131 *result = y * d1 - d2 + 0.5 * cs->c[0];
133 /* Estimate cumulative numerical error */
135 for (i = 0; i <= eval_order; i++)
137 absc += fabs(cs->c[i]);
140 /* Combine truncation error and numerical error */
142 *abserr = fabs (cs->c[eval_order]) + absc * GSL_DBL_EPSILON;
148 gsl_cheb_eval_mode_e (const gsl_cheb_series * cs,
149 const double x, gsl_mode_t mode,
150 double *result, double *abserr)
156 double y = (2. * x - cs->a - cs->b) / (cs->b - cs->a);
163 if (GSL_MODE_PREC (mode) == GSL_PREC_DOUBLE)
164 eval_order = cs->order;
166 eval_order = cs->order_sp;
168 for (i = eval_order; i >= 1; i--)
171 d1 = y2 * d1 - d2 + cs->c[i];
175 *result = y * d1 - d2 + 0.5 * cs->c[0];
177 /* Estimate cumulative numerical error */
179 for (i = 0; i <= eval_order; i++)
181 absc += fabs(cs->c[i]);
184 /* Combine truncation error and numerical error */
186 *abserr = fabs (cs->c[eval_order]) + absc * GSL_DBL_EPSILON;
192 gsl_cheb_eval_mode (const gsl_cheb_series * cs,
193 const double x, gsl_mode_t mode)
195 double result, abserr;
196 int status = gsl_cheb_eval_mode_e (cs, x, mode, &result, &abserr);
198 if (status != GSL_SUCCESS)
200 GSL_ERROR_VAL("gsl_cheb_eval_mode", status, result);