Biogeme: Python Library  2.5
legendre.py
Go to the documentation of this file.
1 ## \file
2 # Fonctions for transformed Legendre polynomials, orthonormal on [0,1]: \f[ L_n(x) = \frac{\sqrt{4n^2-1}}{n}(2x-1)L_{n-1}(x)-\frac{(n-1)\sqrt{2n+1}}{n \sqrt{2n-3}} L_{n-2}(x), \f] with \f$L_0(x)=1\f$, \f$L_1(x)=\sqrt{3}(2x-1)\f$ and \f$L_2(x) = \sqrt{5}(6x^2-6x+1)\f$. See \cite FosgBier07.
3 from math import sqrt
4 
5 ## Implements the transformed Legendre polynomials of degree 0 \f[ L_0(x) = 1 \f]
6 # \param x argument of the polynomial
7 # \return value of the polynomial
8 # \ingroup specs
9 def legendre00(x):
10  return 1
11 
12 ## Implements the transformed Legendre polynomials of degree 1 \f[ L_1(x)=\sqrt{3}(2x-1) \f]
13 # \param x argument of the polynomial
14 # \return value of the polynomial
15 # \ingroup specs
16 def legendre01(x):
17  return sqrt(3.0) * (2 * x - 1)
18 
19 ## Implements the transformed Legendre polynomials of degree 2 \f[ L_2(x)=\sqrt{5}(6x^2-6x+1) \f]
20 # \param x argument of the polynomial
21 # \return value of the polynomial
22 # \ingroup specs
23 def legendre02(x):
24  return sqrt(5.0) * (6 * x * x - 6 * x + 1)
25 
26 ## Implements the transformed Legendre polynomials of degree 3 \f[ L_3(x)=\sqrt{7}(20 x^3 30 x^2+12x-1) \f]
27 # \param x argument of the polynomial
28 # \return value of the polynomial
29 # \ingroup specs
30 def legendre03(x):
31  return sqrt(7.0) * (20 * x * x * x - 30 * x * x + 12 * x - 1)
32 
33 ## Implements the transformed Legendre polynomials of degree 4
34 # \param x argument of the polynomial
35 # \return value of the polynomial
36 # \ingroup specs
37 def legendre04(x):
38  i = 4
39  t1 = sqrt(4 * i * i - 1) / i
40  t2 = (i-1)*sqrt(2*i+1)/(i*sqrt(2*i-3))
41  return t1 * (2*x-1) * legendre03(x) - t2 * legendre02(x)
42 
43 ## Implements the transformed Legendre polynomials of degree 5
44 # \param x argument of the polynomial
45 # \return value of the polynomial
46 # \ingroup specs
47 def legendre05(x):
48  i = 5
49  t1 = sqrt(4 * i * i - 1) / i
50  t2 = (i-1)*sqrt(2*i+1)/(i*sqrt(2*i-3))
51  return t1 * (2*x-1) * legendre04(x) - t2 * legendre03(x)
52 
53 ## Implements the transformed Legendre polynomials of degree 6
54 # \param x argument of the polynomial
55 # \return value of the polynomial
56 # \ingroup specs
57 def legendre06(x):
58  i = 6
59  t1 = sqrt(4 * i * i - 1) / i
60  t2 = (i-1)*sqrt(2*i+1)/(i*sqrt(2*i-3))
61  return t1 * (2*x-1) * legendre05(x) - t2 * legendre04(x)
62 
63 ## Implements the transformed Legendre polynomials of degree 7
64 # \param x argument of the polynomial
65 # \return value of the polynomial
66 # \ingroup specs
67 def legendre07(x):
68  i = 7
69  t1 = sqrt(4 * i * i - 1) / i
70  t2 = (i-1)*sqrt(2*i+1)/(i*sqrt(2*i-3))
71  return t1 * (2*x-1) * legendre06(x) - t2 * legendre05(x)
72 
def legendre04(x)
Implements the transformed Legendre polynomials of degree 4.
Definition: legendre.py:37
def legendre00(x)
Implements the transformed Legendre polynomials of degree 0 .
Definition: legendre.py:9
def legendre06(x)
Implements the transformed Legendre polynomials of degree 6.
Definition: legendre.py:57
def legendre01(x)
Implements the transformed Legendre polynomials of degree 1 .
Definition: legendre.py:16
def legendre02(x)
Implements the transformed Legendre polynomials of degree 2 .
Definition: legendre.py:23
def legendre05(x)
Implements the transformed Legendre polynomials of degree 5.
Definition: legendre.py:47
def legendre03(x)
Implements the transformed Legendre polynomials of degree 3 .
Definition: legendre.py:30
def legendre07(x)
Implements the transformed Legendre polynomials of degree 7.
Definition: legendre.py:67
Copyright 2016 Michel Bierlaire