<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Legendre (and Associated) Polynomials</title> <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> <link rel="home" href="../../../index.html" title="Math Toolkit"> <link rel="up" href="../sf_poly.html" title="Polynomials"> <link rel="prev" href="../sf_poly.html" title="Polynomials"> <link rel="next" href="laguerre.html" title="Laguerre (and Associated) Polynomials"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> <td align="center"><a href="../../../../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <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> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h4 class="title"> <a name="math_toolkit.special.sf_poly.legendre"></a><a class="link" href="legendre.html" title="Legendre (and Associated) Polynomials"> Legendre (and Associated) Polynomials</a> </h4></div></div></div> <a name="math_toolkit.special.sf_poly.legendre.synopsis"></a><h5> <a name="id1115523"></a> <a class="link" href="legendre.html#math_toolkit.special.sf_poly.legendre.synopsis">Synopsis</a> </h5> <p> </p> <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> </pre> <p> </p> <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> <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> <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> <a class="link" href="../../main_overview/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> <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> <a class="link" href="../../main_overview/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> <span class="special">}}</span> <span class="comment">// namespaces </span></pre> <p> The return type of these functions is computed using the <a class="link" href="../../main_overview/result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result type calculation rules</em></span></a>: note than when there is a single 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 type. </p> <p> </p> <p> The final <a class="link" href="../../policy.html" title="Policies">Policy</a> argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Policies">policy documentation for more details</a>. </p> <p> </p> <a name="math_toolkit.special.sf_poly.legendre.description"></a><h5> <a name="id1116375"></a> <a class="link" href="legendre.html#math_toolkit.special.sf_poly.legendre.description">Description</a> </h5> <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> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> </pre> <p> Returns the Legendre Polynomial of the first kind: </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_0.png"></span> </p> <p> Requires -1 <= x <= 1, otherwise returns the result of <a class="link" href="../../main_overview/error_handling.html#domain_error">domain_error</a>. </p> <p> Negative orders are handled via the reflection formula: </p> <p> P<sub>-l-1</sub>(x) = P<sub>l</sub>(x) </p> <p> The following graph illustrates the behaviour of the first few Legendre Polynomials: </p> <p> <span class="inlinemediaobject"><img src="../../../../graphs/legendre_p.png" align="middle"></span> </p> <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> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> </pre> <p> Returns the associated Legendre polynomial of the first kind: </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_1.png"></span> </p> <p> Requires -1 <= x <= 1, otherwise returns the result of <a class="link" href="../../main_overview/error_handling.html#domain_error">domain_error</a>. </p> <p> Negative values of <span class="emphasis"><em>l</em></span> and <span class="emphasis"><em>m</em></span> are handled via the identity relations: </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_3.png"></span> </p> <div class="caution"><table border="0" summary="Caution"> <tr> <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../../doc/src/images/caution.png"></td> <th align="left">Caution</th> </tr> <tr><td align="left" valign="top"> <p> The definition of the associated Legendre polynomial used here includes a leading Condon-Shortley phase term of (-1)<sup>m</sup>. This matches the definition given by Abramowitz and Stegun (8.6.6) and that used by <a href="http://mathworld.wolfram.com/LegendrePolynomial.html" target="_top">Mathworld</a> and <a href="http://documents.wolfram.com/mathematica/functions/LegendreP" target="_top">Mathematica's LegendreP function</a>. However, uses in the literature do not always include this phase term, and strangely the specification for the associated Legendre function in the C++ TR1 (assoc_legendre) also omits it, in spite of stating that it uses Abramowitz and Stegun as the final arbiter on these matters. </p> <p> See: </p> <p> <a href="http://mathworld.wolfram.com/LegendrePolynomial.html" target="_top">Weisstein, Eric W. "Legendre Polynomial." From MathWorld--A Wolfram Web Resource</a>. </p> <p> Abramowitz, M. and Stegun, I. A. (Eds.). "Legendre Functions" and "Orthogonal Polynomials." Ch. 22 in Chs. 8 and 22 in Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, 9th printing. New York: Dover, pp. 331-339 and 771-802, 1972. </p> </td></tr> </table></div> <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> <a class="link" href="../../main_overview/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">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="Policies">Policy</a><span class="special">></span> <a class="link" href="../../main_overview/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="Policies">Policy</a><span class="special">&);</span> </pre> <p> Returns the value of the Legendre polynomial that is the second solution to the Legendre differential equation, for example: </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_2.png"></span> </p> <p> Requires -1 <= x <= 1, otherwise <a class="link" href="../../main_overview/error_handling.html#domain_error">domain_error</a> is called. </p> <p> The following graph illustrates the first few Legendre functions of the second kind: </p> <p> <span class="inlinemediaobject"><img src="../../../../graphs/legendre_q.png" align="middle"></span> </p> <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> <a class="link" href="../../main_overview/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> </pre> <p> Implements the three term recurrence relation for the Legendre polynomials, this function can be used to create a sequence of values evaluated at the same <span class="emphasis"><em>x</em></span>, and for rising <span class="emphasis"><em>l</em></span>. This recurrence relation holds for Legendre Polynomials of both the first and second kinds. </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_4.png"></span> </p> <p> For example we could produce a vector of the first 10 polynomial values using: </p> <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><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> <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><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> <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> <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> </pre> <p> Formally the arguments are: </p> <div class="variablelist"> <p class="title"><b></b></p> <dl> <dt><span class="term">l</span></dt> <dd><p> The degree of the last polynomial calculated. </p></dd> <dt><span class="term">x</span></dt> <dd><p> The abscissa value </p></dd> <dt><span class="term">Pl</span></dt> <dd><p> The value of the polynomial evaluated at degree <span class="emphasis"><em>l</em></span>. </p></dd> <dt><span class="term">Plm1</span></dt> <dd><p> The value of the polynomial evaluated at degree <span class="emphasis"><em>l-1</em></span>. </p></dd> </dl> </div> <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> <a class="link" href="../../main_overview/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> </pre> <p> Implements the three term recurrence relation for the Associated Legendre polynomials, this function can be used to create a sequence of values evaluated at the same <span class="emphasis"><em>x</em></span>, and for rising <span class="emphasis"><em>l</em></span>. </p> <p> <span class="inlinemediaobject"><img src="../../../../equations/legendre_5.png"></span> </p> <p> For example we could produce a vector of the first m+10 polynomial values using: </p> <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><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><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> <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><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> <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">m</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="number">10</span><span class="special">;</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">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">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> </pre> <p> Formally the arguments are: </p> <div class="variablelist"> <p class="title"><b></b></p> <dl> <dt><span class="term">l</span></dt> <dd><p> The degree of the last polynomial calculated. </p></dd> <dt><span class="term">m</span></dt> <dd><p> The order of the Associated Polynomial. </p></dd> <dt><span class="term">x</span></dt> <dd><p> The abscissa value </p></dd> <dt><span class="term">Pl</span></dt> <dd><p> The value of the polynomial evaluated at degree <span class="emphasis"><em>l</em></span>. </p></dd> <dt><span class="term">Plm1</span></dt> <dd><p> The value of the polynomial evaluated at degree <span class="emphasis"><em>l-1</em></span>. </p></dd> </dl> </div> <a name="math_toolkit.special.sf_poly.legendre.accuracy"></a><h5> <a name="id1118494"></a> <a class="link" href="legendre.html#math_toolkit.special.sf_poly.legendre.accuracy">Accuracy</a> </h5> <p> The following table shows peak errors (in units of epsilon) for various domains of input arguments. Note that only results for the widest floating point type on the system are given as narrower types have <a class="link" href="../../backgrounders/relative_error.html#zero_error">effectively zero error</a>. </p> <div class="table"> <a name="id1118512"></a><p class="title"><b>Table 29. Peak Errors In the Legendre P Function</b></p> <div class="table-contents"><table class="table" summary="Peak Errors In the Legendre P Function"> <colgroup> <col> <col> <col> <col> </colgroup> <thead><tr> <th> <p> Significand Size </p> </th> <th> <p> Platform and Compiler </p> </th> <th> <p> Errors in range </p> <p> 0 < l < 20 </p> </th> <th> <p> Errors in range </p> <p> 20 < l < 120 </p> </th> </tr></thead> <tbody> <tr> <td> <p> 53 </p> </td> <td> <p> Win32, Visual C++ 8 </p> </td> <td> <p> Peak=211 Mean=20 </p> </td> <td> <p> Peak=300 Mean=33 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> SUSE Linux IA32, g++ 4.1 </p> </td> <td> <p> Peak=70 Mean=10 </p> </td> <td> <p> Peak=700 Mean=60 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> Red Hat Linux IA64, g++ 3.4.4 </p> </td> <td> <p> Peak=70 Mean=10 </p> </td> <td> <p> Peak=700 Mean=60 </p> </td> </tr> <tr> <td> <p> 113 </p> </td> <td> <p> HPUX IA64, aCC A.06.06 </p> </td> <td> <p> Peak=35 Mean=6 </p> </td> <td> <p> Peak=292 Mean=41 </p> </td> </tr> </tbody> </table></div> </div> <br class="table-break"><div class="table"> <a name="id1118712"></a><p class="title"><b>Table 30. Peak Errors In the Associated Legendre P Function</b></p> <div class="table-contents"><table class="table" summary="Peak Errors In the Associated Legendre P Function"> <colgroup> <col> <col> <col> </colgroup> <thead><tr> <th> <p> Significand Size </p> </th> <th> <p> Platform and Compiler </p> </th> <th> <p> Errors in range </p> <p> 0 < l < 20 </p> </th> </tr></thead> <tbody> <tr> <td> <p> 53 </p> </td> <td> <p> Win32, Visual C++ 8 </p> </td> <td> <p> Peak=1200 Mean=7 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> SUSE Linux IA32, g++ 4.1 </p> </td> <td> <p> Peak=80 Mean=5 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> Red Hat Linux IA64, g++ 3.4.4 </p> </td> <td> <p> Peak=80 Mean=5 </p> </td> </tr> <tr> <td> <p> 113 </p> </td> <td> <p> HPUX IA64, aCC A.06.06 </p> </td> <td> <p> Peak=42 Mean=4 </p> </td> </tr> </tbody> </table></div> </div> <br class="table-break"><div class="table"> <a name="id1118868"></a><p class="title"><b>Table 31. Peak Errors In the Legendre Q Function</b></p> <div class="table-contents"><table class="table" summary="Peak Errors In the Legendre Q Function"> <colgroup> <col> <col> <col> <col> </colgroup> <thead><tr> <th> <p> Significand Size </p> </th> <th> <p> Platform and Compiler </p> </th> <th> <p> Errors in range </p> <p> 0 < l < 20 </p> </th> <th> <p> Errors in range </p> <p> 20 < l < 120 </p> </th> </tr></thead> <tbody> <tr> <td> <p> 53 </p> </td> <td> <p> Win32, Visual C++ 8 </p> </td> <td> <p> Peak=50 Mean=7 </p> </td> <td> <p> Peak=4600 Mean=370 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> SUSE Linux IA32, g++ 4.1 </p> </td> <td> <p> Peak=51 Mean=8 </p> </td> <td> <p> Peak=6000 Mean=480 </p> </td> </tr> <tr> <td> <p> 64 </p> </td> <td> <p> Red Hat Linux IA64, g++ 3.4.4 </p> </td> <td> <p> Peak=51 Mean=8 </p> </td> <td> <p> Peak=6000 Mean=480 </p> </td> </tr> <tr> <td> <p> 113 </p> </td> <td> <p> HPUX IA64, aCC A.06.06 </p> </td> <td> <p> Peak=90 Mean=10 </p> </td> <td> <p> Peak=1700 Mean=140 </p> </td> </tr> </tbody> </table></div> </div> <br class="table-break"><p> Note that the worst errors occur when the order increases, values greater than ~120 are very unlikely to produce sensible results, especially in the associated polynomial case when the degree is also large. Further the relative errors are likely to grow arbitrarily large when the function is very close to a root. </p> <p> No comparisons to other libraries are shown here: there appears to be only one viable implementation method for these functions, the comparisons to other libraries that have been run show identical error rates to those given here. </p> <a name="math_toolkit.special.sf_poly.legendre.testing"></a><h5> <a name="id1119078"></a> <a class="link" href="legendre.html#math_toolkit.special.sf_poly.legendre.testing">Testing</a> </h5> <p> A mixture of spot tests of values calculated using functions.wolfram.com, and randomly generated test data are used: the test data was computed using <a href="http://shoup.net/ntl/doc/RR.txt" target="_top">NTL::RR</a> at 1000-bit precision. </p> <a name="math_toolkit.special.sf_poly.legendre.implementation"></a><h5> <a name="id1119100"></a> <a class="link" href="legendre.html#math_toolkit.special.sf_poly.legendre.implementation">Implementation</a> </h5> <p> These functions are implemented using the stable three term recurrence relations. These relations guarentee low absolute error but cannot guarentee low relative error near one of the roots of the polynomials. </p> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2006 , 2007, 2008, 2009 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg<p> Distributed under the Boost Software License, Version 1.0. (See accompanying 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>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <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> </div> </body> </html>