• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Gegenbauer Polynomials</title>
5<link rel="stylesheet" href="../../math.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Math Toolkit 2.12.0">
8<link rel="up" href="../sf_poly.html" title="Polynomials">
9<link rel="prev" href="cardinal_b_splines.html" title="Cardinal B-splines">
10<link rel="next" href="jacobi.html" title="Jacobi Polynomials">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="cardinal_b_splines.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="jacobi.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="math_toolkit.sf_poly.gegenbauer"></a><a class="link" href="gegenbauer.html" title="Gegenbauer Polynomials">Gegenbauer Polynomials</a>
28</h3></div></div></div>
29<h5>
30<a name="math_toolkit.sf_poly.gegenbauer.h0"></a>
31        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.synopsis"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.synopsis">Synopsis</a>
32      </h5>
33<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">gegenbauer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
34</pre>
35<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
36
37<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
38<span class="identifier">Real</span> <span class="identifier">gegenbauer</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">);</span>
39
40<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
41<span class="identifier">Real</span> <span class="identifier">gegenbauer_prime</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">);</span>
42
43<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
44<span class="identifier">Real</span> <span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">k</span><span class="special">);</span>
45
46<span class="special">}}</span> <span class="comment">// namespaces</span>
47</pre>
48<p>
49        Gegenbauer polynomials are a family of orthogonal polynomials.
50      </p>
51<p>
52        A basic usage is as follows:
53      </p>
54<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gegenbauer</span><span class="special">;</span>
55<span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
56<span class="keyword">double</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
57<span class="keyword">unsigned</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span>
58<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">gegenbauer</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span>
59</pre>
60<p>
61        All derivatives of the Gegenbauer polynomials are available. The <span class="emphasis"><em>k</em></span>-th
62        derivative of the <span class="emphasis"><em>n</em></span>-th Gegenbauer polynomial is given
63        by
64      </p>
65<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gegenbauer_derivative</span><span class="special">;</span>
66<span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
67<span class="keyword">double</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
68<span class="keyword">unsigned</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span>
69<span class="keyword">unsigned</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
70<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">k</span><span class="special">);</span>
71</pre>
72<p>
73        For consistency with the rest of the library, <code class="computeroutput"><span class="identifier">gegenbauer_prime</span></code>
74        is provided which simply returns <code class="computeroutput"><span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
75        <span class="identifier">lambda</span><span class="special">,</span>
76        <span class="identifier">x</span><span class="special">,</span><span class="number">1</span> <span class="special">)</span></code>.
77      </p>
78<p>
79        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer.svg"></object></span>
80      </p>
81<h4>
82<a name="math_toolkit.sf_poly.gegenbauer.h1"></a>
83        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.implementation"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.implementation">Implementation</a>
84      </h4>
85<p>
86        The implementation uses the 3-term recurrence for the Gegenbauer polynomials,
87        rising.
88      </p>
89<h4>
90<a name="math_toolkit.sf_poly.gegenbauer.h2"></a>
91        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.performance"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.performance">Performance</a>
92      </h4>
93<p>
94        Double precision timing on a consumer x86 laptop is shown below. Included
95        is the time to generate a random number argument in the interval [-1, 1]
96        (which takes 11.5ns).
97      </p>
98<pre class="programlisting"><span class="identifier">Run</span> <span class="identifier">on</span> <span class="special">(</span><span class="number">16</span> <span class="identifier">X</span> <span class="number">4300</span> <span class="identifier">MHz</span> <span class="identifier">CPU</span> <span class="identifier">s</span><span class="special">)</span>
99<span class="identifier">CPU</span> <span class="identifier">Caches</span><span class="special">:</span>
100  <span class="identifier">L1</span> <span class="identifier">Data</span> <span class="number">32</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
101  <span class="identifier">L1</span> <span class="identifier">Instruction</span> <span class="number">32</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
102  <span class="identifier">L2</span> <span class="identifier">Unified</span> <span class="number">1024</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
103  <span class="identifier">L3</span> <span class="identifier">Unified</span> <span class="number">11264</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x1</span><span class="special">)</span>
104<span class="identifier">Load</span> <span class="identifier">Average</span><span class="special">:</span> <span class="number">0.21</span><span class="special">,</span> <span class="number">0.33</span><span class="special">,</span> <span class="number">0.29</span>
105<span class="special">-----------------------------------------</span>
106<span class="identifier">Benchmark</span>                            <span class="identifier">Time</span>
107<span class="special">-----------------------------------------</span>
108<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">1</span>              <span class="number">12.5</span> <span class="identifier">ns</span>
109<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">2</span>              <span class="number">13.5</span> <span class="identifier">ns</span>
110<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">3</span>              <span class="number">14.6</span> <span class="identifier">ns</span>
111<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">4</span>              <span class="number">16.0</span> <span class="identifier">ns</span>
112<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">5</span>              <span class="number">17.5</span> <span class="identifier">ns</span>
113<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">6</span>              <span class="number">19.2</span> <span class="identifier">ns</span>
114<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">7</span>              <span class="number">20.7</span> <span class="identifier">ns</span>
115<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">8</span>              <span class="number">22.2</span> <span class="identifier">ns</span>
116<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">9</span>              <span class="number">23.6</span> <span class="identifier">ns</span>
117<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">10</span>             <span class="number">25.2</span> <span class="identifier">ns</span>
118<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">11</span>             <span class="number">26.9</span> <span class="identifier">ns</span>
119<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">12</span>             <span class="number">28.7</span> <span class="identifier">ns</span>
120<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">13</span>             <span class="number">30.5</span> <span class="identifier">ns</span>
121<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">14</span>             <span class="number">32.5</span> <span class="identifier">ns</span>
122<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">15</span>             <span class="number">34.3</span> <span class="identifier">ns</span>
123<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">16</span>             <span class="number">36.3</span> <span class="identifier">ns</span>
124<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">17</span>             <span class="number">38.0</span> <span class="identifier">ns</span>
125<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">18</span>             <span class="number">39.9</span> <span class="identifier">ns</span>
126<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">19</span>             <span class="number">41.8</span> <span class="identifier">ns</span>
127<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">20</span>             <span class="number">43.8</span> <span class="identifier">ns</span>
128<span class="identifier">UniformReal</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span>               <span class="number">11.5</span> <span class="identifier">ns</span>
129</pre>
130<h4>
131<a name="math_toolkit.sf_poly.gegenbauer.h3"></a>
132        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.accuracy"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.accuracy">Accuracy</a>
133      </h4>
134<p>
135        Some representative ULP plots are shown below. The relative accuracy cannot
136        be controlled at the roots of the polynomial, as is to be expected.
137      </p>
138<p>
139        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_3.svg"></object></span> <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_5.svg"></object></span>
140        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_9.svg"></object></span>
141      </p>
142<h4>
143<a name="math_toolkit.sf_poly.gegenbauer.h4"></a>
144        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.caveats"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.caveats">Caveats</a>
145      </h4>
146<p>
147        Some programs define the Gegenbauer polynomial with λ = 0 via renormalization
148        (which makes them Chebyshev polynomials). We do not follow this convention:
149        In this case, only the zeroth Gegenbauer polynomial is nonzero.
150      </p>
151</div>
152<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
153<td align="left"></td>
154<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
155      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
156      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
157      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
158      Daryle Walker and Xiaogang Zhang<p>
159        Distributed under the Boost Software License, Version 1.0. (See accompanying
160        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
161      </p>
162</div></td>
163</tr></table>
164<hr>
165<div class="spirit-nav">
166<a accesskey="p" href="cardinal_b_splines.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="jacobi.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
167</div>
168</body>
169</html>
170