queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::LagrangePolynomial1D1DFunction Class Reference

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

#include <1D1DFunction.h>

Inheritance diagram for QUESO::LagrangePolynomial1D1DFunction:
QUESO::Base1D1DFunction

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 743 of file 1D1DFunction.C.

References m_functionValues, m_positionValues, and QUESO::queso_require_equal_to_msg.

746  :
747  Base1D1DFunction(-INFINITY,INFINITY),
748  m_positionValues(positionValues),
749  m_functionValues(positionValues.size(),1.)
750 {
751  if (functionValues) {
752  queso_require_equal_to_msg(m_positionValues.size(), functionValues->size(), "invalid input");
753  m_functionValues = *functionValues;
754  }
755 }
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585
std::vector< double > m_positionValues
Definition: 1D1DFunction.h:584
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
QUESO::LagrangePolynomial1D1DFunction::~LagrangePolynomial1D1DFunction ( )

Destructor.

Definition at line 757 of file 1D1DFunction.C.

758 {
759 }

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 797 of file 1D1DFunction.C.

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

798 {
799  double value = 0.;
800 
801  if ((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)) {
802  std::cerr << "In LagrangePolynomial1D1DFunction::deriv()"
803  << ": requested x (" << domainValue
804  << ") is out of the interval (" << m_minDomainValue
805  << ", " << m_maxDomainValue
806  << ")"
807  << std::endl;
808  }
809 
810  queso_require_msg(!((domainValue < m_minDomainValue) || (domainValue > m_maxDomainValue)), "x out of range");
811 
812  queso_not_implemented();
813 
814  return value;
815 }
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
Definition: 1D1DFunction.C:762
double QUESO::LagrangePolynomial1D1DFunction::value ( double  domainValue) const
virtual

Returns the value of the Lagrange polynomial at point domainValue.

Implements QUESO::Base1D1DFunction.

Definition at line 762 of file 1D1DFunction.C.

References m_functionValues, and m_positionValues.

Referenced by deriv().

763 {
764  double value = 0.;
765 
766  for (unsigned int k = 0; k < m_positionValues.size(); ++k) {
767  double scaleFactor = 1.;
768  double posK = m_positionValues[k];
769  for (unsigned int j = 0; j < m_positionValues.size(); ++j) {
770  if (j != k) {
771  double posJ = m_positionValues[j];
772  scaleFactor *= (domainValue-posJ)/(posK-posJ);
773  }
774  }
775 
776  //if (m_env.subDisplayFile()) {
777  // *m_env.subDisplayFile() << "In sddTG<K_V,K_M>::lagrange()"
778  // << ": k = " << k
779  // << ", scaleFactor = " << scaleFactor
780  // << std::endl;
781  //}
782 
783  value += scaleFactor * m_functionValues[k];
784 
785  //if (m_env.subDisplayFile()) {
786  // *m_env.subDisplayFile() << "In sddTG<K_V,K_M>::lagrange()"
787  // << ": k = " << k
788  // << ", value = " << value
789  // << std::endl;
790  //}
791  }
792 
793  return value;
794 }
double value(double domainValue) const
Returns the value of the Lagrange polynomial at point domainValue.
Definition: 1D1DFunction.C:762
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585
std::vector< double > m_positionValues
Definition: 1D1DFunction.h:584

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 Tue Jun 5 2018 19:49:18 for queso-0.57.1 by  doxygen 1.8.5