44
44
typedef Distribution::Uniform Uniform;
45
45
typedef Base::Common::InvalidArgumentException InvalidArgumentException;
48
48
/* Default constructor */
49
49
LegendreFactory::LegendreFactory()
50
: OrthogonalUniVariatePolynomialFactory(Uniform())
50
: OrthogonalUniVariatePolynomialFactory(Uniform())
56
56
/* Virtual constructor */
57
57
LegendreFactory * LegendreFactory::clone() const
59
return new LegendreFactory(*this);
63
/* Determine the coefficients of the first Legendre polynomial*/
64
LegendreFactory::Coefficients LegendreFactory::getP0Coefficients() const
66
Coefficients Legendre0Coefficients(1); // Coefficients of the first Orthonormal Legendre-Polynomial
67
Legendre0Coefficients[0] = 1.0;
68
return Legendre0Coefficients;
72
/* Determine the coefficients of the second Legendre polynomial*/
73
LegendreFactory::Coefficients LegendreFactory::getP1Coefficients() const
75
Coefficients Legendre1Coefficients(2); // Coefficients of the second Orthonormal Legendre-Polynomial
76
Legendre1Coefficients[0] = 0.0;
77
Legendre1Coefficients[1] = sqrt(3.0);
78
return Legendre1Coefficients;
81
/* Calculate the coefficients of recurrence a0, a1, a2 such that
82
Pn(x) = (a0 * x + a1) * Pn-1(x) + a2 * Pn-2(x) */
59
return new LegendreFactory(*this);
63
/* Calculate the coefficients of recurrence a0n, a1n, a2n such that
64
Pn+1(x) = (a0n * x + a1n) * Pn(x) + a2n * Pn-1(x) */
83
65
LegendreFactory::Coefficients LegendreFactory::getRecurrenceCoefficients(const UnsignedLong n) const
85
if (n < 2) throw InvalidArgumentException(HERE) << "Error: cannot compute recurrence coefficients for n < 2.";
86
Coefficients recurrenceCoefficients(3);
87
recurrenceCoefficients[0] = sqrt((2.0 * n - 1.0) * (2.0 * n + 1.0)) / n;
88
recurrenceCoefficients[1] = 0.0;
89
recurrenceCoefficients[2] = -(n - 1.0) * sqrt((2.0 * n + 1.0) / (2.0 * n - 3.0)) / n;
90
return recurrenceCoefficients;
67
Coefficients recurrenceCoefficients(3, 0.0);
70
recurrenceCoefficients[0] = sqrt(3.0);
71
recurrenceCoefficients[1] = 0.0;
72
// Conventional value of 0.0 for recurrenceCoefficients[2]
73
return recurrenceCoefficients;
75
const NumericalScalar factor(sqrt(2.0 * n + 3.0) / (n + 1.0));
76
recurrenceCoefficients[0] = sqrt(2.0 * n + 1.0) * factor;
77
recurrenceCoefficients[1] = 0.0;
78
recurrenceCoefficients[2] = -factor * n / sqrt(2.0 * n - 1.0);
79
return recurrenceCoefficients;
94
83
/* String converter */
95
84
String LegendreFactory::__repr__() const
97
return OSS() << "class=" << getClassName()
98
<< " measure=" << measure_;
86
return OSS() << "class=" << getClassName()
87
<< " measure=" << measure_;