...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/special_functions/laguerre.hpp>
namespace boost{ namespace math{ template <class T> calculatedresulttype laguerre(unsigned n, T x); template <class T, class Policy> calculatedresulttype laguerre(unsigned n, T x, const Policy&); template <class T> calculatedresulttype laguerre(unsigned n, unsigned m, T x); template <class T, class Policy> calculatedresulttype laguerre(unsigned n, unsigned m, T x, const Policy&); template <class T1, class T2, class T3> calculatedresulttype laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); template <class T1, class T2, class T3> calculatedresulttype laguerre_next(unsigned n, unsigned m, T1 x, T2 Ln, T3 Lnm1); }} // namespaces
The return type of these functions is computed using the result
type calculation rules: note than when there is a single
template argument the result is the same type as that argument or double
if the template argument is an integer
type.
The final Policy 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 policy documentation for more details.
template <class T> calculatedresulttype laguerre(unsigned n, T x); template <class T, class Policy> calculatedresulttype laguerre(unsigned n, T x, const Policy&);
Returns the value of the Laguerre Polynomial of order n at point x:
The following graph illustrates the behaviour of the first few Laguerre Polynomials:
template <class T> calculatedresulttype laguerre(unsigned n, unsigned m, T x); template <class T, class Policy> calculatedresulttype laguerre(unsigned n, unsigned m, T x, const Policy&);
Returns the Associated Laguerre polynomial of degree n and order m at point x:
template <class T1, class T2, class T3> calculatedresulttype laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1);
Implements the three term recurrence relation for the Laguerre polynomials, this function can be used to create a sequence of values evaluated at the same x, and for rising n.
For example we could produce a vector of the first 10 polynomial values using:
double x = 0.5; // Abscissa value vector<double> v; v.push_back(laguerre(0, x)).push_back(laguerre(1, x)); for(unsigned l = 1; l < 10; ++l) v.push_back(laguerre_next(l, x, v[l], v[l1]));
Formally the arguments are:
The degree n of the last polynomial calculated.
The abscissa value
The value of the polynomial evaluated at degree n.
The value of the polynomial evaluated at degree n1.
template <class T1, class T2, class T3> calculatedresulttype laguerre_next(unsigned n, unsigned m, T1 x, T2 Ln, T3 Lnm1);
Implements the three term recurrence relation for the Associated Laguerre polynomials, this function can be used to create a sequence of values evaluated at the same x, and for rising degree n.
For example we could produce a vector of the first 10 polynomial values using:
double x = 0.5; // Abscissa value int m = 10; // order vector<double> v; v.push_back(laguerre(0, m, x)).push_back(laguerre(1, m, x)); for(unsigned l = 1; l < 10; ++l) v.push_back(laguerre_next(l, m, x, v[l], v[l1]));
Formally the arguments are:
The degree of the last polynomial calculated.
The order of the Associated Polynomial.
The abscissa value.
The value of the polynomial evaluated at degree n.
The value of the polynomial evaluated at degree n1.
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 effectively zero error.
Table 6.35. Error rates for laguerre(n, x)
Microsoft Visual C++ version 12.0 
GNU C++ version 5.1.0 
GNU C++ version 5.1.0 
Sun compiler version 0x5130 


Laguerre Polynomials 
Max = 3.1e+003ε (Mean = 185ε) 
Max = 6.82ε (Mean = 0.408ε) 
Max = 1.39e+04ε (Mean = 828ε) 
Max = 1.39e+04ε (Mean = 828ε) 
Table 6.36. Error rates for laguerre(n, m, x)
Microsoft Visual C++ version 12.0 
GNU C++ version 5.1.0 
GNU C++ version 5.1.0 
Sun compiler version 0x5130 


Associated Laguerre Polynomials 
Max = 434ε (Mean = 11.1ε) 
Max = 0.84ε (Mean = 0.0358ε) 
Max = 167ε (Mean = 6.38ε) 
Max = 167ε (Mean = 6.38ε) 
Note that the worst errors occur when the degree increases, values greater than ~120 are very unlikely to produce sensible results, especially in the associated polynomial case when the order is also large. Further the relative errors are likely to grow arbitrarily large when the function is very close to a root.
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 NTL::RR at 1000bit precision.
These functions are implemented using the stable three term recurrence relations. These relations guarantee low absolute error but cannot guarantee low relative error near one of the roots of the polynomials.