]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>Legendre (and Associated) Polynomials</title> | |
5 | <link rel="stylesheet" href="../../math.css" type="text/css"> | |
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.77.1"> | |
7 | <link rel="home" href="../../index.html" title="Math Toolkit 2.5.1"> | |
8 | <link rel="up" href="../sf_poly.html" title="Polynomials"> | |
9 | <link rel="prev" href="../sf_poly.html" title="Polynomials"> | |
10 | <link rel="next" href="laguerre.html" title="Laguerre (and Associated) 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="../sf_poly.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="laguerre.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.legendre"></a><a class="link" href="legendre.html" title="Legendre (and Associated) Polynomials">Legendre (and Associated) | |
28 | Polynomials</a> | |
29 | </h3></div></div></div> | |
30 | <h5> | |
31 | <a name="math_toolkit.sf_poly.legendre.h0"></a> | |
32 | <span class="phrase"><a name="math_toolkit.sf_poly.legendre.synopsis"></a></span><a class="link" href="legendre.html#math_toolkit.sf_poly.legendre.synopsis">Synopsis</a> | |
33 | </h5> | |
34 | <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">legendre</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> | |
35 | </pre> | |
36 | <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> | |
37 | ||
38 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
39 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
40 | ||
41 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
42 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
43 | ||
44 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
45 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
46 | ||
47 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
48 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
49 | ||
50 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
51 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_q</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
52 | ||
53 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
54 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_q</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
55 | ||
56 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span> | |
57 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_next</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">Pl</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">Plm1</span><span class="special">);</span> | |
58 | ||
59 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span> | |
60 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_next</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">Pl</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">Plm1</span><span class="special">);</span> | |
61 | ||
62 | ||
63 | <span class="special">}}</span> <span class="comment">// namespaces</span> | |
64 | </pre> | |
65 | <p> | |
66 | The return type of these functions is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result | |
67 | type calculation rules</em></span></a>: note than when there is a single | |
68 | template argument the result is the same type as that argument or <code class="computeroutput"><span class="keyword">double</span></code> if the template argument is an integer | |
69 | type. | |
70 | </p> | |
71 | <p> | |
72 | The final <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can | |
73 | be used to control the behaviour of the function: how it handles errors, | |
74 | what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">policy | |
75 | documentation for more details</a>. | |
76 | </p> | |
77 | <h5> | |
78 | <a name="math_toolkit.sf_poly.legendre.h1"></a> | |
79 | <span class="phrase"><a name="math_toolkit.sf_poly.legendre.description"></a></span><a class="link" href="legendre.html#math_toolkit.sf_poly.legendre.description">Description</a> | |
80 | </h5> | |
81 | <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
82 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
83 | ||
84 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
85 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
86 | </pre> | |
87 | <p> | |
88 | Returns the Legendre Polynomial of the first kind: | |
89 | </p> | |
90 | <p> | |
91 | <span class="inlinemediaobject"><img src="../../../equations/legendre_0.svg"></span> | |
92 | </p> | |
93 | <p> | |
94 | Requires -1 <= x <= 1, otherwise returns the result of <a class="link" href="../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>. | |
95 | </p> | |
96 | <p> | |
97 | Negative orders are handled via the reflection formula: | |
98 | </p> | |
99 | <p> | |
100 | P<sub>-l-1</sub>(x) = P<sub>l</sub>(x) | |
101 | </p> | |
102 | <p> | |
103 | The following graph illustrates the behaviour of the first few Legendre Polynomials: | |
104 | </p> | |
105 | <p> | |
106 | <span class="inlinemediaobject"><img src="../../../graphs/legendre_p.svg" align="middle"></span> | |
107 | </p> | |
108 | <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
109 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">l</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
110 | ||
111 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
112 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_p</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">l</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
113 | </pre> | |
114 | <p> | |
115 | Returns the associated Legendre polynomial of the first kind: | |
116 | </p> | |
117 | <p> | |
118 | <span class="inlinemediaobject"><img src="../../../equations/legendre_1.svg"></span> | |
119 | </p> | |
120 | <p> | |
121 | Requires -1 <= x <= 1, otherwise returns the result of <a class="link" href="../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>. | |
122 | </p> | |
123 | <p> | |
124 | Negative values of <span class="emphasis"><em>l</em></span> and <span class="emphasis"><em>m</em></span> are | |
125 | handled via the identity relations: | |
126 | </p> | |
127 | <p> | |
128 | <span class="inlinemediaobject"><img src="../../../equations/legendre_3.svg"></span> | |
129 | </p> | |
130 | <div class="caution"><table border="0" summary="Caution"> | |
131 | <tr> | |
132 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../doc/src/images/caution.png"></td> | |
133 | <th align="left">Caution</th> | |
134 | </tr> | |
135 | <tr><td align="left" valign="top"> | |
136 | <p> | |
137 | The definition of the associated Legendre polynomial used here includes | |
138 | a leading Condon-Shortley phase term of (-1)<sup>m</sup>. This matches the definition | |
139 | given by Abramowitz and Stegun (8.6.6) and that used by <a href="http://mathworld.wolfram.com/LegendrePolynomial.html" target="_top">Mathworld</a> | |
140 | and <a href="http://documents.wolfram.com/mathematica/functions/LegendreP" target="_top">Mathematica's | |
141 | LegendreP function</a>. However, uses in the literature do not always | |
142 | include this phase term, and strangely the specification for the associated | |
143 | Legendre function in the C++ TR1 (assoc_legendre) also omits it, in spite | |
144 | of stating that it uses Abramowitz and Stegun as the final arbiter on these | |
145 | matters. | |
146 | </p> | |
147 | <p> | |
148 | See: | |
149 | </p> | |
150 | <p> | |
151 | <a href="http://mathworld.wolfram.com/LegendrePolynomial.html" target="_top">Weisstein, | |
152 | Eric W. "Legendre Polynomial." From MathWorld--A Wolfram Web | |
153 | Resource</a>. | |
154 | </p> | |
155 | <p> | |
156 | Abramowitz, M. and Stegun, I. A. (Eds.). "Legendre Functions" | |
157 | and "Orthogonal Polynomials." Ch. 22 in Chs. 8 and 22 in Handbook | |
158 | of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, | |
159 | 9th printing. New York: Dover, pp. 331-339 and 771-802, 1972. | |
160 | </p> | |
161 | </td></tr> | |
162 | </table></div> | |
163 | <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> | |
164 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_q</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> | |
165 | ||
166 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
167 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_q</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> | |
168 | </pre> | |
169 | <p> | |
170 | Returns the value of the Legendre polynomial that is the second solution | |
171 | to the Legendre differential equation, for example: | |
172 | </p> | |
173 | <p> | |
174 | <span class="inlinemediaobject"><img src="../../../equations/legendre_2.svg"></span> | |
175 | </p> | |
176 | <p> | |
177 | Requires -1 <= x <= 1, otherwise <a class="link" href="../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a> | |
178 | is called. | |
179 | </p> | |
180 | <p> | |
181 | The following graph illustrates the first few Legendre functions of the second | |
182 | kind: | |
183 | </p> | |
184 | <p> | |
185 | <span class="inlinemediaobject"><img src="../../../graphs/legendre_q.svg" align="middle"></span> | |
186 | </p> | |
187 | <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span> | |
188 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_next</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">Pl</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">Plm1</span><span class="special">);</span> | |
189 | </pre> | |
190 | <p> | |
191 | Implements the three term recurrence relation for the Legendre polynomials, | |
192 | this function can be used to create a sequence of values evaluated at the | |
193 | same <span class="emphasis"><em>x</em></span>, and for rising <span class="emphasis"><em>l</em></span>. This | |
194 | recurrence relation holds for Legendre Polynomials of both the first and | |
195 | second kinds. | |
196 | </p> | |
197 | <p> | |
198 | <span class="inlinemediaobject"><img src="../../../equations/legendre_4.svg"></span> | |
199 | </p> | |
200 | <p> | |
201 | For example we could produce a vector of the first 10 polynomial values using: | |
202 | </p> | |
203 | <pre class="programlisting"><span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span> <span class="comment">// Abscissa value</span> | |
204 | <span class="identifier">vector</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">v</span><span class="special">;</span> | |
205 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_p</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
206 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_p</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
207 | <span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">l</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">l</span><span class="special">)</span> | |
208 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_next</span><span class="special">(</span><span class="identifier">l</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">],</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">-</span><span class="number">1</span><span class="special">]));</span> | |
209 | <span class="comment">// Double check values:</span> | |
210 | <span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">l</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">l</span><span class="special">)</span> | |
211 | <span class="identifier">assert</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">]</span> <span class="special">==</span> <span class="identifier">legendre_p</span><span class="special">(</span><span class="identifier">l</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
212 | </pre> | |
213 | <p> | |
214 | Formally the arguments are: | |
215 | </p> | |
216 | <div class="variablelist"> | |
217 | <p class="title"><b></b></p> | |
218 | <dl class="variablelist"> | |
219 | <dt><span class="term">l</span></dt> | |
220 | <dd><p> | |
221 | The degree of the last polynomial calculated. | |
222 | </p></dd> | |
223 | <dt><span class="term">x</span></dt> | |
224 | <dd><p> | |
225 | The abscissa value | |
226 | </p></dd> | |
227 | <dt><span class="term">Pl</span></dt> | |
228 | <dd><p> | |
229 | The value of the polynomial evaluated at degree <span class="emphasis"><em>l</em></span>. | |
230 | </p></dd> | |
231 | <dt><span class="term">Plm1</span></dt> | |
232 | <dd><p> | |
233 | The value of the polynomial evaluated at degree <span class="emphasis"><em>l-1</em></span>. | |
234 | </p></dd> | |
235 | </dl> | |
236 | </div> | |
237 | <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">></span> | |
238 | <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">legendre_next</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">Pl</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">Plm1</span><span class="special">);</span> | |
239 | </pre> | |
240 | <p> | |
241 | Implements the three term recurrence relation for the Associated Legendre | |
242 | polynomials, this function can be used to create a sequence of values evaluated | |
243 | at the same <span class="emphasis"><em>x</em></span>, and for rising <span class="emphasis"><em>l</em></span>. | |
244 | </p> | |
245 | <p> | |
246 | <span class="inlinemediaobject"><img src="../../../equations/legendre_5.svg"></span> | |
247 | </p> | |
248 | <p> | |
249 | For example we could produce a vector of the first m+10 polynomial values | |
250 | using: | |
251 | </p> | |
252 | <pre class="programlisting"><span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span> <span class="comment">// Abscissa value</span> | |
253 | <span class="keyword">int</span> <span class="identifier">m</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// order</span> | |
254 | <span class="identifier">vector</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">v</span><span class="special">;</span> | |
255 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_p</span><span class="special">(</span><span class="identifier">m</span><span class="special">,</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
256 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_p</span><span class="special">(</span><span class="number">1</span> <span class="special">+</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
257 | <span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">l</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">l</span><span class="special">)</span> | |
258 | <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">legendre_next</span><span class="special">(</span><span class="identifier">l</span> <span class="special">+</span> <span class="number">10</span><span class="special">,</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">],</span> <span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">-</span><span class="number">1</span><span class="special">]));</span> | |
259 | <span class="comment">// Double check values:</span> | |
260 | <span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">l</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">l</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">l</span><span class="special">)</span> | |
261 | <span class="identifier">assert</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="identifier">l</span><span class="special">]</span> <span class="special">==</span> <span class="identifier">legendre_p</span><span class="special">(</span><span class="number">10</span> <span class="special">+</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">x</span><span class="special">));</span> | |
262 | </pre> | |
263 | <p> | |
264 | Formally the arguments are: | |
265 | </p> | |
266 | <div class="variablelist"> | |
267 | <p class="title"><b></b></p> | |
268 | <dl class="variablelist"> | |
269 | <dt><span class="term">l</span></dt> | |
270 | <dd><p> | |
271 | The degree of the last polynomial calculated. | |
272 | </p></dd> | |
273 | <dt><span class="term">m</span></dt> | |
274 | <dd><p> | |
275 | The order of the Associated Polynomial. | |
276 | </p></dd> | |
277 | <dt><span class="term">x</span></dt> | |
278 | <dd><p> | |
279 | The abscissa value | |
280 | </p></dd> | |
281 | <dt><span class="term">Pl</span></dt> | |
282 | <dd><p> | |
283 | The value of the polynomial evaluated at degree <span class="emphasis"><em>l</em></span>. | |
284 | </p></dd> | |
285 | <dt><span class="term">Plm1</span></dt> | |
286 | <dd><p> | |
287 | The value of the polynomial evaluated at degree <span class="emphasis"><em>l-1</em></span>. | |
288 | </p></dd> | |
289 | </dl> | |
290 | </div> | |
291 | <h5> | |
292 | <a name="math_toolkit.sf_poly.legendre.h2"></a> | |
293 | <span class="phrase"><a name="math_toolkit.sf_poly.legendre.accuracy"></a></span><a class="link" href="legendre.html#math_toolkit.sf_poly.legendre.accuracy">Accuracy</a> | |
294 | </h5> | |
295 | <p> | |
296 | The following table shows peak errors (in units of epsilon) for various domains | |
297 | of input arguments. Note that only results for the widest floating point | |
298 | type on the system are given as narrower types have <a class="link" href="../relative_error.html#math_toolkit.relative_error.zero_error">effectively | |
299 | zero error</a>. | |
300 | </p> | |
301 | <div class="table"> | |
302 | <a name="math_toolkit.sf_poly.legendre.table_legendre_p"></a><p class="title"><b>Table 6.32. Error rates for legendre_p</b></p> | |
303 | <div class="table-contents"><table class="table" summary="Error rates for legendre_p"> | |
304 | <colgroup> | |
305 | <col> | |
306 | <col> | |
307 | <col> | |
308 | <col> | |
309 | <col> | |
310 | </colgroup> | |
311 | <thead><tr> | |
312 | <th> | |
313 | </th> | |
314 | <th> | |
315 | <p> | |
316 | Microsoft Visual C++ version 12.0<br> Win32<br> double | |
317 | </p> | |
318 | </th> | |
319 | <th> | |
320 | <p> | |
321 | GNU C++ version 5.1.0<br> linux<br> double | |
322 | </p> | |
323 | </th> | |
324 | <th> | |
325 | <p> | |
326 | GNU C++ version 5.1.0<br> linux<br> long double | |
327 | </p> | |
328 | </th> | |
329 | <th> | |
330 | <p> | |
331 | Sun compiler version 0x5130<br> Sun Solaris<br> long double | |
332 | </p> | |
333 | </th> | |
334 | </tr></thead> | |
335 | <tbody> | |
336 | <tr> | |
337 | <td> | |
338 | <p> | |
339 | Legendre Polynomials: Small Values | |
340 | </p> | |
341 | </td> | |
342 | <td> | |
343 | <p> | |
344 | <span class="blue">Max = 211ε (Mean = 20.4ε)</span> | |
345 | </p> | |
346 | </td> | |
347 | <td> | |
348 | <p> | |
349 | <span class="blue">Max = 0.732ε (Mean = 0.0619ε)</span><br> | |
350 | <br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 211ε (Mean = 20.4ε)) | |
351 | </p> | |
352 | </td> | |
353 | <td> | |
354 | <p> | |
355 | <span class="blue">Max = 69.2ε (Mean = 9.58ε)</span><br> <br> | |
356 | (<span class="emphasis"><em><tr1/cmath>:</em></span> Max = 124ε (Mean = 13.2ε)) | |
357 | </p> | |
358 | </td> | |
359 | <td> | |
360 | <p> | |
361 | <span class="blue">Max = 69.2ε (Mean = 9.58ε)</span> | |
362 | </p> | |
363 | </td> | |
364 | </tr> | |
365 | <tr> | |
366 | <td> | |
367 | <p> | |
368 | Legendre Polynomials: Large Values | |
369 | </p> | |
370 | </td> | |
371 | <td> | |
372 | <p> | |
373 | <span class="blue">Max = 300ε (Mean = 33.2ε)</span> | |
374 | </p> | |
375 | </td> | |
376 | <td> | |
377 | <p> | |
378 | <span class="blue">Max = 0.632ε (Mean = 0.0693ε)</span><br> | |
379 | <br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 300ε (Mean = 33.2ε)) | |
380 | </p> | |
381 | </td> | |
382 | <td> | |
383 | <p> | |
384 | <span class="blue">Max = 699ε (Mean = 59.6ε)</span><br> <br> | |
385 | (<span class="emphasis"><em><tr1/cmath>:</em></span> Max = 343ε (Mean = 32.1ε)) | |
386 | </p> | |
387 | </td> | |
388 | <td> | |
389 | <p> | |
390 | <span class="blue">Max = 699ε (Mean = 59.6ε)</span> | |
391 | </p> | |
392 | </td> | |
393 | </tr> | |
394 | </tbody> | |
395 | </table></div> | |
396 | </div> | |
397 | <br class="table-break"><div class="table"> | |
398 | <a name="math_toolkit.sf_poly.legendre.table_legendre_q"></a><p class="title"><b>Table 6.33. Error rates for legendre_q</b></p> | |
399 | <div class="table-contents"><table class="table" summary="Error rates for legendre_q"> | |
400 | <colgroup> | |
401 | <col> | |
402 | <col> | |
403 | <col> | |
404 | <col> | |
405 | <col> | |
406 | </colgroup> | |
407 | <thead><tr> | |
408 | <th> | |
409 | </th> | |
410 | <th> | |
411 | <p> | |
412 | Microsoft Visual C++ version 12.0<br> Win32<br> double | |
413 | </p> | |
414 | </th> | |
415 | <th> | |
416 | <p> | |
417 | GNU C++ version 5.1.0<br> linux<br> double | |
418 | </p> | |
419 | </th> | |
420 | <th> | |
421 | <p> | |
422 | GNU C++ version 5.1.0<br> linux<br> long double | |
423 | </p> | |
424 | </th> | |
425 | <th> | |
426 | <p> | |
427 | Sun compiler version 0x5130<br> Sun Solaris<br> long double | |
428 | </p> | |
429 | </th> | |
430 | </tr></thead> | |
431 | <tbody> | |
432 | <tr> | |
433 | <td> | |
434 | <p> | |
435 | Legendre Polynomials: Small Values | |
436 | </p> | |
437 | </td> | |
438 | <td> | |
439 | <p> | |
440 | <span class="blue">Max = 46.4ε (Mean = 7.32ε)</span> | |
441 | </p> | |
442 | </td> | |
443 | <td> | |
444 | <p> | |
445 | <span class="blue">Max = 0.612ε (Mean = 0.0517ε)</span><br> | |
446 | <br> (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 46.4ε (Mean = 7.46ε)) | |
447 | </p> | |
448 | </td> | |
449 | <td> | |
450 | <p> | |
451 | <span class="blue">Max = 50.9ε (Mean = 9ε)</span> | |
452 | </p> | |
453 | </td> | |
454 | <td> | |
455 | <p> | |
456 | <span class="blue">Max = 50.9ε (Mean = 8.98ε)</span> | |
457 | </p> | |
458 | </td> | |
459 | </tr> | |
460 | <tr> | |
461 | <td> | |
462 | <p> | |
463 | Legendre Polynomials: Large Values | |
464 | </p> | |
465 | </td> | |
466 | <td> | |
467 | <p> | |
468 | <span class="blue">Max = 4.6e+003ε (Mean = 366ε)</span> | |
469 | </p> | |
470 | </td> | |
471 | <td> | |
472 | <p> | |
473 | <span class="blue">Max = 2.49ε (Mean = 0.202ε)</span><br> <br> | |
474 | (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 4.6e+03ε (Mean = 366ε)) | |
475 | </p> | |
476 | </td> | |
477 | <td> | |
478 | <p> | |
479 | <span class="blue">Max = 5.98e+03ε (Mean = 478ε)</span> | |
480 | </p> | |
481 | </td> | |
482 | <td> | |
483 | <p> | |
484 | <span class="blue">Max = 5.98e+03ε (Mean = 478ε)</span> | |
485 | </p> | |
486 | </td> | |
487 | </tr> | |
488 | </tbody> | |
489 | </table></div> | |
490 | </div> | |
491 | <br class="table-break"><div class="table"> | |
492 | <a name="math_toolkit.sf_poly.legendre.table_legendre_p_associated_"></a><p class="title"><b>Table 6.34. Error rates for legendre_p (associated)</b></p> | |
493 | <div class="table-contents"><table class="table" summary="Error rates for legendre_p (associated)"> | |
494 | <colgroup> | |
495 | <col> | |
496 | <col> | |
497 | <col> | |
498 | <col> | |
499 | <col> | |
500 | </colgroup> | |
501 | <thead><tr> | |
502 | <th> | |
503 | </th> | |
504 | <th> | |
505 | <p> | |
506 | Microsoft Visual C++ version 12.0<br> Win32<br> double | |
507 | </p> | |
508 | </th> | |
509 | <th> | |
510 | <p> | |
511 | GNU C++ version 5.1.0<br> linux<br> double | |
512 | </p> | |
513 | </th> | |
514 | <th> | |
515 | <p> | |
516 | GNU C++ version 5.1.0<br> linux<br> long double | |
517 | </p> | |
518 | </th> | |
519 | <th> | |
520 | <p> | |
521 | Sun compiler version 0x5130<br> Sun Solaris<br> long double | |
522 | </p> | |
523 | </th> | |
524 | </tr></thead> | |
525 | <tbody><tr> | |
526 | <td> | |
527 | <p> | |
528 | Associated Legendre Polynomials: Small Values | |
529 | </p> | |
530 | </td> | |
531 | <td> | |
532 | <p> | |
533 | <span class="blue">Max = 121ε (Mean = 7.14ε)</span> | |
534 | </p> | |
535 | </td> | |
536 | <td> | |
537 | <p> | |
538 | <span class="blue">Max = 0.999ε (Mean = 0.05ε)</span><br> <br> | |
539 | (<span class="emphasis"><em>GSL 1.16:</em></span> Max = 121ε (Mean = 6.75ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_double_legendre_p_associated__GSL_1_16_Associated_Legendre_Polynomials_Small_Values">And | |
540 | other failures.</a>) | |
541 | </p> | |
542 | </td> | |
543 | <td> | |
544 | <p> | |
545 | <span class="blue">Max = 175ε (Mean = 9.88ε)</span><br> <br> | |
546 | (<span class="emphasis"><em><tr1/cmath>:</em></span> Max = 175ε (Mean = 9.36ε) | |
547 | <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_5_1_0_linux_long_double_legendre_p_associated___tr1_cmath__Associated_Legendre_Polynomials_Small_Values">And | |
548 | other failures.</a>) | |
549 | </p> | |
550 | </td> | |
551 | <td> | |
552 | <p> | |
553 | <span class="blue">Max = 77.7ε (Mean = 5.59ε)</span> | |
554 | </p> | |
555 | </td> | |
556 | </tr></tbody> | |
557 | </table></div> | |
558 | </div> | |
559 | <br class="table-break"><p> | |
560 | Note that the worst errors occur when the order increases, values greater | |
561 | than ~120 are very unlikely to produce sensible results, especially in the | |
562 | associated polynomial case when the degree is also large. Further the relative | |
563 | errors are likely to grow arbitrarily large when the function is very close | |
564 | to a root. | |
565 | </p> | |
566 | <h5> | |
567 | <a name="math_toolkit.sf_poly.legendre.h3"></a> | |
568 | <span class="phrase"><a name="math_toolkit.sf_poly.legendre.testing"></a></span><a class="link" href="legendre.html#math_toolkit.sf_poly.legendre.testing">Testing</a> | |
569 | </h5> | |
570 | <p> | |
571 | A mixture of spot tests of values calculated using functions.wolfram.com, | |
572 | and randomly generated test data are used: the test data was computed using | |
573 | <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a> at 1000-bit | |
574 | precision. | |
575 | </p> | |
576 | <h5> | |
577 | <a name="math_toolkit.sf_poly.legendre.h4"></a> | |
578 | <span class="phrase"><a name="math_toolkit.sf_poly.legendre.implementation"></a></span><a class="link" href="legendre.html#math_toolkit.sf_poly.legendre.implementation">Implementation</a> | |
579 | </h5> | |
580 | <p> | |
581 | These functions are implemented using the stable three term recurrence relations. | |
582 | These relations guarantee low absolute error but cannot guarantee low relative | |
583 | error near one of the roots of the polynomials. | |
584 | </p> | |
585 | </div> | |
586 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
587 | <td align="left"></td> | |
588 | <td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal, | |
589 | Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert | |
590 | Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, | |
591 | Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p> | |
592 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
593 | 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>) | |
594 | </p> | |
595 | </div></td> | |
596 | </tr></table> | |
597 | <hr> | |
598 | <div class="spirit-nav"> | |
599 | <a accesskey="p" href="../sf_poly.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="laguerre.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> | |
600 | </div> | |
601 | </body> | |
602 | </html> |