gegenbauer.qbk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. [/
  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).
  6. ]
  7. [section:gegenbauer Gegenbauer Polynomials]
  8. [h4 Synopsis]
  9. ``
  10. #include <boost/math/special_functions/gegenbauer.hpp>
  11. ``
  12. namespace boost{ namespace math{
  13. template<typename Real>
  14. Real gegenbauer(unsigned n, Real lambda, Real x);
  15. template<typename Real>
  16. Real gegenbauer_prime(unsigned n, Real lambda, Real x);
  17. template<typename Real>
  18. Real gegenbauer_derivative(unsigned n, Real lambda, Real x, unsigned k);
  19. }} // namespaces
  20. Gegenbauer polynomials are a family of orthogonal polynomials.
  21. A basic usage is as follows:
  22. using boost::math::gegenbauer;
  23. double x = 0.5;
  24. double lambda = 0.5;
  25. unsigned n = 3;
  26. double y = gegenbauer(n, lambda, x);
  27. All derivatives of the Gegenbauer polynomials are available.
  28. The /k/-th derivative of the /n/-th Gegenbauer polynomial is given by
  29. using boost::math::gegenbauer_derivative;
  30. double x = 0.5;
  31. double lambda = 0.5;
  32. unsigned n = 3;
  33. unsigned k = 2;
  34. double y = gegenbauer_derivative(n, lambda, x, k);
  35. For consistency with the rest of the library, `gegenbauer_prime` is provided which simply returns `gegenbauer_derivative(n, lambda, x,1 )`.
  36. [$../graphs/gegenbauer.svg]
  37. [h3 Implementation]
  38. The implementation uses the 3-term recurrence for the Gegenbauer polynomials, rising.
  39. [h3 Performance]
  40. Double precision timing on a consumer x86 laptop is shown below.
  41. Included is the time to generate a random number argument in the interval \[-1, 1\] (which takes 11.5ns).
  42. ``
  43. Run on (16 X 4300 MHz CPU s)
  44. CPU Caches:
  45. L1 Data 32K (x8)
  46. L1 Instruction 32K (x8)
  47. L2 Unified 1024K (x8)
  48. L3 Unified 11264K (x1)
  49. Load Average: 0.21, 0.33, 0.29
  50. -----------------------------------------
  51. Benchmark Time
  52. -----------------------------------------
  53. Gegenbauer<double>/1 12.5 ns
  54. Gegenbauer<double>/2 13.5 ns
  55. Gegenbauer<double>/3 14.6 ns
  56. Gegenbauer<double>/4 16.0 ns
  57. Gegenbauer<double>/5 17.5 ns
  58. Gegenbauer<double>/6 19.2 ns
  59. Gegenbauer<double>/7 20.7 ns
  60. Gegenbauer<double>/8 22.2 ns
  61. Gegenbauer<double>/9 23.6 ns
  62. Gegenbauer<double>/10 25.2 ns
  63. Gegenbauer<double>/11 26.9 ns
  64. Gegenbauer<double>/12 28.7 ns
  65. Gegenbauer<double>/13 30.5 ns
  66. Gegenbauer<double>/14 32.5 ns
  67. Gegenbauer<double>/15 34.3 ns
  68. Gegenbauer<double>/16 36.3 ns
  69. Gegenbauer<double>/17 38.0 ns
  70. Gegenbauer<double>/18 39.9 ns
  71. Gegenbauer<double>/19 41.8 ns
  72. Gegenbauer<double>/20 43.8 ns
  73. UniformReal<double> 11.5 ns
  74. ``
  75. [h3 Accuracy]
  76. Some representative ULP plots are shown below.
  77. The relative accuracy cannot be controlled at the roots of the polynomial, as is to be expected.
  78. [$../graphs/gegenbauer_ulp_3.svg]
  79. [$../graphs/gegenbauer_ulp_5.svg]
  80. [$../graphs/gegenbauer_ulp_9.svg]
  81. [h3 Caveats]
  82. Some programs define the Gegenbauer polynomial with \u03BB = 0 via renormalization (which makes them Chebyshev polynomials).
  83. We do not follow this convention: In this case, only the zeroth Gegenbauer polynomial is nonzero.
  84. [endsect]