2 Copyright 2019, Nick Thompson
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt).
8 [section:gegenbauer Gegenbauer Polynomials]
13 #include <boost/math/special_functions/gegenbauer.hpp>
16 namespace boost{ namespace math{
18 template<typename Real>
19 Real gegenbauer(unsigned n, Real lambda, Real x);
21 template<typename Real>
22 Real gegenbauer_prime(unsigned n, Real lambda, Real x);
24 template<typename Real>
25 Real gegenbauer_derivative(unsigned n, Real lambda, Real x, unsigned k);
29 Gegenbauer polynomials are a family of orthogonal polynomials.
31 A basic usage is as follows:
33 using boost::math::gegenbauer;
37 double y = gegenbauer(n, lambda, x);
39 All derivatives of the Gegenbauer polynomials are available.
40 The /k/-th derivative of the /n/-th Gegenbauer polynomial is given by
42 using boost::math::gegenbauer_derivative;
47 double y = gegenbauer_derivative(n, lambda, x, k);
49 For consistency with the rest of the library, `gegenbauer_prime` is provided which simply returns `gegenbauer_derivative(n, lambda, x,1 )`.
51 [$../graphs/gegenbauer.svg]
55 The implementation uses the 3-term recurrence for the Gegenbauer polynomials, rising.
59 Double precision timing on a consumer x86 laptop is shown below.
60 Included is the time to generate a random number argument in the interval \[-1, 1\] (which takes 11.5ns).
63 Run on (16 X 4300 MHz CPU s)
66 L1 Instruction 32K (x8)
68 L3 Unified 11264K (x1)
69 Load Average: 0.21, 0.33, 0.29
70 -----------------------------------------
72 -----------------------------------------
73 Gegenbauer<double>/1 12.5 ns
74 Gegenbauer<double>/2 13.5 ns
75 Gegenbauer<double>/3 14.6 ns
76 Gegenbauer<double>/4 16.0 ns
77 Gegenbauer<double>/5 17.5 ns
78 Gegenbauer<double>/6 19.2 ns
79 Gegenbauer<double>/7 20.7 ns
80 Gegenbauer<double>/8 22.2 ns
81 Gegenbauer<double>/9 23.6 ns
82 Gegenbauer<double>/10 25.2 ns
83 Gegenbauer<double>/11 26.9 ns
84 Gegenbauer<double>/12 28.7 ns
85 Gegenbauer<double>/13 30.5 ns
86 Gegenbauer<double>/14 32.5 ns
87 Gegenbauer<double>/15 34.3 ns
88 Gegenbauer<double>/16 36.3 ns
89 Gegenbauer<double>/17 38.0 ns
90 Gegenbauer<double>/18 39.9 ns
91 Gegenbauer<double>/19 41.8 ns
92 Gegenbauer<double>/20 43.8 ns
93 UniformReal<double> 11.5 ns
98 Some representative ULP plots are shown below.
99 The relative accuracy cannot be controlled at the roots of the polynomial, as is to be expected.
101 [$../graphs/gegenbauer_ulp_3.svg]
102 [$../graphs/gegenbauer_ulp_5.svg]
103 [$../graphs/gegenbauer_ulp_9.svg]
107 Some programs define the Gegenbauer polynomial with \u03BB = 0 via renormalization (which makes them Chebyshev polynomials).
108 We do not follow this convention: In this case, only the zeroth Gegenbauer polynomial is nonzero.