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

References m_functionValues, m_positionValues, and 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 }
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
Base1D1DFunction(double minDomainValue, double maxDomainValue)
Default constructor.
Definition: 1D1DFunction.C:33
std::vector< double > m_positionValues
Definition: 1D1DFunction.h:584
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585
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, queso_not_implemented, queso_require_msg, 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 
813 
814  return value;
815 }
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
#define queso_not_implemented()
Definition: asserts.h:56
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 k, 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_positionValues
Definition: 1D1DFunction.h:584
std::vector< double > m_functionValues
Definition: 1D1DFunction.h:585
int k
Definition: ann_sample.cpp:53

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 Jun 11 2015 13:52:35 for queso-0.53.0 by  doxygen 1.8.5