queso-0.51.1
Protected Attributes | List of all members
QUESO::LagrangePolynomial1D1DFunction Class Reference

Class for one-dimensional Lagrange polynomials. More...

#include <1D1DFunction.h>

Inheritance diagram for QUESO::LagrangePolynomial1D1DFunction:
Inheritance graph
[legend]
Collaboration diagram for QUESO::LagrangePolynomial1D1DFunction:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 LagrangePolynomial1D1DFunction (const std::vector< double > &positionValues, const std::vector< double > *functionValues)
 Default constructor. More...
 
 ~LagrangePolynomial1D1DFunction ()
 Destructor. More...
 
Mathematical methods
double value (double domainValue) const
 Returns the value of the Lagrange polynomial at point domainValue. More...
 
double deriv (double domainValue) const
 TODO: Returns the value of the derivative of the Lagrange polynomial at point domainValue. More...
 
- Public Member Functions inherited from QUESO::Base1D1DFunction
 Base1D1DFunction (double minDomainValue, double maxDomainValue)
 Default constructor. More...
 
virtual ~Base1D1DFunction ()
 Destructor. More...
 
double minDomainValue () const
 Returns the minimum value of the domain of the (one-dimensional) function. More...
 
double maxDomainValue () const
 Returns the maximum value of the domain of the (one-dimensional) function. More...
 
virtual double multiplyAndIntegrate (const Base1D1DFunction &func, unsigned int quadratureOrder, double *resultWithMultiplicationByTAsWell) const
 TODO: Multiplies this function with function, and integrates it numerically. See template specialization. More...
 

Protected Attributes

std::vector< double > m_positionValues
 
std::vector< double > m_functionValues
 
- Protected Attributes inherited from QUESO::Base1D1DFunction
double m_minDomainValue
 
double m_maxDomainValue
 

Detailed Description

Class for one-dimensional Lagrange polynomials.

The Lagrange interpolating polynomial of a one-dimensional function $ f(x) = y $ is the polynomial $ P(x) $ of degree $ \leq n-1 $ that passes through the $ n $ points $ (x_1,y_1=f(x_1)), (x_2,y_2=f(x_2)), ..., (x_n,y_n=f(x_n))$, and is given by:

\[ P(x)=\sum_{j=1}^n \prod_{k=1; k\not=j}^n \frac{x-x_k}{x_j-x_k}.\]

Written explicitly,

\[ P(x)=\frac{(x-x_2)(x-x_3)...(x-x_n)}{(x_1-x_2)(x_1-x_3)...(x_1-x_n)}y_1+ \frac{(x-x_1)(x-x_3)...(x-x_n)}{(x_2-x_1)(x_2-x_3)...(x_2-x_n)}y_2+...+ \frac{(x-x_1)(x-x_2)...(x-x_(n-1))}{(x_n-x_1)(x_n-x_2)...(x_n-x_(n-1))}y_n.\]

In this class, the array std::vector<double>& positionValues stores the points $ x_1, x_2, ... x_n $ and the array std::vector<double>* functionValues stores the points $ y_1, y_2, ... y_n $ of the Lagrange polynomial.

See Also
Archer, Branden and Weisstein, Eric W. "Lagrange Interpolating Polynomial." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html.

Definition at line 558 of file 1D1DFunction.h.

Constructor & Destructor Documentation

QUESO::LagrangePolynomial1D1DFunction::LagrangePolynomial1D1DFunction ( const std::vector< double > &  positionValues,
const std::vector< double > *  functionValues 
)

Default constructor.

Definition at line 827 of file 1D1DFunction.C.

References m_functionValues, m_positionValues, UQ_FATAL_TEST_MACRO, and QUESO::UQ_UNAVAILABLE_RANK.

