1 #ifndef _utl_TabulatedFunction_h_
2 #define _utl_TabulatedFunction_h_
4 #include <utl/TabulatedFunctionIterators.h>
5 #include <utl/IteratorRange.h>
30 typedef std::vector<double>
Array;
40 const double boundaryTolerance = 1e-3) :
46 const std::vector<double>& yValues,
47 const unsigned int interpolationOrder = 1,
48 const double boundaryTolerance = 1e-3) :
62 void PushBack(
const double x,
const double y);
152 double Y(
const double x)
const
156 double InterpolateY(
const double x,
const unsigned int polyDegree)
const;
162 const double&
GetY(
const unsigned int idx)
const {
return fY[idx]; }
165 const double&
GetX(
const unsigned int idx)
const {
return fX[idx]; }
167 double&
GetX(
const unsigned int idx) {
return fX[idx]; }
168 double&
GetY(
const unsigned int idx) {
return fY[idx]; }
171 double SumX()
const {
return std::accumulate(
fX.begin(),
fX.end(), 0.); }
174 double SumY()
const {
return std::accumulate(
fY.begin(),
fY.end(), 0.); }
177 {
return fX.front() <= x && x <=
fX.back(); }
180 {
return fX == t.
fX &&
fY == t.
fY; }
199 [&s](
auto const& elem) {
return elem *
s; }
208 [&s](
auto const& elem) {
return elem *
s; }
223 void FillTable(
const std::vector<double>& xValues,
224 const std::vector<double>& yValues);
Pair operator[](const int idx) const
Note: cannot be used in assignment.
Array::reverse_iterator ArrayReverseIterator
double fBoundaryTolerance
unsigned int GetNPoints() const
ConstIterator FindY(const double y) const
void swap(utl::Trace< T > &t1, utl::Trace< T > &t2)
ArrayConstIterator YBegin() const
begin of array of Y
TabulatedFunction(const unsigned int interpolationOrder=1, const double boundaryTolerance=1e-3)
ArrayConstReference XBack() const
read-only reference to back of array of X
#define OFFLINE_MAKE_BOTH_ITERATOR_RANGES(_Iterator_, _ConstIterator_, _NamePrefix_)
ConstTabulatedFunctionIterator ConstIterator
#define OFFLINE_MAKE_BOTH_FRIEND_RANGES(_Iterator_, _ConstIterator_, _Class_)
Array::const_iterator ArrayConstIterator
ArrayReverseIterator YREnd()
end reverse iterator for Y
ArrayReverseIterator XREnd()
end reverse iterator for X
void swap(utl::TabulatedFunction &t1, utl::TabulatedFunction &t2)
ArrayIterator XEnd()
end of array of X
ConstIterator End() const
Class to hold collection (x,y) points and provide interpolation between them.
ConstIterator FindX(const double x) const
TabulatedFunction(const std::vector< double > &xValues, const std::vector< double > &yValues, const unsigned int interpolationOrder=1, const double boundaryTolerance=1e-3)
bool IsInValidRange(const double x) const
ArrayConstIterator XBegin() const
begin of array of X
ArrayConstReverseIterator XREnd() const
double operator()(const double x) const
void PushBack(const double x, const double y)
unsigned int fInterpolationOrder
double & GetY(const unsigned int idx)
double SumY() const
return the sum of Y values
ArrayConstReverseIterator YRBegin() const
begin reverse iterator for Y
std::vector< double > Array
ArrayConstReference XFront() const
read-only reference to front of array of X
ConstIterator Begin() const
Array::const_reference ArrayConstReference
bool operator==(const TabulatedFunction &t) const
Iterator Insert(const double x, const double y)
ArrayConstReference YFront() const
read-only reference to front of array of Y
void FillTable(const std::vector< double > &xValues, const std::vector< double > &yValues)
ArrayReverseIterator XRBegin()
begin reverse iterator for X
TabulatedFunctionIterator Iterator
ArrayConstReverseIterator XRBegin() const
begin reverse iterator for X
const double & GetY(const unsigned int idx) const
ArrayIterator YBegin()
begin of array of Y
void SetInterpolationOrder(const unsigned int interpolationOrder)
double & GetX(const unsigned int idx)
void SetBoundaryTolerance(const double tolerance)
ArrayConstReference YBack() const
read-only reference to back of array of Y
Array::iterator ArrayIterator
Array::const_reverse_iterator ArrayConstReverseIterator
double InterpolateY(const double x, const unsigned int polyDegree) const
Interpolate the Y value with a polyDegree polynomial.
ArrayIterator XBegin()
begin of array of X
ArrayConstIterator XEnd() const
end of array of X
unsigned int GetInterpolationOrder() const
double LinearInterpolateY(const double x) const
bool operator!=(const TabulatedFunction &t) const
void Swap(TabulatedFunction &tf)
const double & GetX(const unsigned int idx) const
ArrayConstReverseIterator YREnd() const
end reverse iterator for Y
ArrayIterator YEnd()
end of array of Y
ArrayConstIterator YEnd() const
end of array of Y
a pair of graph points (x,y)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
double GetBoundaryTolerance() const
void ScaleY(const double s)
void ScaleX(const double s)
ArrayReverseIterator YRBegin()
begin reverse iterator for Y
double SumX() const
return the sum of X values