Public Member Functions | Private Member Functions | Private Attributes | List of all members
gnsstk::CubicSpline< T > Class Template Reference

Detailed Description

template<class T>
class gnsstk::CubicSpline< T >

Cubic spline interpolation.

*&;/

Definition at line 56 of file CubicSpline.hpp.

#include <CubicSpline.hpp>

Public Member Functions

 CubicSpline ()
 Empty constructor - NB must call initialize() before Eval(). More...
 
 CubicSpline (const std::vector< T > &X, const std::vector< T > &Y)
 
std::vector< T > evaluate (const std::vector< T > &x)
 
evaluate (const T &x)
 
void initialize (const std::vector< T > &X, const std::vector< T > &Y)
 
void initialize (const std::vector< T > &X, const std::vector< T > &Y, const T DYDX1, const T DYDXN)
 
int size () const
 Return the current size of the second derivative array. More...
 
bool testLimits (const T &x, T &y)
 

Private Member Functions

void build (const std::vector< T > &x, const std::vector< T > &y, bool fixEnds)
 
interpolate (const int k, const T x)
 

Private Attributes

fd1
 Values of the derivative dy/dx at the first and last data points. More...
 
fdN
 
int N
 size of the arrays X,Y,S More...
 
std::vector< T > S
 
std::vector< T > X
 Data arrays. More...
 
std::vector< T > Y
 

Constructor & Destructor Documentation

◆ CubicSpline() [1/2]

template<class T >
gnsstk::CubicSpline< T >::CubicSpline ( )
inline

Empty constructor - NB must call initialize() before Eval().

Definition at line 60 of file CubicSpline.hpp.

◆ CubicSpline() [2/2]

template<class T >
gnsstk::CubicSpline< T >::CubicSpline ( const std::vector< T > &  X,
const std::vector< T > &  Y 
)
inline

Constructor given vectors of data X(N) Y(N); calls initialize(X,Y).

Exceptions
Exception

Definition at line 65 of file CubicSpline.hpp.

Member Function Documentation

◆ build()

template<class T >
void gnsstk::CubicSpline< T >::build ( const std::vector< T > &  x,
const std::vector< T > &  y,
bool  fixEnds 
)
inlineprivate

initialize array of second derivatives with the values of the data x(N) and y(N). If the first derivative at the end points has been fixed, the input boolean is true. Called by all versions of initialize().

Parameters
xVector of data for independent variable, must parallel y, and must be strictly increasing.
yVector of data for dependent variable, must parallel x.
fixEndsif true, initial and final values of derivative dy/dx have been set using member data fd1 and fdN.
Exceptions
Exceptionif input is invalid: arrays are empty or x not strictly increasing.

Definition at line 253 of file CubicSpline.hpp.

◆ evaluate() [1/2]

template<class T >
std::vector<T> gnsstk::CubicSpline< T >::evaluate ( const std::vector< T > &  x)
inline

Compute interpolated values of y at a vector of x's; cf. Evalute(x).

Parameters
xvector of values of independent variable X at which to evaluate.
Returns
y output vector of interpolated values parallel to x.
Exceptions
Exceptionif the object has not been initialized by a call to initialize(), or if the given x is outside the range of the data used in initialize().

Definition at line 185 of file CubicSpline.hpp.

◆ evaluate() [2/2]

template<class T >
T gnsstk::CubicSpline< T >::evaluate ( const T &  x)
inline

Compute the value of y at the given x, using interpolation by cubic spline. The object must have been initialized before this call, either by using the constructor CubicSpline(X,Y) or by calling initialize() with the data arrays X and Y.

Parameters
xvalue of independent variable X at which to evaluate spline.
Returns
y(x) the interpolated value
Exceptions
Exceptionif the object has not been initialized by a call to initialize(), or if the given x is outside the range of the data used in initialize().

Definition at line 140 of file CubicSpline.hpp.

◆ initialize() [1/2]

template<class T >
void gnsstk::CubicSpline< T >::initialize ( const std::vector< T > &  X,
const std::vector< T > &  Y 
)
inline

Initialize array of second derivatives, which is used by Interpolate(). Called by constructor. If the arrays are shorter than 4 points, then linear interpolation is used. Do not fix derivatives at end points; if this is desired, call initialize(X,Y,deriv1,derivN).

Parameters
XVector of data for independent variable, must parallel Y
YVector of data for dependent variable, must parallel X
Exceptions
Exception

Definition at line 78 of file CubicSpline.hpp.

◆ initialize() [2/2]

template<class T >
void gnsstk::CubicSpline< T >::initialize ( const std::vector< T > &  X,
const std::vector< T > &  Y,
const DYDX1,
const DYDXN 
)
inline

Initialize array of second derivatives with the values of the derivative at the first and last points set by input. Cf. initialize(X,Y);

Parameters
XVector of data for independent variable, must parallel Y
YVector of data for dependent variable, must parallel X
DYDX1Initial value of derivative dy/dx
DYDXNFinal value of derivative dy/dx
Exceptions
Exception

Definition at line 92 of file CubicSpline.hpp.

◆ interpolate()

template<class T >
T gnsstk::CubicSpline< T >::interpolate ( const int  k,
const x 
)
inlineprivate

Given an index k into the array S, and a value x such that X[k-1] < x < X[k], find the interpolated value y at x.

Definition at line 354 of file CubicSpline.hpp.

◆ size()

template<class T >
int gnsstk::CubicSpline< T >::size ( ) const
inline

Return the current size of the second derivative array.

Definition at line 238 of file CubicSpline.hpp.

◆ testLimits()

template<class T >
bool gnsstk::CubicSpline< T >::testLimits ( const T &  x,
T &  y 
)
inline

Determine if the given value of x is within the range of the data used to initialize the object; if it is not, return the value of Y which is closest to x (either Y[0] or Y[N-1]).

Parameters
xvalue of independent variable X at which to test limits
yreturn value of data Y at endpoint closest to x
Returns
true if x lies within the range of the data.
Exceptions
Exceptionif the object has not been initialized by a call to initialize().

Definition at line 109 of file CubicSpline.hpp.

Member Data Documentation

◆ fd1

template<class T >
T gnsstk::CubicSpline< T >::fd1
private

Values of the derivative dy/dx at the first and last data points.

Definition at line 372 of file CubicSpline.hpp.

◆ fdN

template<class T >
T gnsstk::CubicSpline< T >::fdN
private

Definition at line 372 of file CubicSpline.hpp.

◆ N

template<class T >
int gnsstk::CubicSpline< T >::N
private

size of the arrays X,Y,S

Definition at line 375 of file CubicSpline.hpp.

◆ S

template<class T >
std::vector<T> gnsstk::CubicSpline< T >::S
private

Array of second derivatives, computed by build() and used in interpolate().

Definition at line 369 of file CubicSpline.hpp.

◆ X

template<class T >
std::vector<T> gnsstk::CubicSpline< T >::X
private

Data arrays.

Definition at line 364 of file CubicSpline.hpp.

◆ Y

template<class T >
std::vector<T> gnsstk::CubicSpline< T >::Y
private

Definition at line 364 of file CubicSpline.hpp.


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


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44