830  :
831  Base1D1DFunction(-INFINITY,INFINITY),
832  m_positionValues(positionValues),
833  m_functionValues(positionValues.size(),1.)
834 {
835  if (functionValues) {
836  UQ_FATAL_TEST_MACRO(m_positionValues.size() != functionValues->size(),
838  "LagrangePolynomial1D1DFunction::constructor()",
839  "invalid input");
840  m_functionValues = *functionValues;
841  }
842 }
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
std::vector< double > m_positionValues
Definition: 1D1DFunction.h:584
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585
QUESO::LagrangePolynomial1D1DFunction::~LagrangePolynomial1D1DFunction ( )

Destructor.

Definition at line 844 of file 1D1DFunction.C.

845 {
846 }

Member Function Documentation

double QUESO::LagrangePolynomial1D1DFunction::deriv ( double  domainValue) const
virtual

TODO: Returns the value of the derivative of the Lagrange polynomial at point domainValue.

Todo:
This function checks if point domainValue belongs to the domain of this function, and in affirmative case, it returns the value of the derivative at such point.

Implements QUESO::Base1D1DFunction.

Definition at line 884 of file 1D1DFunction.C.

References QUESO::Base1D1DFunction::m_maxDomainValue, QUESO::Base1D1DFunction::m_minDomainValue, UQ_FATAL_TEST_MACRO, QUESO::UQ_UNAVAILABLE_RANK, and value().

885 {
886  double value = 0.;
887 
888  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
889  std::cerr << "In LagrangePolynomial1D1DFunction::deriv()"
890  << ": requested x (" << domainValue
891  << ") is out of the interval (" << m_minDomainValue
892  << ", " << m_maxDomainValue
893  << ")"
894  << std::endl;
895  }
896 
897  UQ_FATAL_TEST_MACRO(((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)),
899  "LagrangePolynomial1D1DFunction::deriv()",
900  "x out of range");
901 
902  UQ_FATAL_TEST_MACRO(true,
904  "LagrangePolynomial1D1DFunction::deriv()",
905  "not implemented yet");
906 
907  return value;
908 }
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
Definition: 1D1DFunction.C:849
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
double QUESO::LagrangePolynomial1D1DFunction::value ( double  domainValue) const
virtual

Returns the value of the Lagrange polynomial at point domainValue.

Implements QUESO::Base1D1DFunction.

Definition at line 849 of file 1D1DFunction.C.

References m_functionValues, and m_positionValues.

Referenced by deriv().

850 {
851  double value = 0.;
852 
853  for (unsigned int k = 0; k < m_positionValues.size(); ++k) {
854  double scaleFactor = 1.;
855  double posK = m_positionValues[k];
856  for (unsigned int j = 0; j < m_positionValues.size(); ++j) {
857  if (j != k) {
858  double posJ = m_positionValues[j];
859  scaleFactor *= (domainValue-posJ)/(posK-posJ);
860  }
861  }
862 
863  //if (m_env.subDisplayFile()) {
864  // *m_env.subDisplayFile() << "In sddTG<K_V,K_M>::lagrange()"
865  // << ": k = " << k
866  // << ", scaleFactor = " << scaleFactor
867  // << std::endl;
868  //}
869 
870  value += scaleFactor * m_functionValues[k];
871 
872  //if (m_env.subDisplayFile()) {
873  // *m_env.subDisplayFile() << "In sddTG<K_V,K_M>::lagrange()"
874  // << ": k = " << k
875  // << ", value = " << value
876  // << std::endl;
877  //}
878  }
879 
880  return value;
881 }
std::vector< double > m_positionValues
Definition: 1D1DFunction.h:584
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
Definition: 1D1DFunction.C:849
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585

Member Data Documentation

std::vector<double> QUESO::LagrangePolynomial1D1DFunction::m_functionValues
protected

Definition at line 585 of file 1D1DFunction.h.

Referenced by LagrangePolynomial1D1DFunction(), and value().

std::vector<double> QUESO::LagrangePolynomial1D1DFunction::m_positionValues
protected

Definition at line 584 of file 1D1DFunction.h.

Referenced by LagrangePolynomial1D1DFunction(), and value().


The documentation for this class was generated from the following files:

Generated on Thu Apr 23 2015 19:26:17 for queso-0.51.1 by  doxygen 1.8.5