1 /* specfunc/gegenbauer.c
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.
20 /* Author: G. Jungman */
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_sf_gegenbauer.h>
29 /* See: [Thompson, Atlas for Computing Mathematical Functions] */
33 gsl_sf_gegenpoly_1_e(double lambda, double x, gsl_sf_result * result)
35 /* CHECK_POINTER(result) */
39 result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
43 result->val = 2.0*lambda*x;
44 result->err = 4.0 * GSL_DBL_EPSILON * fabs(result->val);
50 gsl_sf_gegenpoly_2_e(double lambda, double x, gsl_sf_result * result)
52 /* CHECK_POINTER(result) */
55 const double txx = 2.0*x*x;
56 result->val = -1.0 + txx;
57 result->err = 2.0 * GSL_DBL_EPSILON * fabs(txx);
58 result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
62 result->val = lambda*(-1.0 + 2.0*(1.0+lambda)*x*x);
63 result->err = GSL_DBL_EPSILON * (2.0 * fabs(result->val) + fabs(lambda));
69 gsl_sf_gegenpoly_3_e(double lambda, double x, gsl_sf_result * result)
71 /* CHECK_POINTER(result) */
74 result->val = x*(-2.0 + 4.0/3.0*x*x);
75 result->err = GSL_DBL_EPSILON * (2.0 * fabs(result->val) + fabs(x));
79 double c = 4.0 + lambda*(6.0 + 2.0*lambda);
80 result->val = 2.0*lambda * x * ( -1.0 - lambda + c*x*x/3.0 );
81 result->err = GSL_DBL_EPSILON * (2.0 * fabs(result->val) + fabs(lambda * x));
88 gsl_sf_gegenpoly_n_e(int n, double lambda, double x, gsl_sf_result * result)
90 /* CHECK_POINTER(result) */
92 if(lambda <= -0.5 || n < 0) {
101 return gsl_sf_gegenpoly_1_e(lambda, x, result);
104 return gsl_sf_gegenpoly_2_e(lambda, x, result);
107 return gsl_sf_gegenpoly_3_e(lambda, x, result);
110 if(lambda == 0.0 && (x >= -1.0 || x <= 1.0)) {
112 const double z = n * acos(x);
113 result->val = 2.0 * cos(z) / n;
114 result->err = 2.0 * GSL_DBL_EPSILON * fabs(z * result->val);
121 int stat_g2 = gsl_sf_gegenpoly_2_e(lambda, x, &g2);
122 int stat_g3 = gsl_sf_gegenpoly_3_e(lambda, x, &g3);
123 int stat_g = GSL_ERROR_SELECT_2(stat_g2, stat_g3);
124 double gkm2 = g2.val;
125 double gkm1 = g3.val;
127 for(k=4; k<=n; k++) {
128 gk = (2.0*(k+lambda-1.0)*x*gkm1 - (k+2.0*lambda-2.0)*gkm2) / k;
133 result->err = 2.0 * GSL_DBL_EPSILON * 0.5 * n * fabs(gk);
141 gsl_sf_gegenpoly_array(int nmax, double lambda, double x, double * result_array)
145 /* CHECK_POINTER(result_array) */
147 if(lambda <= -0.5 || nmax < 0) {
148 GSL_ERROR("domain error", GSL_EDOM);
152 result_array[0] = 1.0;
153 if(nmax == 0) return GSL_SUCCESS;
157 result_array[1] = 2.0*x;
159 result_array[1] = 2.0*lambda*x;
162 for(k=2; k<=nmax; k++) {
163 double term1 = 2.0*(k+lambda-1.0) * x * result_array[k-1];
164 double term2 = (k+2.0*lambda-2.0) * result_array[k-2];
165 result_array[k] = (term1 - term2) / k;
172 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
176 double gsl_sf_gegenpoly_1(double lambda, double x)
178 EVAL_RESULT(gsl_sf_gegenpoly_1_e(lambda, x, &result));
181 double gsl_sf_gegenpoly_2(double lambda, double x)
183 EVAL_RESULT(gsl_sf_gegenpoly_2_e(lambda, x, &result));
186 double gsl_sf_gegenpoly_3(double lambda, double x)
188 EVAL_RESULT(gsl_sf_gegenpoly_3_e(lambda, x, &result));
191 double gsl_sf_gegenpoly_n(int n, double lambda, double x)
193 EVAL_RESULT(gsl_sf_gegenpoly_n_e(n, lambda, x, &result));