![]() |
Home | Libraries | People | FAQ | More |
#include <boost/math/special_functions/laguerre.hpp>
namespace boost{ namespace math{ template <class T> calculated-result-type laguerre(unsigned n, T x); template <class T, class Policy> calculated-result-type laguerre(unsigned n, T x, const Policy&); template <class T> calculated-result-type laguerre(unsigned n, unsigned m, T x); template <class T, class Policy> calculated-result-type laguerre(unsigned n, unsigned m, T x, const Policy&); template <class T1, class T2> calculated-result-type laguerre(unsigned n, T1 alpha, T2 x); template <class T1, class T2, class Policy> calculated-result-type laguerre(unsigned n, T1 alpha, T2 x, const Policy&); template <class T1, class T2, class T3> calculated-result-type laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); template <class T1, class T2, class T3> calculated-result-type laguerre_next(unsigned n, unsigned m, T1 x, T2 Ln, T3 Lnm1); template <class T> std::vector<T> laguerre_zeros(unsigned n, T alpha = 0); template <class T, class Policy> std::vector<T> laguerre_zeros(unsigned n, T alpha, const Policy&); }} // 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> calculated-result-type laguerre(unsigned n, T x); template <class T, class Policy> calculated-result-type 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> calculated-result-type laguerre(unsigned n, unsigned m, T x); template <class T, class Policy> calculated-result-type 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> calculated-result-type laguerre(unsigned n, T1 alpha, T2 x); template <class T1, class T2, class Policy> calculated-result-type laguerre(unsigned n, T1 alpha, T2 x, const Policy&);
When alpha has a floating-point type, returns the generalized Laguerre polynomial of degree n and parameter α at x,
Ln(α)(x) = ∑k=0n (-1)k C(n + α, n - k) xk / k!,
which is orthogonal for the weight xα e-x on
[0, ∞) when α > -1, but is a polynomial for any real α. For an integer α =
m it is the associated polynomial above, and for α = 0
the Laguerre polynomial. The result type is computed from both arguments;
an integer order m leaves it to x
alone. Its zeros are given by laguerre_zeros,
below.
template <class T1, class T2, class T3> calculated-result-type 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[l-1]));
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 n-1.
template <class T1, class T2, class T3> calculated-result-type 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[l-1]));
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 n-1.
laguerre_zeros returns the
n zeros of the generalized Laguerre polynomial Ln(α),
in increasing order; they are all positive. For n =
0 the result is empty. Ln(α) is orthogonal
for the weight xα e-x on [0, ∞), and
for integer α = m it is the associated polynomial laguerre(n, m, x)
above. α must be finite and greater than -1, otherwise the result is a vector
of n values returned by domain_error.
The type T must be a floating-point type: write laguerre_zeros<double>(n) or
laguerre_zeros(n, 0.5). These are the abscissas of the Gauss-Laguerre
quadrature rule.
The zeros are found in O(n) operations by following
the differential equation of the Laguerre functions from zero to zero in
twice the working precision (Glaser, Liu and Rokhlin). Where that cannot
vouch for a zero, the zeros come from the three-term recurrence instead,
which overflows for large n combined with large α (in
double, for example n
= 2000 and α = 50): the result is then a vector of values returned by evaluation_error.
In our tests against high-precision values they are correctly rounded in
float, double
and 50-digit precision.
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 8.35. Error rates for laguerre(n, x)
|
GNU C++ version 7.1.0 |
GNU C++ version 7.1.0 |
Sun compiler version 0x5150 |
Microsoft Visual C++ version 14.1 |
|
|---|---|---|---|---|
|
Laguerre Polynomials |
Max = 6.82ε (Mean = 0.408ε) |
Max = 1.39e+04ε (Mean = 828ε) |
Max = 1.39e+04ε (Mean = 828ε) |
Max = 3.1e+03ε (Mean = 185ε) |
Table 8.36. Error rates for laguerre(n, m, x)
|
GNU C++ version 7.1.0 |
GNU C++ version 7.1.0 |
Sun compiler version 0x5150 |
Microsoft Visual C++ version 14.1 |
|
|---|---|---|---|---|
|
Associated Laguerre Polynomials |
Max = 0.84ε (Mean = 0.0358ε) |
Max = 167ε (Mean = 6.38ε) |
Max = 167ε (Mean = 6.38ε) |
Max = 434ε (Mean = 11.1ε) |
Near a root the relative error grows with the condition number |x L'(x) / L(x)|, as for any method that is given x rounded to the working precision.
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 1000-bit precision.
These functions are implemented using the three term recurrence relations.
On its own the recurrence loses up to about n1.5 ε where
the polynomial oscillates, so the rounding error of each step, and of its
coefficients 2/c/ + 1 + α - x and c
+ α, is found almost exactly and carried forward by the same recurrence. In
tests against 600-bit sums the Laguerre, associated and generalized polynomials
are then correctly rounded in double,
for degrees up to 200 and the arguments tested, at about 10 ns per degree.