1#ifndef NumericalApproximation_h
2#define NumericalApproximation_h
13#include <gsl/gsl_errno.h>
14#include <gsl/gsl_spline.h>
15#include "IException.h"
788 void AddData(
const double x,
const double y);
789 void AddData(
unsigned int n,
double *x,
double *y);
790 void AddData(
const vector <double> &x,
const vector <double> &y);
830 const double h = 0.1);
832 const double h = 0.1);
834 const double h = 0.1);
838 const double h = 0.1);
840 const double h = 0.1);
842 const double h = 0.1);
845 double GslIntegral(
const double a,
const double b);
849 double BoolesRule(
const double a,
const double b);
907 const unsigned int n);
911 const string &message,
const char *filesrc,
ErrorType
Contains a set of exception error types.
NumericalApproximation provides various numerical analysis methods of interpolation,...
void ValidateDataSet()
Validates the data set before computing interpolation.
gsl_interp_accel * p_acc
Lookup accelorator.
void GslDeallocation()
Deallocate GSL interpolator resources, if used.
void GslAllocation(unsigned int npoints)
Allocates GSL interpolation functions.
double EvaluatePolynomialNeville(const double a)
Performs polynomial interpolation using Neville's algorithm.
vector< double > p_x
List of X values.
vector< double > p_fprimeOfx
List of first derivatives corresponding to each x value in the data set (i.e. each value in p_x)
void ReportException(IException::ErrorType type, const string &method, const string &message, const char *filesrc, int lineno) const
Generalized error report generator.
double GslFirstDerivative(const double a)
Approximates the first derivative of the data set function evaluated at the given domain value for GS...
double p_clampedDerivLastPt
First derivative of last x-value, p_x[n-1]. This is only used for the CubicClamped interpolation type...
int FindIntervalLowerIndex(const double a)
Find the index of the x-value in the data set that is just below the input value, a.
vector< double > CubicClampedSecondDerivatives()
Retrieves the second derivatives of the data set.
double DomainMinimum()
Input data domain minimum value.
bool GslInterpType(NumericalApproximation::InterpType itype) const
Returns whether an interpolation type is adapted from the GSL library.
InterpFunctor GslFunctor(NumericalApproximation::InterpType itype) const
Search for a GSL interpolation function.
bool p_clampedComputed
Flag variable to determine whether ComputeCubicClamped() has been called.
double Evaluate(const double a, const ExtrapType &etype=ThrowError)
Calculates interpolated or extrapolated value of tabulated data set for given domain value.
void Init(NumericalApproximation::InterpType itype)
Initializes the object upon instantiation.
bool InsideDomain(const double a)
Returns whether the passed value is greater than or equal to the domain minimum and less than or equa...
bool p_dataValidated
Flag variable to determine whether ValidateDataSet() has been called.
void GslIntegrityCheck(int gsl_status, const char *src, int line)
Checks the status of the GSL interpolation operations.
void AddCubicHermiteDeriv(unsigned int n, double *fprimeOfx)
Adds values for the first derivatives of the data points.
const gsl_interp_type * InterpFunctor
GSL Interpolation specs.
void ComputeGsl()
Computes the GSL interpolation for a set of (x,y) data points.
string Name() const
Get name of interpolating function assigned to object.
map< InterpType, InterpFunctor > FunctorList
Set up a std::map of GSL interpolator functors. List of function types.
double RombergsMethod(double a, double b)
Uses Romberg's method to approximate the integral of the interpolated data set function on the interv...
InterpType
This enum defines the types of interpolation supported in this class.
@ CubicClamped
Cubic Spline interpolation with clamped boundary conditions.
@ CubicNatPeriodic
Cubic Spline interpolation with periodic boundary conditions.
@ Linear
Linear interpolation.
@ CubicHermite
Cubic Spline interpolation using the Hermite cubic polynomial.
@ CubicNeighborhood
Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions.
@ PolynomialNeville
Polynomial interpolation using Neville's algorithm.
@ CubicNatural
Cubic Spline interpolation with natural boundary conditions.
@ AkimaPeriodic
Non-rounded Akima Spline interpolation with periodic boundary conditions.
@ Polynomial
Polynomial interpolation.
@ Akima
Non-rounded Akima Spline interpolation with natural boundary conditions.
NumericalApproximation & operator=(const NumericalApproximation &numApMeth)
NumericalApproximation assigmment operator sets this object "equal to" another.
double TrapezoidalRule(const double a, const double b)
Uses the trapezoidal rule to approximate the integral of the interpolated data set function on the in...
double RefineExtendedTrap(double a, double b, double s, unsigned int n)
Calculates refinements extended trapezoidal rule to approximate the integral of the interpolated data...
double ValueToExtrapolate(const double a, const ExtrapType &etype)
Returns the domain value at which to evaluate.
double GslSecondDerivative(const double a)
Approximates the second derivative of the interpolated data set function evaluated at the given domai...
void ComputeCubicClamped()
Computes the cubic clamped interpolation for a set of (x,y) data points, given the first derivatives ...
bool Contains(double x)
Returns whether the passed value is an element of the set of x-values in the data set.
void SetInterpType(NumericalApproximation::InterpType itype)
Sets interpolation type.
double Simpsons4PointRule(const double a, const double b)
Uses Simpson's 4-point rule to approximate the integral of the interpolated data set function on the ...
double BackwardFirstDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point backward first difference formula to approximate the first derivative evaluated at a ...
double EvaluateCubicHermite(const double a)
Performs interpolation using the Hermite cubic polynomial.
bool GslComputed() const
Returns whether a GSL interpolation computation of the data set has been performed.
gsl_spline * p_interp
Currently active interpolator.
double GslIntegral(const double a, const double b)
Approximates the integral of the data set function evaluated on the given interval for GSL supported ...
void Reset()
Resets the state of the object.
FunctorList::const_iterator FunctorConstIter
GSL Iterator.
vector< double > p_clampedSecondDerivs
List of second derivatives evaluated at p_x values. This is only used for the CubicClamped interpolat...
bool p_clampedEndptsSet
Flag variable to determine whether SetCubicClampedEndptDeriv() has been called after all data was add...
NumericalApproximation(const NumericalApproximation::InterpType &itype=CubicNatural)
Default constructor creates NumericalApproximation object.
double CenterSecondDifference(const double a, const unsigned int n=5, const double h=0.1)
Uses an n point center second difference formula to approximate the second derivative evaluated at a ...
double p_clampedDerivFirstPt
First derivative of first x-value, p_x[0]. This is only used for the CubicClamped interpolation type.
InterpType p_itype
Interpolation type.
double EvaluateCubicHermiteSecDeriv(const double a)
Approximates the second derivative of the data set function evaluated at the given domain value for C...
double Simpsons3PointRule(const double a, const double b)
Uses Simpson's 3-point rule to approximate the integral of the interpolated data set function on the ...
static FunctorList p_interpFunctors
Maintains list of interpolator options.
double DomainMaximum()
Input data domain maximum value.
double EvaluateCubicClamped(const double a)
Performs cubic spline interpolation with clamped boundary conditions, if possible.
virtual ~NumericalApproximation()
Destructor deallocates memory being used.
double BackwardSecondDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point backward second difference formula to approximate the second derivative evaluated at ...
double ForwardFirstDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point forward first difference formula to approximate the first derivative evaluated at a g...
double BoolesRule(const double a, const double b)
Uses Boole's Rule to approximate the integral of the interpolated data set function on the interval (...
vector< double > p_polyNevError
Estimate of error for interpolation evaluated at x. This is only used for the PolynomialNeville inter...
double EvaluateCubicNeighborhood(const double a)
Performs cubic spline interpolation for a neighborhood about a.
double CenterFirstDifference(const double a, const unsigned int n=5, const double h=0.1)
Uses an n point center first difference formula to approximate the first derivative evaluated at a gi...
double EvaluateCubicHermiteFirstDeriv(const double a)
Approximates the first derivative of the data set function evaluated at the given domain value for Cu...
ExtrapType
This enum defines the manner in which a value outside of the domain should be handled if passed to th...
@ NearestEndpoint
Evaluate() returns the y-value of the nearest endpoint if a is outside of the domain.
@ ThrowError
Evaluate() throws an error if a is outside of the domain.
@ Extrapolate
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
InterpType InterpolationType()
Returns the enumerated type of interpolation chosen.
unsigned int Size()
Returns the number of the coordinates added to the data set.
int MinPoints()
Minimum number of points required by interpolating function.
double ForwardSecondDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point forward second difference formula to approximate the second derivative evaluated at a...
vector< double > PolynomialNevilleErrorEstimate()
Retrieves the error estimate for the Neville's polynomial interpolation type.
vector< double > p_y
List of Y values.
void SetCubicClampedEndptDeriv(const double yp1, const double ypn)
Sets the values for the first derivatives of the endpoints of the data set.
void AddData(const double x, const double y)
Add a datapoint to the set.
vector< double > EvaluateForIntegration(const double a, const double b, const unsigned int n)
Evaluates data set in order to have enough data points to approximate the function to be integrated.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.