~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/OrthogonalBasis/LegendreFactory.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-05-10 17:27:55 UTC
  • mfrom: (1.1.4 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100510172755-cb5ynskknqqi5rhp
Tags: 0.13.2-2ubuntu1
* Merge with Debian testing. No changes left.
* ubuntu_fix-python-2.6.patch: fix detection of python 2.6 libs, to not use
  LOCALMODLIBS. This pulls a dependency on SSL and makes the package FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  @file  LegendreFactory.cxx
4
4
 *  @brief Legendre polynomial factory
5
5
 *
6
 
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
6
 *  (C) Copyright 2005-2010 EDF-EADS-Phimeca
7
7
 *
8
8
 *  This library is free software; you can redistribute it and/or
9
9
 *  modify it under the terms of the GNU Lesser General Public
43
43
 
44
44
      typedef Distribution::Uniform                  Uniform;
45
45
      typedef Base::Common::InvalidArgumentException InvalidArgumentException;
46
 
      
 
46
 
47
47
 
48
48
      /* Default constructor */
49
49
      LegendreFactory::LegendreFactory()
50
 
        : OrthogonalUniVariatePolynomialFactory(Uniform())
 
50
        : OrthogonalUniVariatePolynomialFactory(Uniform())
51
51
      {
52
 
        initializeCache();
 
52
        initializeCache();
53
53
      }
54
54
 
55
55
 
56
56
      /* Virtual constructor */
57
57
      LegendreFactory * LegendreFactory::clone() const
58
58
      {
59
 
        return new LegendreFactory(*this);
60
 
      }
61
 
 
62
 
 
63
 
      /* Determine the coefficients of the first Legendre polynomial*/
64
 
      LegendreFactory::Coefficients LegendreFactory::getP0Coefficients() const
65
 
      {
66
 
        Coefficients Legendre0Coefficients(1); // Coefficients of the first Orthonormal Legendre-Polynomial
67
 
        Legendre0Coefficients[0] = 1.0;
68
 
        return Legendre0Coefficients;
69
 
      }
70
 
 
71
 
 
72
 
      /* Determine the coefficients of the second Legendre polynomial*/
73
 
      LegendreFactory::Coefficients LegendreFactory::getP1Coefficients() const
74
 
      {
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;
79
 
      }
80
 
 
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);
 
60
      }
 
61
 
 
62
 
 
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
84
66
      {
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);
 
68
        if (n == 0)
 
69
          {
 
70
            recurrenceCoefficients[0] = sqrt(3.0);
 
71
            recurrenceCoefficients[1] = 0.0;
 
72
            // Conventional value of 0.0 for recurrenceCoefficients[2]
 
73
            return recurrenceCoefficients;
 
74
          }
 
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;
91
80
      }
92
81
 
93
82
 
94
83
      /* String converter */
95
84
      String LegendreFactory::__repr__() const
96
85
      {
97
 
        return OSS() << "class=" << getClassName()
98
 
                     << " measure=" << measure_;
 
86
        return OSS() << "class=" << getClassName()
 
87
                     << " measure=" << measure_;
99
88
      }
100
89
 
101
90