USGS

Isis 3.0 Object Programmers' Reference

Home

Isis::NumericalApproximation Class Reference
[Math]

#include <NumericalApproximation.h>

Inheritance diagram for Isis::NumericalApproximation:

Inheritance graph
[legend]
Collaboration diagram for Isis::NumericalApproximation:

Collaboration graph
[legend]
List of all members.

Detailed Description

NumericalApproximation provides various numerical analysis methods of interpolation, extrapolation and approximation of a tabulated set of x, y data.

This class contains a merged version of the Isis3 classes DataInterp and NumericalMethods. In addition, some methods from AtmosModel were moved to this class, the CubicNeighborhood interpolation type was adapted from the IDL routine called interpol (using the "/spline" keyword), and several differentiation and integration approximation methods were created.

NumericalApproximation contains 9 types of data interpolation routines. These routines act on x, y pairs of data points. The following forms of data interpolation are supported:

Name Type (enum) MinPoints Description
Linear Linear 2 Linear interpolation approximates a curve by concatinating line segments between known data points. This results in a continuous curve with a discontinuities of the derivative at the known data points. This interpolation type uses the GSL library routines.

Polynomial Polynomial 3 Computes a polynomial interpolation. This method should only be used for interpolating small numbers of points because polynomial interpolation introduces large oscillations, even for well-behaved datasets. The number of terms in the interpolating polynomial is equal to the number of points. This interpolation type uses the GSL library routines.
Neville's Algorithm for Polynomial Interpolation PolynomialNeville 3 Polynomial interpolation using Neville's algorithm. This first fits a polynomial of degree 0 through each point. On the second iteration, the polynomial of adjoining indices are combined to fit through pairs of points. This process repeats until a pyramid of approximations is reached. This is based on the Newton form of the interpolating polynomial and the recursion relation of the divided differences.
Natural Cubic Spline CubicNatural 3 Cubic spline with natural boundary conditions. The resulting curve is piecewise cubic on each interval with matching first and second derivatives at the supplied data points. The second derivative is chosen to be zero at the endpoints, i.e. the first and last points of the data set. This is also refered to as free boundary condtions. This interpolation type uses the GSL library routines.
Clamped Cubic Spline CubicClamped 3 Cubic Spline interpolation with clamped boundary conditions. The resulting curve is piecewise cubic on each interval. For this type of boundary condition to hold, it is necessary to have either the values of the derivative at the endpoints or an accurate approximation to those values. In general, clamped boundary conditions lead to more accurate approximations since they include more information about the function.
Periodic Natural Cubic Spline CubicNatPeriodic 2 Cubic spline with periodic boundary conditions. The resulting curve is piecewise cubic on each interval with matching first and second derivatives at the supplied data points. The derivatives at the first and last points are also matched. Note that the last point in the data must have the same y-value as the first point, otherwise the resulting periodic interpolation will have a discontinuity at the boundary. This interpolation type uses the GSL library routines.
Cubic Spline about 4-point Neighborhood CubicNeighborhood 4 Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions. This interpolation type is adapted from the IDL interpol.pro application using the "/spline" keyword on an irregular grid. This type of cubic spline fits a natural cubic spline to the 4-point neighborhood of known data points surrounding the x value at which we wish to evaluate. For example, suppose {x0, x1, ..., xn} is the array of known domain values in the data set and $ x_i \leq u < x_{i+1} $ for some i such that $ 0 \leq i \leq n $, then to evaluate the y value at u, this method of interpolation evaluates the ordinary cubic spline consisting of the data set {xi-1, xi, xi+1, xi+2} at u.
Cubic Spline using Hermite cubic polynomial CubicHermite 2 Cubic Spline interpolation using the Hermite cubic polynomial (also called the unique Hermite interpolating fundamental polynomial of degree 3). This method requires the input of the slopes of the tangent lines of the curve (i.e. velocities, or first derivatives) at each of the data points. This ensures that the approximation has the same "shape" as the curve at the known data points. This interpolation type uses piecewise Hermite cubic polynomials for each interval, (x0, x1), using the known data points, (x0,f(x0)) and (x1,f(x1)), and their derivatives, f '(x0) and f '(x1). The Hermite cubic polynomial is defined

\[ H_3(x) = f(x_0)h_0(x)+f(x_1)h_1(x) +f\prime(x_0)\hat{h}_0(x)+f\prime(x_1)\hat{h}_1(x) \]

where $ h_k(x) = [1-2(x-x_k)L\prime_k(x_k)](L_k(x))^2 $ and $ \hat{h}_k(x) = (x-x_k)(L_k(x))^2 $ for the kth-Lagrange coefficient polynomials of degree n = 1, $ L_0(x) = \frac{x- x_1}{x_0-x_1}$ and $ L_1(x) = \frac{x- x_0}{x_1-x_0}$.

Akima Akima 5 Non-rounded Akima spline with natural boundary conditions. This method uses non-rounded corner algorithm of Wodicka. This interpolation type uses the GSL library routines.
Periodic Akima AkimaPeriodic 5 Non-rounded Akima spline with periodic boundary conditions. This method uses non-rounded corner algorithm of Wodicka. This interpolation type uses the GSL library routines.

Numerical analysis approximation methods for differentiating and integrating unknown functions represented by a data set are implemented by using the interpolations on the data set created with a NumericalApproximation object. The Lagrange polynomial,

\[ L(x) = \sum_{k=0}^{n} \left(f(x_k) \prod_{i=0,i \neq k}^{n} \frac{x- x_i}{x_k-x_i}\right) \]

is used to determine formulas for numerical differentiation and integration.
Numerical Differentiation
The differentiation methods use difference formulas to approximate first and second derivatives at a domain value for a given a set of known (x,y) data points. Once all of the data points are added, a Isis::NumericalApproximation interpolation is used on the dataset to estimate the function, $f:x \to y$, mapping x values to corresponding y values. Then, the derivative of f evaluated at x0 is approximated. To do so, a uniform step size of h is chosen to determine the distance between xi and xi+1.
Differentiation methods require the parameters a (domain value at which the derivative will be evaluated), n (number of points used in the difference formula), and h (step size of points). Note: a is denoted x0 in the above formulas.
Numerical Differentiation Type Difference Formulas Methods Available Description
Backward Difference
  • 2-point backward difference.

    \[ f\prime(x_0) \approx \frac{1}{h}[f(x_0) - f(x_0 - h)] \]

  • 3-point backward difference.

    \[ f\prime(x_0) \approx \frac{1}{2h}[3f(x_0) - 4f(x_0 - h) + f(x_0 - 2h)] \]

  • 3-point backward second difference.

    \[ f\prime\prime(x_0) \approx \frac{1}{h^2}[f(x_0) - 2f(x_0 - h) + f(x_0 - 2h)] \]

Backward difference formulas use a uniform step-size moving in the negative direction from the given x0. These formulas are derived by differentiating the Lagrange polynomials for xi = x0 - ih and evaluating them atx0.
Forward Difference
  • 2-point forward difference.

    \[ f\prime(x_0) \approx \frac{1}{h}[f(x_0 + h) - f(x_0)] \]

  • 3-point forward difference.

    \[ f\prime(x_0) \approx \frac{1}{2h}[-f(x_0 + 2h) + 4f(x_0 + h) - 3f(x_0)] \]

  • 3-point forward second difference.

    \[ f\prime\prime(x_0) \approx \frac{1}{h^2}[f(x_0 + 2h) - 2f(x_0 + h) + f(x_0)] \]

Forward difference formulas use a uniform step-size moving in the positive direction from x0. These formulas are derived by differentiating the Lagrange polynomials for xi = x0 + ih and evaluating them atx0.
Center Difference
  • 3-point center difference.

    \[ f\prime(x_0) \approx \frac{1}{2h}[f(x_0 + h) - f(x_0 - h)] \]

  • 5-point center difference.

    \[ f\prime(x_0) \approx \frac{1}{12h}[-f(x_0 + 2h) + 8f(x_0 +h) - 8f(x_0 - h) + f(x_0 - 2h)] \]

  • 3-point center second difference.

    \[ f\prime\prime(x_0) \approx \frac{1}{h^2}[f(x_0 + h) - 2f(x_0) + f(x_0 - h)] \]

  • 5-point center second difference.

    \[ f\prime\prime(x_0) \approx \frac{1}{12h^2}[-f(x_0 + 2h) + 16f(x_0 +h) - 30f(x_0) + 16f(x_0 - h) - f(x_0 - 2h)] \]

Center difference formulas use a uniform step-size moving in both directions from x0 so this point stays centered. These formulas are derived by differentiating the Lagrange polynomials for xi = x0 + (i - (n - 1)/2)h and evaluating them at x0.
GSL Differentiation Unknown No documentation was found about the algorithms used for these methods. They may only be called when interpolation type is one of the following: Linear, Polynomial, CubicNatural, CubicNatPeriodic, Akima, or AkimaPeriodic.

Numerical Integration
The integration methods were derived using Newton-Cotes, or quadrature, formulas for approximating integrals given a set of known (x,y) data points. The x values may be irregularly spaced, but must be unique and added to the dataset in ascending order. Once all of the data points are added, a Isis::NumericalApproximation interpolation is used on the dataset to estimate the function, $f:x \to y$, mapping x values to corresponding y values. Then, the integral of f on the interval from a to b is approximated. To do so, an algorithm for creating a composite formula by applying the original formula to segments that share a boundary point is used. The NumericalApproximation::InterpType chosen for interpolation computation seems to have little affect on the error between the actual integral and the return values of the integration methods. The BoolesRule() method varies the most in error. Although errors are not high for any of the interpolation types, CubicNatural spline interpolations seem to have the smallest error most often with BoolesRule(). For any other numerical integration method, the errors appear to be identical for any NumericalApproximation::InterpType except Polynomial, which usually has a slightly larger error than the other interpolation types. Note: A portion of this algorithm is derived from the IDL function int_tabulated for Boole's Method.
Integration methods require the parameters a, b (interval of domain over which to integrate).
Numerical Integration Type Integration Formulas Methods Available Description
Trapezoidal Rule
  • 2-point Newton-Cotes trapezoidal rule:

    \[ \int_{a}^b f(x)dx \approx \frac{h}{2}[f(a) + f(b)] \]

    where h = b - a.

The 2-point closed rule, known as the trapezoidal rule, uses straight line segments between known data points to estimate the area under the curve (integral). This Newton-Cotes formula uses a uniform step-size of h = b - a and is derived by integrating the Lagrange polynomials over the closed interval [a, a+h] for xi = x0 + ih.
Simpson's Rule, or Simpson's 3-Point Rule
  • 3-point Newton-Cotes, Simpson's Rule

    \[ \int_{a}^b f(x)dx \approx \frac{h}{3}[f(a) + 4f(a+h) + f(a+2h)] \]

    where h = (b - a)/2.

The 3-point closed rule, known as Simpson's Rule or Simpson's 3-Point Rule, uses parabolic arcs between known data points to estimate the area under the curve (integral). This Newton-Cotes formula uses a uniform step-size of h = (b - a)/2 and is derived by integrating the Lagrange polynomials over the closed interval [a, a+2h] for xi = x0 + ih.
Simpson's 3/8 Rule, or Simpson's 4-Point Rule
  • 4-point Newton-Cotes, Simpson's 3/8 Rule

    \[ \int_{a}^b f(x)dx \approx \frac{3h}{8}[f(a) + 3f(a+h) + 3f(a+2h) + f(a+3h)] \]

    where h = (b - a)/3.

The 4-point closed rule, known as Simpson's 3/8 Rule or Simpson's 4-Point Rule, uses cubic curves between known data points to estimate the area under the curve (integral). This Newton-Cotes formula uses a uniform step-size of h = (b - a)/3 and is derived by integrating the Lagrange polynomials over the closed interval [a, a+3h] for xi = x0 + ih.
Boole's Rule
  • 5-point Newton-Cotes, Boole's Rule

    \[ \int_{a}^b f(x)dx \approx \frac{2h}{45}[7f(a) + 32f(a+h) + 12f(a+2h) + 32f(a+3h) + 7f(a+4h)] \]

    where h = (b - a)/4.

The 5-point closed rule, known as Boole's Rule, uses quartic curves between known data points to estimate the area under the curve (integral). This Newton-Cotes formula uses a uniform step-size of h = (b - a)/4 and is derived by integrating the Lagrange polynomials over the closed interval [a, a+4h] for xi = x0 + ih.
Refinements of Extended Trapezoidal Rule
  • Extended closed trapezoidal rule

    \[ \int_{a}^b f(x)dx \approx h[\frac12 f(x_0) + f(x_1) + ... + f(x_{n-2} + \frac12 f(x_{n-1})] \]

    where h = (b - a)/4, x0 = a, and xn-1 = b.

The extended (or composite) trapezoidal rule can be used to with a series of refinements to approximate the integral. The first stage of refinement returns the ordinary trapezoidal estimate of the integral. Subsequent stages will improve the accuracy, where, for the nth stage 2n-2 interior points are added.
Romberg's Method
  • Romberg's Method for Integration
Romberg's Method is a potent numerical integration tool. It uses the extended trapezoidal rule and Neville's algorithm for polynomial interpolation.
GSL Integration Unknown No documentation was found about the algorithm used for this methods. They may only be called when interpolation type is one of the following: Linear, Polynomial, CubicNatural, CubicNatPeriodic, Akima, or AkimaPeriodic.

Below is an example demonstating the use of this class:

    inline double f(double x) { return (x + cos ((x * x))); }
 
    NumericalApproximation
    spline(NumericalApproximation::CubicClamped);
    for (int x = 0; x < 200 ; x++) {
      spline.addPoint(x, f(x));
    }
    spline.SetCubicClampedEndptDeriv(0,0);
    double yinterp = spline.Evaluate(50.7);
    double yextrap =
        spline.Evaluate(201,NumericalApproximation::Extrapolate);
    double deriv = spline.CenterFirstDifference(10);
    double integ =
        spline.RombergsMethod(spline.DomainMinimum(),spline.DomainMaximum());

To compute the same data set using the Akima spline, just use the following:

    spline.Reset(NumericalApproximation::Akima); 
    double yinterp = spline.Evaluate(50.7);
    double yextrap =
        spline.Evaluate(201,NumericalApproximation::NearestEndpoint);
    double deriv = spline.CenterFirstDifference(10);
    double integ =
        spline.RombergsMethod(spline.DomainMinimum(),spline.DomainMaximum()); 

Caveats

When using this class, there are some important details that require consideration. Several interpolation types of this class use the GSL library. In addition, the GSL library default error handling scheme has implications when used in C++ objects. The default behavior is to terminate the application when an error occurs. Options for developers are to turn off error trapping within the GSL, which means users of the library must do their own error checking, or a specific handler can be specified to replace the default mode. Neither option is well suited in object-oriented implementations because they apply globally, to all users of the library. The approach used here is to turn off error handling and require users to handle their own error checking. This is not entirely safe as any user that does not follow this strategy could change this behavior at runtime. Other options should be explored. An additional option is that the default behavior can be altered prior to building GSL but this is also problematic since this behavior cannot be guaranteed universally.

For these types, interpolation is strictly adhered to and extrapolation is not handled well. If the input to be evaluated is outside of the minimum and maximum x values of the original data points, then the y value corresponding to the x value that is nearest to that input is returned. However, for sufficiently close values, the clamped cubic and polynomial Neville's types are fairly accurate in their extrapolation techniques. All differentiation and integration methods throw an error if the value passed is outside of the domain.

Author:
2008-11-05 Janet Barrett, Kris Becker, K Teal Thompson, Jeannie Walldren

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version of NumericalMethods subroutines in Isis2.
History:
2006-06-14 Kris Becker - Created DataInterp class
History:
2007-02-20 Janet Barrett - Created NumericalMethods class from Isis2 subroutines
History:
2007-02-20 Janet Barrett - Created AtmosModel class from Isis2 subroutines
History:
2008-06-18 Christopher Austin - Fixed documentation for DataInterp
History:
2008-06-18 Steven Koechle - Updated NumericalMethods unitTest.
History:
2008-11-05 Jeannie Walldren - Merged DataInterp class, NumericalMethods class, and methods from AtmosModel. Modified methods from various classes to be able to function similarly. Added InterpType CubicNeighborhood, difference formula methods, and integration methods. Created new unitTest.
History:
2008-11-12 Jeannie Walldren - Fixed documentation.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type vector, NumericalApproximation::InterpType, and NumericalApproximation::ExtrapType in Constructors, AddData(), Evaluate(), ValueToExtrapolate(), EvaluateCubicNeighborhood(),
History:
2009-01-26 Jeannie Walldren - Fixed error documentation.
History:
2009-02-12 Jeannie Walldren - Fixed documentation to include weblinks.
History:
2009-07-17 Steven Lambright - Added algorithm include, removed macro MAX
History:
2009-06-10 Jeannie Walldren - Added interpolation type CubicHermite. This involved modifying some methods, as well as adding variable p_fprimeOfx and methods AddCubicHermiteDeriv() and EvaluateCubicHermite(). Added Contains() method.
History:
2009-07-02 Jeannie Walldren - Replaced Hermite interpolation algorithm with simpler version and added methods EvaluateCubicHermiteFirstDeriv and EvaluateCubicHermiteSecDeriv
History:
2009-07-09 Debbie Cook - Finished Jeannie's modifications.
History:
2009-08-03 Jeannie Walldren - Clean up code, documentation and check in changes from 2009-06-10, 2009-07-02, 2009-07-09

Definition at line 715 of file NumericalApproximation.h.

Public Types

 Linear
 Linear interpolation.
 Polynomial
 Polynomial interpolation.
 PolynomialNeville
 Polynomial interpolation using Neville's algorithm.
 CubicNatural
 Cubic Spline interpolation with natural boundary conditions.
 CubicClamped
 Cubic Spline interpolation with clamped boundary conditions.
 CubicNatPeriodic
 Cubic Spline interpolation with periodic boundary conditions.
 CubicNeighborhood
 Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions.
 CubicHermite
 Cubic Spline interpolation using the Hermite cubic polynomial.
 Akima
 Non-rounded Akima Spline interpolation with natural boundary conditions.
 AkimaPeriodic
 Non-rounded Akima Spline interpolation with periodic boundary conditions.
 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 NumericalApproximation::InterpType CubicClamped or PolynomialNeville and the result will be accurate only if sufficiently close to the domain boundary.
 NearestEndpoint
 Evaluate() returns the y-value of the nearest endpoint if a is outside of the domain.
enum  InterpType {
  Linear, Polynomial, PolynomialNeville, CubicNatural,
  CubicClamped, CubicNatPeriodic, CubicNeighborhood, CubicHermite,
  Akima, AkimaPeriodic
}
 This enum defines the types of interpolation supported in this class. More...
enum  ExtrapType { ThrowError, Extrapolate, NearestEndpoint }
 This enum defines the manner in which a value outside of the domain should be handled if passed to the Evaluate() method. More...

Public Member Functions

 NumericalApproximation (const InterpType &itype=CubicNatural) throw (iException &)
 NumericalApproximation (unsigned int n, double *x, double *y, const InterpType &itype=CubicNatural) throw (iException &)
 NumericalApproximation (const vector< double > &x, const vector< double > &y, const InterpType &itype=CubicNatural) throw (iException &)
 NumericalApproximation (const NumericalApproximation &dint)
 Copy constructor creates NumericalApproximation object and sets the copies the class variable values and state of input NumericalApproximation object to the new object.
NumericalApproximationoperator= (const NumericalApproximation &numApMeth)
 NumericalApproximation assigmment operator sets this object "equal to" another.
virtual ~NumericalApproximation ()
 Destructor deallocates memory being used.
string Name () const
 Get name of interpolating function assigned to object.
InterpType InterpolationType ()
 Returns the enumerated type of interpolation chosen.
int MinPoints ()
 Minimum number of points required by interpolating function.
int MinPoints (InterpType itype) throw (iException &)
void AddData (const double x, const double y)
 Add a datapoint to the set.
void AddData (unsigned int n, double *x, double *y)
 Add set of points to the data set using pointer arrays.
void AddData (const vector< double > &x, const vector< double > &y) throw (iException &)
 Add set of points to the data set using vectors.
void SetCubicClampedEndptDeriv (const double yp1, const double ypn) throw (iException &)
 Sets the values for the first derivatives of the endpoints of the data set.
void AddCubicHermiteDeriv (unsigned int n, double *fprimeOfx) throw (iException &)
 Adds values for the first derivatives of the data points.
void AddCubicHermiteDeriv (const vector< double > &fprimeOfx) throw (iException &)
 Adds values for the first derivatives of the data points.
void AddCubicHermiteDeriv (const double fprimeOfx) throw (iException &)
 Adds value of a first derivative of a data point.
double DomainMinimum ()
 Input data domain minimum value.
double DomainMaximum ()
 Input data domain maximum value.
bool Contains (double x)
 Returns whether the passed value is an element of the set of x-values in the data set.
unsigned int Size ()
 Returns the number of the coordinates added to the data set.
double Evaluate (const double a, const ExtrapType &etype=ThrowError) throw (iException &)
 Calculates interpolated or extrapolated value of tabulated data set for given domain value.
vector< double > Evaluate (const vector< double > &a, const ExtrapType &etype=ThrowError) throw (iException &)
 Calculates interpolated value for given set of domain values.
vector< double > PolynomialNevilleErrorEstimate () throw (iException &)
 Retrieves the error estimate for the Neville's polynomial interpolation type.
vector< double > CubicClampedSecondDerivatives () throw (iException &)
 Retrieves the second derivatives of the data set.
double EvaluateCubicHermiteFirstDeriv (const double a)
 Approximates the first derivative of the data set function evaluated at the given domain value for CubicHermite interpolation type.
double EvaluateCubicHermiteSecDeriv (const double a)
 Approximates the second derivative of the data set function evaluated at the given domain value for CubicHermite interpolation type.
double GslFirstDerivative (const double a) throw (iException &)
 Approximates the first derivative of the data set function evaluated at the given domain value for GSL supported interpolation types.
double BackwardFirstDifference (const double a, const unsigned int n=3, const double h=0.1) throw (iException &)
 Uses an n point backward first difference formula to approximate the first derivative evaluated at a given domain value.
double ForwardFirstDifference (const double a, const unsigned int n=3, const double h=0.1) throw (iException &)
 Uses an n point forward first difference formula to approximate the first derivative evaluated at a given domain value.
double CenterFirstDifference (const double a, const unsigned int n=5, const double h=0.1) throw (iException &)
 Uses an n point center first difference formula to approximate the first derivative evaluated at a given domain value.
double GslSecondDerivative (const double a) throw (iException &)
 Approximates the second derivative of the interpolated data set function evaluated at the given domain value for GSL supported interpolation types.
double BackwardSecondDifference (const double a, const unsigned int n=3, const double h=0.1) throw (iException &)
 Uses an n point backward second difference formula to approximate the second derivative evaluated at a given domain value.
double ForwardSecondDifference (const double a, const unsigned int n=3, const double h=0.1) throw (iException &)
 Uses an n point forward second difference formula to approximate the second derivative evaluated at a given domain value.
double CenterSecondDifference (const double a, const unsigned int n=5, const double h=0.1) throw (iException &)
 Uses an n point center second difference formula to approximate the second derivative evaluated at a given domain value.
double GslIntegral (const double a, const double b) throw (iException &)
 Approximates the integral of the data set function evaluated on the given interval for GSL supported interpolation types.
double TrapezoidalRule (const double a, const double b)
 Uses the trapezoidal rule to approximate the integral of the interpolated data set function on the interval (a, b).
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 interval (a,b).
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 interval (a,b).
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 (a,b).
double RefineExtendedTrap (double a, double b, double s, unsigned int n) throw (iException &)
 Calculates refinements extended trapezoidal rule to approximate the integral of the interpolated data set function on the interval (a,b).
double RombergsMethod (double a, double b) throw (iException &)
 Uses Romberg's method to approximate the integral of the interpolated data set function on the interval (a,b).
void Reset ()
 Resets the state of the object.
void Reset (InterpType itype) throw (iException &)
void SetInterpType (InterpType itype) throw (iException &)

Protected Types

typedef const gsl_interp_type * InterpFunctor
 GSL Interpolation specs.
typedef map< InterpType, InterpFunctorFunctorList
 Set up a std::map of GSL interpolator functors. List of function types.
typedef FunctorList::const_iterator FunctorConstIter
 GSL Iterator.

Protected Member Functions

void Init (InterpType itype)
bool GslInterpType (InterpType itype) const
void GslAllocation (unsigned int npoints)
 Allocates GSL interpolation functions.
void GslDeallocation ()
 Deallocate GSL interpolator resources, if used.
InterpFunctor GslFunctor (InterpType itype) const throw (iException &)
void GslIntegrityCheck (int gsl_status, char *src, int line) throw (iException &)
 Checks the status of the GSL interpolation operations.
void ValidateDataSet () throw (iException &)
 Validates the data set before computing interpolation.
bool InsideDomain (const double a)
 Returns whether the passed value is greater than or equal to the domain minimum and less than or equal to the domain maximum.
bool GslComputed () const
 Returns whether a GSL interpolation computation of the data set has been performed.
void ComputeGsl () throw (iException &)
 Computes the GSL interpolation for a set of (x,y) data points.
void ComputeCubicClamped () throw (iException &)
 Computes the cubic clamped interpolation for a set of (x,y) data points, given the first derivatives of the endpoints of the data set.
double ValueToExtrapolate (const double a, const ExtrapType &etype)
 Returns the domain value at which to evaluate.
double EvaluateCubicNeighborhood (const double a)
 Performs cubic spline interpolation for a neighborhood about a.
vector< double > EvaluateCubicNeighborhood (const vector< double > &a, const ExtrapType &etype)
 Performs cubic spline interpolations for neighborhoods about each value of a.
double EvaluateCubicClamped (const double a) throw (iException &)
 Performs cubic spline interpolation with clamped boundary conditions, if possible.
double EvaluateCubicHermite (const double a) throw (iException &)
 Performs interpolation using the Hermite cubic polynomial.
double EvaluatePolynomialNeville (const double a) throw (iException &)
 Performs polynomial interpolation using Neville's algorithm.
vector< double > EvaluateForIntegration (const double a, const double b, const unsigned int n) throw (iException &)
 Evaluates data set in order to have enough data points to approximate the function to be integrated.
int FindIntervalLowerIndex (const double a)
 Find the index of the x-value in the data set that is just below the input value, a.
void ReportException (iException::errType type, const string &method, const string &message, char *filesrc, int lineno) const throw (iException &)
 Generalized error report generator.

Protected Attributes

InterpType p_itype
 Interpolation type.
vector< double > p_x
 List of X values.
vector< double > p_y
 List of Y values.
bool p_dataValidated
 Flag variable to determine whether ValidateDataSet() has been called.
gsl_interp_accel * p_acc
 Lookup accelorator.
gsl_spline * p_interp
 Currently active interpolator.
FunctorList p_interpFunctors
 Maintains list of interpolator options.
bool p_clampedEndptsSet
 Flag variable to determine whether SetCubicClampedEndptDeriv() has been called after all data was added for CubicClamped interpolation.
bool p_clampedComputed
 Flag variable to determine whether ComputeCubicClamped() has been called.
double p_clampedDerivFirstPt
 First derivative of first x-value, p_x[0]. This is only used for the CubicClamped interpolation type.
double p_clampedDerivLastPt
 First derivative of last x-value, p_x[n-1]. This is only used for the CubicClamped interpolation type.
vector< double > p_clampedSecondDerivs
 List of second derivatives evaluated at p_x values. This is only used for the CubicClamped interpolation type.
vector< double > p_polyNevError
 Estimate of error for interpolation evaluated at x. This is only used for the PolynomialNeville interpolation type. 91 taken from AtmosModel.
vector< double > p_fprimeOfx
 List of first derivatives corresponding to each x value in the data set (i.e. each value in p_x).


Member Typedef Documentation

typedef FunctorList::const_iterator Isis::NumericalApproximation::FunctorConstIter [protected]

GSL Iterator.

Definition at line 853 of file NumericalApproximation.h.

typedef map<InterpType, InterpFunctor> Isis::NumericalApproximation::FunctorList [protected]

Set up a std::map of GSL interpolator functors. List of function types.

Definition at line 852 of file NumericalApproximation.h.

typedef const gsl_interp_type* Isis::NumericalApproximation::InterpFunctor [protected]

GSL Interpolation specs.

Definition at line 851 of file NumericalApproximation.h.


Member Enumeration Documentation

enum Isis::NumericalApproximation::ExtrapType

This enum defines the manner in which a value outside of the domain should be handled if passed to the Evaluate() method.

Enumerator:
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 NumericalApproximation::InterpType CubicClamped or PolynomialNeville and the result will be accurate only if sufficiently close to the domain boundary.
NearestEndpoint  Evaluate() returns the y-value of the nearest endpoint if a is outside of the domain.

Definition at line 798 of file NumericalApproximation.h.

enum Isis::NumericalApproximation::InterpType

This enum defines the types of interpolation supported in this class.

Enumerator:
Linear  Linear interpolation.
Polynomial  Polynomial interpolation.
PolynomialNeville  Polynomial interpolation using Neville's algorithm.
CubicNatural  Cubic Spline interpolation with natural boundary conditions.
CubicClamped  Cubic Spline interpolation with clamped boundary conditions.
CubicNatPeriodic  Cubic Spline interpolation with periodic boundary conditions.
CubicNeighborhood  Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions.
CubicHermite  Cubic Spline interpolation using the Hermite cubic polynomial.
Akima  Non-rounded Akima Spline interpolation with natural boundary conditions.
AkimaPeriodic  Non-rounded Akima Spline interpolation with periodic boundary conditions.

Definition at line 720 of file NumericalApproximation.h.


Constructor & Destructor Documentation

Isis::NumericalApproximation::NumericalApproximation ( const NumericalApproximation oldObject  ) 

Copy constructor creates NumericalApproximation object and sets the copies the class variable values and state of input NumericalApproximation object to the new object.

Copying of class objects must be handled explicitly in order for it to be completed properly. The data, interpolator type and other class variables are copied from the supplied object.

Parameters:
oldObject NumericalApproximation object to gleen data from for creation of this object
Exceptions:
Isis::iException::Programmer "Unable to construct NumericalApproximation object"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name DataInterp().
History:
2008-11-05 Jeannie Walldren - Changed name and modified to allow for interpolation types other than those supported by GSL.
History:
2009-06-10 Jeannie Walldren - Set new variable, p_fprimeOfx.

Definition at line 160 of file NumericalApproximation.cpp.

References _FILEINFO_, e, Isis::iException::Message(), p_clampedComputed, p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedEndptsSet, p_clampedSecondDerivs, p_dataValidated, p_fprimeOfx, p_itype, p_polyNevError, p_x, and p_y.

Isis::NumericalApproximation::~NumericalApproximation (  )  [virtual]

Destructor deallocates memory being used.

Explicit operations are required to free resources of the interpolation

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name ~DataInterp().
History:
2008-11-05 Jeannie Walldren - Changed name.

Definition at line 242 of file NumericalApproximation.cpp.

References GslDeallocation(), and p_itype.


Member Function Documentation

void Isis::NumericalApproximation::AddCubicHermiteDeriv ( const double  fprimeOfx  )  throw (iException &)

Adds value of a first derivative of a data point.

This method can only be called for cubic Hermite splines, i.e. if NumericalApproximation::InterpType is CubicHermite. Values should be entered in the order of the corresponding data points.

Parameters:
fprimeOfx Derivative value to be added.
Exceptions:
Isis::iException::Programmer "Method only used for cspline-Hermite interpolation type"

For internal use only.

History:
2009-06-10 Jeannie Walldren - Original version

Definition at line 612 of file NumericalApproximation.cpp.

References _FILEINFO_, and CubicHermite.

void Isis::NumericalApproximation::AddCubicHermiteDeriv ( const vector< double > &  fprimeOfx  )  throw (iException &)

Adds values for the first derivatives of the data points.

This method can only be called for cubic Hermite splines, i.e. if NumericalApproximation::InterpType is CubicHermite. These values should be entered in the order of the corresponding data points.

Parameters:
fprimeOfx Vector of derivative values to be added.
Exceptions:
Isis::iException::Programmer "Method only used for cspline-Hermite interpolation type"

For internal use only.

History:
2009-06-10 Jeannie Walldren - Original version

Definition at line 587 of file NumericalApproximation.cpp.

References _FILEINFO_, and CubicHermite.

void Isis::NumericalApproximation::AddCubicHermiteDeriv ( unsigned int  n,
double *  fprimeOfx 
) throw (iException &)

Adds values for the first derivatives of the data points.

This method can only be called for cubic Hermite splines, i.e. if NumericalApproximation::InterpType is CubicHermite. These values should be entered in the order of the corresponding data points.

Parameters:
n Number of derivative values to be added.
fprimeOfx Array of derivative values to be added.
Exceptions:
Isis::iException::Programmer "Method only used for cspline-Hermite interpolation type"

For internal use only.

History:
2009-06-10 Jeannie Walldren - Original version

Definition at line 562 of file NumericalApproximation.cpp.

References _FILEINFO_, and CubicHermite.

Referenced by Isis::SpicePosition::SetEphemerisTimeHermiteCache().

void Isis::NumericalApproximation::AddData ( const vector< double > &  x,
const vector< double > &  y 
) throw (iException &)

Add set of points to the data set using vectors.

This method allows the user to add a set of points to the set of data in preparation for interpolation over an interval. This method does not overwrite previously added data. Rather, it adds the new data to the end of the existing data set.

Note: Behavior is undefined if the domain is not sorted in ascending or descending order.

Parameters:
x Vector of domain values to add to data set
y Vector of range values corresponding to each domain value in x
Exceptions:
Isis::iException::Programmer "Invalid arguments. The number of x-values does not equal the number of y-values."

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type vector.

Definition at line 495 of file NumericalApproximation.cpp.

References _FILEINFO_, x, and y.

void Isis::NumericalApproximation::AddData ( unsigned int  n,
double *  x,
double *  y 
)

Add set of points to the data set using pointer arrays.

This method allows the user to add a set of points to the set of data in preparation for interpolation over an interval. This method does not overwrite previously added data. Rather, it adds the new data to the end of the existing data set.

Note: Behavior is undefined if the domain is not sorted in ascending or descending order.

Parameters:
n Number of data points to be used.
x Array of domain values to add to data set
y Array of range values corresponding to each domain value in x

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 456 of file NumericalApproximation.cpp.

References p_acc, p_clampedComputed, p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedEndptsSet, p_clampedSecondDerivs, p_dataValidated, p_interp, p_polyNevError, p_x, and p_y.

void Isis::NumericalApproximation::AddData ( const double  x,
const double  y 
)

Add a datapoint to the set.

This method allows the user to add a point to the set of data in preparation for interpolation over an interval.

Note: All data sets must have unique x values. If the interpolation type is not PolynomialNeville, x values must be sorted in ascending order. If CubicNatPeriodic interpolation type is used, the first and last points added to the data set must have the same y value.

Parameters:
x Domain value to add to data set
y Range value corresponding to domain value x

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to reset class variables for interpolation types other than those supported by GSL.

Definition at line 423 of file NumericalApproximation.cpp.

References p_acc, p_clampedComputed, p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedEndptsSet, p_clampedSecondDerivs, p_dataValidated, p_interp, p_polyNevError, p_x, and p_y.

Referenced by EvaluateCubicNeighborhood(), Isis::AtmosModel::GenerateAhTable(), Isis::AtmosModel::GenerateHahgTables(), and Isis::SpicePosition::SetEphemerisTimeHermiteCache().

double Isis::NumericalApproximation::BackwardFirstDifference ( const double  a,
const unsigned int  n = 3,
const double  h = 0.1 
) throw (iException &)

Uses an n point backward first difference formula to approximate the first derivative evaluated at a given domain value.

This method uses backward first difference formulas to return an approximation of the first derivative of the interpolated data set function evaluated at given a valid domain value, a. Backward difference formulas use n points, with the largest x value at a, for numerical differentiation approximation. This method uses one of the following formulas:

Parameters:
a Domain value at which first deriviative is evaluated.
n The number of points used in the formula
h Distance between nearest points in the formula
Returns:
double First derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a-(n-1)h is less than domain min.
Isis::iException::Programmer "Invalid argument. There is no n-point backward difference formula in use."
Isis::iException::Programmer "Unable to calculate backward first difference for given (a,n,h)"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1112 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

double Isis::NumericalApproximation::BackwardSecondDifference ( const double  a,
const unsigned int  n = 3,
const double  h = 0.1 
) throw (iException &)

Uses an n point backward second difference formula to approximate the second derivative evaluated at a given domain value.

This method uses backward second difference formulas to return an approximation of the second derivative of the interpolated data set function evaluated at given a valid domain value, a. Backward second difference formulas use n points, with the largest x value at a, for numerical differentiation approximation. This method uses the following formula:

Parameters:
a Domain value at which second deriviative is evaluated.
n The number of points used in the formula.
h Distance between nearest points in the formula.
Returns:
double Second derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a-(n-1)h is less than domain min.
Isis::iException::Programmer "Invalid argument. There is no n-point backward difference formula in use."
Isis::iException::Programmer 

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1485 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

double Isis::NumericalApproximation::BoolesRule ( const double  a,
const double  b 
)

Uses Boole's Rule to approximate the integral of the interpolated data set function on the interval (a,b).

The Boole's Rule for integration approximation uses a 5-point Newton-Cote formula. This rule states:

\[ \int_{a}^b f(x)dx \approx \frac{2h}{45}[7f(a) + 32f(a+h) + 12f(a+2h) + 32f(a+3h) + 7f(a+4h)] \]

where h = (b - a)/4.

This method uses a composite, or extended, Boole's rule formula to approximate the integral.

Note: The method uses an algorithm that is adapted from the IDL function int_tabulated.pro.

Parameters:
a Lower bound of interval.
b Upper bound of interval.
Returns:
double Approximate integral of data set function from a to b.
Exceptions:
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using Boole's rule"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1951 of file NumericalApproximation.cpp.

References _FILEINFO_, e, EvaluateForIntegration(), and Isis::iException::Message().

double Isis::NumericalApproximation::CenterFirstDifference ( const double  a,
const unsigned int  n = 5,
const double  h = 0.1 
) throw (iException &)

Uses an n point center first difference formula to approximate the first derivative evaluated at a given domain value.

This method uses center first difference formulas to return an approximation of the first derivative of the interpolated data set function evaluated at given a valid domain value, a. Center difference formulas use n points, centered at a, for numerical differentiation approximation. This method uses one of the following formulas:

Parameters:
a Domain value at which first deriviative is evaluated.
n The number of points used in the formula.
h Distance between nearest points in the formula.
Returns:
double First derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a+(n-1)h is greater than domain max or a-(n-1)h is less than domain min.
Isis::iException::Programmer "Invalid argument. There is no n-point center difference formula in use."
Isis::iException::Programmer "Unable to calculate center first difference for (a,n,h)"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1283 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

double Isis::NumericalApproximation::CenterSecondDifference ( const double  a,
const unsigned int  n = 5,
const double  h = 0.1 
) throw (iException &)

Uses an n point center second difference formula to approximate the second derivative evaluated at a given domain value.

This method uses center second difference formulas to return an approximation of the second derivative of the interpolated data set function evaluated at given a valid domain value, a. Center second difference formulas use n points, centered at a, for numerical differentiation approximation. This method uses one of the following formulas:

Parameters:
a Domain value at which second deriviative is evaluated.
n The number of points used in the formula.
h Distance between nearest points in the formula.
Returns:
double Second derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a+(n-1)h is greater than domain max or a-(n-1)h is less than domain min.
Isis::iException::Programmer "Invalid argument. There is no n-point center difference formula in use."
Isis::iException::Programmer "Unable to calculate center second difference for (a,n,h)"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1649 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

void Isis::NumericalApproximation::ComputeCubicClamped (  )  throw (iException &) [protected]

Computes the cubic clamped interpolation for a set of (x,y) data points, given the first derivatives of the endpoints of the data set.

This protected method is called only if the object is assigned a cubic clamped interpolation type and if it has not already been computed for the given data set. It calculates the second derivatives for each p_x value of the known data set and stores these values in p_clampedSecondDerivs so that the EvaluateCubicClamped() method may be called to interpolate the set using clamped boundary conditions, if possible. This method must be called when all the data points have been added to the object for the data set and after SetCubicClampedEndptDeriv() has been called. If the endpoint derivatives are greater than or equal to 1 x 1030, the routine is signaled to set the corresponding boundary condition for a natural spline, with zero second derivative on that boundary.

Exceptions:
Issis::iException::Programmer "Must use SetCubicClampedEndptDeriv() before computing cubic spline with clamped boundary"
Issis::iException::Programmer "Unable to compute cubic clamped interpolation"
See also:
SetCubicClampedEndptDeriv()

EvaluateCubicClamped()

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version in Isis2.
History:
2007-02-20 Janet Barrett - Imported to Isis3 in NumericalMethods class. Original name r8spline().
History:
2008-11-05 Jeannie Walldren - Renamed and modified input parameters.

Definition at line 2647 of file NumericalApproximation.cpp.

References _FILEINFO_, e, Isis::iException::Message(), p_clampedComputed, p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedEndptsSet, p_clampedSecondDerivs, p_dataValidated, p_x, p_y, ReportException(), Size(), and ValidateDataSet().

Referenced by CubicClampedSecondDerivatives().

void Isis::NumericalApproximation::ComputeGsl (  )  throw (iException &) [protected]

Computes the GSL interpolation for a set of (x,y) data points.

This protected method is called only if the object is assigned a GSL interpolation type and if it has not already been computed on the given data set. It will compute the interval of interpolated range values over the given domain. A copy of this data is maintained in the object so the data points do not need to be interpolated on each evaluation of a point unless the data set changes.

Exceptions:
Isis::iException::Programmer "Unable to compute GSL interpolation"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for computation of interpolation types other than those supported by GSL.

Definition at line 2596 of file NumericalApproximation.cpp.

References _FILEINFO_, e, GslAllocation(), GslComputed(), GslIntegrityCheck(), Isis::iException::Message(), p_dataValidated, p_interp, p_x, p_y, Size(), and ValidateDataSet().

Referenced by DomainMaximum(), and DomainMinimum().

bool Isis::NumericalApproximation::Contains ( double  x  ) 

Returns whether the passed value is an element of the set of x-values in the data set.

This method uses a binary search of the set of x-values to determine whether the input is contained in this set.

Parameters:
x Value to search for in the data set.
Returns:
bool Whether the passed value is contained in the x-values of the data set.

For internal use only.

History:
2009-06-19 Jeannie Walldren - Original version.

Definition at line 750 of file NumericalApproximation.cpp.

References p_x.

vector< double > Isis::NumericalApproximation::CubicClampedSecondDerivatives (  )  throw (iException &)

Retrieves the second derivatives of the data set.

This method returns a vector of the same size as the data set. Each component is the second derivative of the corresponding p_x value , as estimated by the ComputeCubicClamped() method.

Returns:
vector <double> List of second derivatives for each p_x value in the data set.
Exceptions:
Isis::iException::Programmer "Method only used for cspline-clamped interpolation type"
Isis::iException::Programmer "Unable to calculate the second derivatives of the data set for a clamped cubic spline."
See also:
ComputeCubicClamped()

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version written to save off the error estimate found by EvaluatePolynomialNeville()
History:
2009-06-10 Jeannie Walldren - Moved itype verification to beginning of method.

Definition at line 647 of file NumericalApproximation.cpp.

References _FILEINFO_, ComputeCubicClamped(), CubicClamped, e, Isis::iException::Message(), Name(), p_clampedComputed, p_clampedSecondDerivs, p_itype, and ReportException().

double Isis::NumericalApproximation::DomainMaximum (  ) 

Input data domain maximum value.

This method validates the data set for the assigned interpolation type and returns the largest value in p_x of the data set.

Returns:
double Maximum domain value
Exceptions:
Isis::iException::Programmer "Unable to calculate the domain minimum for the data set."

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for interpolation types other than those supported by GSL.

Definition at line 718 of file NumericalApproximation.cpp.

References _FILEINFO_, ComputeGsl(), e, GslComputed(), Isis::iException::Message(), p_dataValidated, p_interp, p_itype, p_x, and ValidateDataSet().

Referenced by InsideDomain(), and ValueToExtrapolate().

double Isis::NumericalApproximation::DomainMinimum (  ) 

Input data domain minimum value.

This method validates the data set for the assigned interpolation type and returns the smallest value in p_x of the data set.

Returns:
double Minimum domain value
Exceptions:
Isis::iException::Programmer "Unable to calculate the domain maximum for the data set."

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for interpolation types other than those supported by GSL.

Definition at line 682 of file NumericalApproximation.cpp.

References _FILEINFO_, ComputeGsl(), e, GslComputed(), Isis::iException::Message(), p_dataValidated, p_interp, p_itype, p_x, and ValidateDataSet().

Referenced by FindIntervalLowerIndex(), InsideDomain(), and ValueToExtrapolate().

vector< double > Isis::NumericalApproximation::Evaluate ( const vector< double > &  a,
const ExtrapType etype = ThrowError 
) throw (iException &)

Calculates interpolated value for given set of domain values.

This method returns the approximate values for f(ai), where ai is an element in the domain and f is the interpolated function for the given data set. If any of the given values in a fall outside of the domain, then the extrapoltion type is examined to determine the result. CubicNeighborhood and GSL interpolation types can not extrapolate, so the user must choose to throw an error or return f evaluated at the nearest domain boundary. CubicClamped and PolynomialNeville interpolation types can extrapolate a value with accuracy only if ai is near enough to the domain boundary.

Parameters:
a Vector of domain values from which to interpolate a vector of corresponding range values
etype NumericalApproximation::ExtrapType enum value indicates how to evaluate any value of a that falls outside of the domain. (Default: ThrowError)
Returns:
vector <double> Set of interpolated range values corresponding to the elements of the vector of domain values given
Exceptions:
Isis::iException::Programmer "Unable to evaluate the function at the vector of points, a."

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type vector and NumericalApproximation::ExtrapType.
History:
2009-06-10 Jeannie Walldren - Added functionality for CubicHermite evaluation.

Definition at line 868 of file NumericalApproximation.cpp.

References _FILEINFO_, a, CubicNeighborhood, e, Evaluate(), Isis::iException::Message(), and PolynomialNeville.

double Isis::NumericalApproximation::Evaluate ( const double  a,
const ExtrapType etype = ThrowError 
) throw (iException &)

Calculates interpolated or extrapolated value of tabulated data set for given domain value.

This method returns the approximate value for f(a), where a is an element near the domain and f is the approximated function for the given data set. If the given value, a, falls outside of the domain, then the extrapoltion type is examined to determine the result. CubicNeighborhood and GSL interpolation types can not extrapolate, so the user must choose to throw an error or return f evaluated at the nearest domain boundary. CubicClamped, CubicHermite, and PolynomialNeville interpolation types can extrapolate a value with accuracy only if a is near enough to the domain boundary. Default NumericalApproximation::ExtrapType is ThrowError.

Parameters:
a Domain value from which to interpolate a corresponding range value
etype NumericalApproximation::ExtrapType enum value indicates how to evaluate if a falls outside of the domain. (Default: ThrowError)
Returns:
double Range value interpolated or extrapolated for the given domain value
Exceptions:
Isis::iException::Programmer "Unable to evaluate the function at the point a"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for interpolation types other than those supported by GSL.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type NumericalApproximation::ExtrapType.
History:
2009-06-10 Jeannie Walldren - Added functionality for CubicHermite evaluation.

Definition at line 793 of file NumericalApproximation.cpp.

References _FILEINFO_, a, CubicClamped, CubicHermite, CubicNeighborhood, e, Isis::iException::Message(), and PolynomialNeville.

Referenced by Isis::HapkeAtm2::AtmosModelAlgorithm(), Isis::HapkeAtm1::AtmosModelAlgorithm(), EvaluateCubicNeighborhood(), and Isis::SpicePosition::SetEphemerisTimeHermiteCache().

double Isis::NumericalApproximation::EvaluateCubicClamped ( const double  a  )  throw (iException &) [protected]

Performs cubic spline interpolation with clamped boundary conditions, if possible.

This is a protected method called by Evaluate() if the NumericalApproximation::InterpType is CubicClamped and SetCubicClampedEndptDeriv() has been called. It uses the second derivative vector, p_clampedSecondDerivs, to interpolate the value for f(a) using a clamped cubic spline formula,

Note: If the given value, a, falls outside of the domain, then extrapolation is attempted and the result is accurate only if a is near enough to the domain boundary.

Parameters:
a Domain value from which to interpolate a corresponding range value
Returns:
double Value returned from interpolation or extrapolation.
See also:
Evaluate()

ComputeCubicClamped()

SetCubicClampedEndptDeriv()

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version in Isis2.
History:
2007-02-20 Janet Barrett - Imported to Isis3 in NumericalMethods class. Original name r8splint().
History:
2008-11-05 Jeannie Walldren - Renamed and modified input parameters, removed iException and replaced it with ValidateDataSet() method.

Definition at line 2967 of file NumericalApproximation.cpp.

References a.

double Isis::NumericalApproximation::EvaluateCubicHermite ( const double  a  )  throw (iException &) [protected]

Performs interpolation using the Hermite cubic polynomial.

This is a protected method called by Evaluate() if the NumericalApproximation::InterpType is CubicHermite. It returns an approximate value for f(a) by using the Hermite cubic polynomial, which uses Lagrange coefficient polynomials. The data points and each corresponding first derivative should have been already added.

Parameters:
a Domain value from which to interpolate a corresponding range value
Returns:
double Value returned from interpolation or extrapolation
Exceptions:
Isis::iException::User "Invalid arguments. The size of the first derivative vector does not match the number of (x,y) data points."
See also:
http://mathworld.wolfram.com/HermitesInterpolatingPolynomial.html

http://en.wikipedia.org/wiki/Lagrange_Polynomial

Evaluate()

AddCubicHermiteDeriv()

For internal use only.

History:
2009-06-10 Jeannie Walldren - Original version.

Definition at line 3028 of file NumericalApproximation.cpp.

References _FILEINFO_, and a.

double Isis::NumericalApproximation::EvaluateCubicHermiteFirstDeriv ( const double  a  ) 

Approximates the first derivative of the data set function evaluated at the given domain value for CubicHermite interpolation type.

This method returns an approximation of the first derivative evaluated at given a valid domain value, a. It is able to extrapolate for values not far outside of the domain

For internal use only.

History:
2009-07-30 Debbie Cook - Original Version

Definition at line 1024 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicHermite, FindIntervalLowerIndex(), Name(), p_fprimeOfx, p_itype, p_x, p_y, ReportException(), and Size().

Referenced by Isis::SpicePosition::SetEphemerisTimeHermiteCache().

double Isis::NumericalApproximation::EvaluateCubicHermiteSecDeriv ( const double  a  ) 

Approximates the second derivative of the data set function evaluated at the given domain value for CubicHermite interpolation type.

This method returns an approximation of the second derivative evaluated at given a valid domain value, a. It is able to extrapolate for values not far outside of the domain

For internal use only.

History:
2009-07-30 Debbie Cook - Original Version

Definition at line 1413 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicHermite, FindIntervalLowerIndex(), Name(), p_fprimeOfx, p_itype, p_x, p_y, ReportException(), and Size().

vector< double > Isis::NumericalApproximation::EvaluateCubicNeighborhood ( const vector< double > &  a,
const ExtrapType etype 
) [protected]

Performs cubic spline interpolations for neighborhoods about each value of a.

This is a protected method called by Evaluate() if the NumericalApproximation::InterpType is CubicNeighborhood. It uses an algorithm that is adapted from the IDL interpol.pro application using the "/spline" keyword on an irregular grid. For each component of a, this method fits a natural cubic spline using the 4-point neighborhood of known data points surrounding that component. For example, suppose {x0, x1, ..., xn} is the array of known domain values in the data set, then for each component of a, ak, in the domain, there is an i such that $ 0 \leq i \leq n $ and $ x_i \leq a_k < x_{i+1}$. Then, f(ak) is evaluated by interpolating the natural cubic spline consisting of the data set {xi-1, xi, xi+1, xi+2} at ak.

Note: If any given value, ai, falls outside of the domain, then f is evaluated at the nearest domain boundary.

Parameters:
a Vector of domain values from which to interpolate a vector of corresponding range values
etype NumericalApproximation::ExtrapType enum value indicates how to evaluate if a falls outside of the domain. (Default: ThrowError)
Returns:
vector <double> Result of interpolated value of f at each value of a.
Exceptions:
Isis::iException::Programmer "Unable to evaluate cubic neighborhood interpolation at the values in the vector, a"
See also:
Evaluate()

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type vector and NumericalApproximation::ExtrapType.

Definition at line 2881 of file NumericalApproximation.cpp.

References _FILEINFO_, AddData(), CubicNatural, e, Evaluate(), InsideDomain(), Isis::iException::Message(), NearestEndpoint, p_x, p_y, Reset(), Size(), and ValueToExtrapolate().

double Isis::NumericalApproximation::EvaluateCubicNeighborhood ( const double  a  )  [protected]

Performs cubic spline interpolation for a neighborhood about a.

This is a protected method called by Evaluate() if the NumericalApproximation::InterpType is CubicNeighborhood. It uses an algorithm that is adapted from the IDL interpol.pro application using the "/spline" keyword on an irregular grid. This type of cubic spline fits a natural cubic spline to the 4-point neighborhood of known data points surrounding a. For example, suppose {x0, x1, ..., xn} is the array of known domain values in the data set and $ x_i \leq a < x_{i+1}$ for some i such that $ 0 \leq i \leq n $, then f(a) is evaluated by interpolating the natural cubic spline consisting of the data set {xi-1, xi, xi+1, xi+2} at a.

Note: If the given value, a, falls outside of the domain, then f evaluated at the nearest domain boundary is returned.

Parameters:
a Domain value from which to interpolate a corresponding range value.
Returns:
double Result of interpolated value of f(a).
Exceptions:
Isis::iException::Programmer "Unable to evaluate cubic neighborhood interpolation at a"
See also:
Evaluate()

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 2802 of file NumericalApproximation.cpp.

References _FILEINFO_, AddData(), CubicNatural, e, Evaluate(), Isis::iException::Message(), NearestEndpoint, p_x, p_y, and Size().

vector< double > Isis::NumericalApproximation::EvaluateForIntegration ( const double  a,
const double  b,
const unsigned int  n 
) throw (iException &) [protected]

Evaluates data set in order to have enough data points to approximate the function to be integrated.

Parameters:
a Lower bound of interval.
b Upper bound of interval.
n Number of points used in Newton-Cotes formula.
Returns:
vector <double> Array of y values to be used in numerical integration
Exceptions:
Isis::iException::Programmer (When a > b) "Invalid interval entered"
Isis::iException::Programmer "Invalid arguments. Interval entered is not contained within domain"
Isis::iException::Programmer "Unable to evaluate the data set for integration"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 3213 of file NumericalApproximation.cpp.

References _FILEINFO_, a, b, e, Evaluate(), and Isis::iException::Message().

Referenced by BoolesRule(), Simpsons3PointRule(), Simpsons4PointRule(), and TrapezoidalRule().

double Isis::NumericalApproximation::EvaluatePolynomialNeville ( const double  a  )  throw (iException &) [protected]

Performs polynomial interpolation using Neville's algorithm.

This is a protected method called by Evaluate() if the NumericalApproximation::InterpType is PolynomialNeville. It uses Neville's algorithm for Lagrange polynomials. It returns a value f(a) and sets the error estimate p_polyNevError. After this method is called, the user may access this error estimate by calling PolynomialNevilleErrorEstimate().

Note: If the given value, a, falls outside of the domain, then extrapolation is attempted and the result is accurate only if a is near enough to the domain boundary.

Parameters:
a Domain value from which to interpolate a corresponding range value
Returns:
double Value returned from interpolation or extrapolation
See also:
http://mathworld.wolfram.com/NevillesAlgorithm.html

Evaluate()

PolynomialNevilleErrorEstimate()

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version in Isis2.
History:
2007-02-20 Janet Barrett - Imported to Isis3 in NumericalMethods class. Original name r8polint()
History:
2008-11-05 Jeannie Walldren - Renamed and modified input/output parameters, removed iException and replaced it with ValidateDataSet() method.

Definition at line 3149 of file NumericalApproximation.cpp.

References a, c, d, ns, and y.

int Isis::NumericalApproximation::FindIntervalLowerIndex ( const double  a  )  [protected]

Find the index of the x-value in the data set that is just below the input value, a.

This method is used by EvaluateCubicHermite(), EvaluateCubFirstDeriv() and EvaluateCubicHermiteSecDeriv() to determine in which interval of x-values a lies. It returns the index of the lower endpoint of the interval. If a is below the domain minimum, the method returns 0 as the lower index. If a is above the domain maximum, it returns the second to last index of the data set, Size()-2, as the lower index.

Parameters:
a Domain value around which the interval lies
Returns:
int Index of the x-value that is the lower endpoint of the interval of data points that surrounds a. Returns 0 if a is below domain min and Size()-2 if a is above domain max.

For internal use only.

History:
2009-06-10 Jeannie Walldren - Original Version

Definition at line 3090 of file NumericalApproximation.cpp.

References DomainMinimum(), InsideDomain(), p_x, pos, and Size().

Referenced by EvaluateCubicHermiteFirstDeriv(), and EvaluateCubicHermiteSecDeriv().

double Isis::NumericalApproximation::ForwardFirstDifference ( const double  a,
const unsigned int  n = 3,
const double  h = 0.1 
) throw (iException &)

Uses an n point forward first difference formula to approximate the first derivative evaluated at a given domain value.

This method uses forward first difference formulas to return an approximation of the first derivative of the interpolated data set function evaluated at given a valid domain value, a. Forward difference formulas use n points, with the smallest x value at a, for numerical differentiation approximation. This method uses one of the following formulas:

Parameters:
a Domain value at which first deriviative is evaluated.
n The number of points used in the formula.
h Distance between nearest points in the formula.
Returns:
double First derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a+(n-1)h is greater than domain max.
Isis::iException::Programmer "Invalid argument. There is no n-point forward difference formula in use."
Isis::iException::Programmer "Unable to calculate forward first difference for (a,n,h)"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1197 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

double Isis::NumericalApproximation::ForwardSecondDifference ( const double  a,
const unsigned int  n = 3,
const double  h = 0.1 
) throw (iException &)

Uses an n point forward second difference formula to approximate the second derivative evaluated at a given domain value.

This method uses forward second difference formulas to return an approximation of the second derivative of the interpolated data set function evaluated at given a valid domain value, a. Forward second difference formulas use n points, with the smallest x value at a, for numerical differentiation approximation. This method uses the following formula:

Parameters:
a Domain value at which second deriviative is evaluated.
n The number of points used in the formula.
h Distance between nearest points in the formula.
Returns:
double Second derivative approximation for the given domain value
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Formula steps outside of domain." If a+(n-1)h is greater than domain max.
Isis::iException::Programmer "Invalid argument. There is no n-point forward difference formula in use."
Isis::iException::Programmer "Unable to calculate forward second difference for (a,n,h)"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1564 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Evaluate(), and Isis::iException::Message().

void Isis::NumericalApproximation::GslAllocation ( unsigned int  npoints  )  [protected]

Allocates GSL interpolation functions.

This method is called within Compute to allocate pointers to a GSL interpolation object and to a GSL accelerator object (for interpolation look-ups). This is only called for the GSL interpolation types. If it is deemed invalid, an exception will be thrown.

Parameters:
npoints Number of points to allocate for the GSL interpolator

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name allocate().
History:
2008-11-05 Jeannie Walldren - Renamed.

Definition at line 2358 of file NumericalApproximation.cpp.

References GslDeallocation(), p_acc, p_interp, and p_itype.

Referenced by ComputeGsl().

bool Isis::NumericalApproximation::GslComputed (  )  const [protected]

Returns whether a GSL interpolation computation of the data set has been performed.

This method is only applicable to GSL interpolation types.

Returns:
bool True if GSL interpolation has been computed.
Exceptions:
Isis::iException::Programmer "Method only valid for GSL interpolation types"
See also:
ComputeGsl()

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Renamed, added iException.

Definition at line 2566 of file NumericalApproximation.cpp.

References _FILEINFO_, Isis::iException::Message(), Name(), p_acc, p_interp, and p_itype.

Referenced by ComputeGsl(), DomainMaximum(), and DomainMinimum().

void Isis::NumericalApproximation::GslDeallocation (  )  [protected]

Deallocate GSL interpolator resources, if used.

If a GSL interpolator function has been allocated, this routine will free its resources and reset internal pointers to reflect this state and provide a mechanism to test its state. Otherwise, this method sets the internal GSL pointers to their default, 0.

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name deallocate().
History:
2008-11-05 Jeannie Walldren - Renamed.

Definition at line 2380 of file NumericalApproximation.cpp.

References p_acc, and p_interp.

Referenced by GslAllocation(), operator=(), Reset(), and ~NumericalApproximation().

double Isis::NumericalApproximation::GslFirstDerivative ( const double  a  )  throw (iException &)

Approximates the first derivative of the data set function evaluated at the given domain value for GSL supported interpolation types.

This method returns an approximation of the first derivative evaluated at given a valid domain value, a. It is a wrapper for the GSL subroutine gsl_spline_eval_deriv_e(). If the NumericalApproximation::InterpType is not a GSL type, then this method throws an error. No documentation was found concerning the algorithm used by this method.

Parameters:
a Domain value at which first deriviative is evaluated.
Returns:
double First derivative approximation for the given domain value, if valid.
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Cannot use this method for interpolation type" (If the interpolation type is not GSL)
Isis::iException::Programmer "Unable to compute the first derivative at a using the GSL interpolation"
Isis::iException::Programmer "Unable to compute the first derivative at a. GSL integrity check failed"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name firstDerivative().
History:
2008-11-05 Jeannie Walldren - Modified to throw errors if passed value is out of domain or if interpolation type is not supported by GSL.

Definition at line 975 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Isis::iException::Message(), and value.

double Isis::NumericalApproximation::GslIntegral ( const double  a,
const double  b 
) throw (iException &)

Approximates the integral of the data set function evaluated on the given interval for GSL supported interpolation types.

This method returns an approximation of the integral evaluated on a given valid domain interval, (a,b). It is a wrapper for the GSL subroutine gsl_spline_eval_integ_e(). If the NumericalApproximation::InterpType is not a GSL type, then this method throws an error. No documentation was found concerning the algorithm used by this method.

Parameters:
a Lower endpoint at which integral is evaluated.
b Upper endpoint at which integral is evaluated.
Returns:
double Integral approximation for the given interval, if valid.
Exceptions:
Isis::iException::Programmer (When a > b) "Invalid interval entered"
Isis::iException::Programmer "Invalid arguments. Interval entered is not contained within domain"
Isis::iException::Programmer "Cannot use this method for interpolation type" (If the interpolation type is not GSL)
Isis::iException::Programmer "Unable to compute the integral on the interval (a,b) using GSL interpolation"
Isis::iException::Programmer "Unable to compute the integral on the interval (a,b). GSL integrity check failed."

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1726 of file NumericalApproximation.cpp.

References _FILEINFO_, a, b, e, Isis::iException::Message(), and value.

void Isis::NumericalApproximation::GslIntegrityCheck ( int  gsl_status,
char *  src,
int  line 
) throw (iException &) [protected]

Checks the status of the GSL interpolation operations.

This method takes a return status from a GSL call and determines if it is completed successfully. This implementation currently allows the GSL_DOMAIN error to propagate through sucessfully as the domain can be checked by the caller if they deem this necessary.

Parameters:
gsl_status Return status of a GSL function call
src Name of the calling source invoking the check. This allows more precise determination of the error.
line Line of the calling source that invoked the check
Exceptions:
Isis::iException::Programmer "GSL error occured"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name integrityCheck().
History:
2008-11-05 Jeannie Walldren - Renamed.

Definition at line 2437 of file NumericalApproximation.cpp.

References line.

Referenced by ComputeGsl().

double Isis::NumericalApproximation::GslSecondDerivative ( const double  a  )  throw (iException &)

Approximates the second derivative of the interpolated data set function evaluated at the given domain value for GSL supported interpolation types.

This method returns an approximation of the second derivative evaluated at given a valid domain value, a. It is a wrapper for the GSL subroutine gsl_spline_eval_deriv2_e(). If the NumericalApproximation::InterpType is not a GSL type, then this method throws an error. No documentation was found concerning the algorithm used by this method.

Parameters:
a Domain value at which second deriviative is evaluated.
Returns:
double Second derivative approximation for the given domain value, if valid.
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain."
Isis::iException::Programmer "Cannot use this method for interpolation type" (If the interpolation type is not GSL)
Isis::iException::Programmer "Unable to compute the second derivative at a using GSL interpolation"
Isis::iException::Programmer "Unable to compute the second derivative at a. GSL integrity check failed"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class. Original name secondDerivative().
History:
2008-11-05 Jeannie Walldren - Modified to throw errors if passed value is out of domain or if interpolation type is not supported by GSL.

Definition at line 1363 of file NumericalApproximation.cpp.

References _FILEINFO_, a, e, Isis::iException::Message(), and value.

bool Isis::NumericalApproximation::InsideDomain ( const double  a  )  [protected]

Returns whether the passed value is greater than or equal to the domain minimum and less than or equal to the domain maximum.

Parameters:
a Value to be verified as valid domain value.
Returns:
bool True if passed parameter is within the domain.
Exceptions:
Isis::iException::Programmer "Unable to compute domain boundaries"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 2533 of file NumericalApproximation.cpp.

References _FILEINFO_, DomainMaximum(), DomainMinimum(), e, and Isis::iException::Message().

Referenced by EvaluateCubicNeighborhood(), and FindIntervalLowerIndex().

InterpType Isis::NumericalApproximation::InterpolationType (  )  [inline]

Returns the enumerated type of interpolation chosen.

This method can be selected after all the points are added in the interpolation by using Compute() method. Note that this prints out as an integer representaion of the enumerated type:

Returns:
NumericalApproximation::InterpType Currently assigned interpolation type

Definition at line 770 of file NumericalApproximation.h.

References p_itype.

int Isis::NumericalApproximation::MinPoints (  ) 

Minimum number of points required by interpolating function.

This method returns the minimum number of points that are required by the interpolating function in order for it to be applied to a data set. It returns the number of the of the currently selected/active interpolation function.

Returns:
int Minimum number of data points required for the interpolation function
Exceptions:
Isis::iException::Programmer "Unable to calculate minimum points."

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for interpolation types other than those supported by GSL.
History:
2009-06-10 Jeannie Walldren - Added min points for CubicHermite.

Definition at line 318 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicClamped, CubicHermite, CubicNeighborhood, e, Isis::iException::Message(), p_itype, and PolynomialNeville.

Referenced by ValidateDataSet().

string Isis::NumericalApproximation::Name (  )  const

Get name of interpolating function assigned to object.

This method returns the name of the interpolation type that is currently assigned to this object as a std::string. This may be called without adding any points. If called before computation, the result reflects the name of the function chosen at instantiation.

Returns:
std::string Name of the interpolation function used/to be used.
Exceptions:
Isis::iException::Programmer "Unable to retrieve numerical approximation name",

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for interpolation types other than those supported by GSL.
History:
2009-06-10 Jeannie Walldren - Added CubicHermite name.

Definition at line 268 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicClamped, CubicHermite, CubicNatural, CubicNeighborhood, e, Isis::iException::Message(), p_itype, and PolynomialNeville.

Referenced by CubicClampedSecondDerivatives(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), GslComputed(), PolynomialNevilleErrorEstimate(), ValidateDataSet(), and ValueToExtrapolate().

NumericalApproximation::NumericalApproximation & Isis::NumericalApproximation::operator= ( const NumericalApproximation oldObject  ) 

NumericalApproximation assigmment operator sets this object "equal to" another.

Assigning one object to the other requires a deallocation of the current state of this object and reinitialization of data from the right hand object. This may be a bit costly if the number of values is large.

Parameters:
oldObject NumericalApproximation object to copy data from for initialization
Exceptions:
Isis::iException::Programmer "Unable to copy NumericalApproximation object"

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Changed name and modified to allow for interpolation types other than those supported by GSL.
History:
2009-06-10 Jeannie Walldren - Set new variable, p_fprimeOfx.

Definition at line 207 of file NumericalApproximation.cpp.

References _FILEINFO_, e, GslDeallocation(), Isis::iException::Message(), p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedSecondDerivs, p_dataValidated, p_fprimeOfx, p_itype, p_polyNevError, p_x, and p_y.

vector< double > Isis::NumericalApproximation::PolynomialNevilleErrorEstimate (  )  throw (iException &)

Retrieves the error estimate for the Neville's polynomial interpolation type.

This method must be called after the Evaluate() method has been invoked. If the Evaluate() method is passed a vector, this error will contain an error estimate for each of the values of the passed in vector. Otherwise, it will contain a single value.

Returns:
vector <double> Estimation of difference between actual value of f(a) and the polynomial Neville interpolated return value of Evaluate(), where f is the function that defines the given data set.
Exceptions:
Isis::iException::Programmer "Method only used for polynomial-Neville's interpolation type"
Isis::iException::Programmer "Error not calculated"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version written to save off the error estimate found by EvaluatePolynomialNeville()

Definition at line 925 of file NumericalApproximation.cpp.

References _FILEINFO_, Name(), p_itype, p_polyNevError, PolynomialNeville, and ReportException().

double Isis::NumericalApproximation::RefineExtendedTrap ( double  a,
double  b,
double  s,
unsigned int  n 
) throw (iException &)

Calculates refinements extended trapezoidal rule to approximate the integral of the interpolated data set function on the interval (a,b).

This method calculates the nth stage of refinement of an extended trapezoidal rule. When called with n = 1, the method returns the non-composite trapezoidal estimate of the integral. Subsequent calls with n = 2, 3, ... (in sequential order) will improve the accuracy by adding 2n-2 additional interior points. This method can be used to integrate by the extended trapeziodal rule if you know the number of steps you want to take. For example, if you want 2M + 1, use the following code:

 double result;
 for(int j = 1; j <= M+1; j++){
   result = RefineExtendedTrap(a,b,result,j);
 }
Note: Although this method may be used to approximate an integral, as described above, it is most often used by RombergsMethod() to integrate.

Parameters:
a Lower limit of integration
b Upper limit of integration
s Previous value of refinement
n Number of partitions to use when integrating
Returns:
double Integral (refined) approximation of the function on the interval (a, b)
Exceptions:
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using the extended trapezoidal rule"
See also:
RombergsMethod()

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version in Isis2.
History:
2007-02-20 Janet Barrett - Imported to Isis3 in AtmosModel class. Original name r8trapzd().
History:
2008-11-05 Jeannie Walldren - Renamed, modified input parameters, adapted to be used with data set.

Definition at line 2019 of file NumericalApproximation.cpp.

References _FILEINFO_, a, b, CubicNeighborhood, delta, e, Evaluate(), Extrapolate, Isis::iException::Message(), NearestEndpoint, sum, and x.

void Isis::NumericalApproximation::ReportException ( iException::errType  type,
const string &  methodName,
const string &  message,
char *  filesrc,
int  lineno 
) const throw (iException &) [protected]

Generalized error report generator.

This method is used throughout this class to standardize error reporting as a convenience to its implementor.

Parameters:
type Type of Isis::iException
methodName Name of method where exception originated
message Error context string provided by the caller
filesrc Name of the file the error occured in.
lineno Line number of the calling source where the error occured.
Exceptions:
Isis::iException::errType equal to type and error message equal to (methodName + " - " + message)

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to take iException::errType as input parameter.

Definition at line 3278 of file NumericalApproximation.cpp.

References Isis::iException::Message().

Referenced by ComputeCubicClamped(), CubicClampedSecondDerivatives(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), PolynomialNevilleErrorEstimate(), ValidateDataSet(), and ValueToExtrapolate().

void Isis::NumericalApproximation::Reset (  ) 

Resets the state of the object.

This method deallocates the internal state of the object and clears the data set and class variables. The object is returned to its original state, so data points must be entered before computing again. This does not clear or reset the interpolation type.

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to reset class variables related to interpolation types not supported by GSL.
History:
2009-06-10 Jeannie Walldren - Reset new variable, p_fprimeOfx.

Definition at line 2172 of file NumericalApproximation.cpp.

References GslDeallocation(), p_clampedComputed, p_clampedDerivFirstPt, p_clampedDerivLastPt, p_clampedEndptsSet, p_clampedSecondDerivs, p_dataValidated, p_fprimeOfx, p_itype, p_polyNevError, p_x, and p_y.

Referenced by EvaluateCubicNeighborhood(), Isis::AtmosModel::GenerateAhTable(), and Isis::AtmosModel::GenerateHahgTables().

double Isis::NumericalApproximation::RombergsMethod ( double  a,
double  b 
) throw (iException &)

Uses Romberg's method to approximate the integral of the interpolated data set function on the interval (a,b).

This method returns the integral of the function from a to b using Romberg's method for Numerical Integration of order 2K, where, e.g., K=2 is simpson's rule. This is a generalization of the trapezoidal rule. Romberg Integration uses a series of refinements on the extended (or composite) trapezoidal rule to reduce error terms. This method makes use of Neville's algorithm for polynomial interpolation to extrapolate successive refinements.

Parameters:
a Lower limit of integration
b Upper limit of integration
Returns:
double Integral approximation of the function on the interval (a, b)
Exceptions:
Isis::iException::Programmer "Failed to converge."
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using Romberg's method"
See also:
http://mathworld.wolfram.com/RombergIntegration.html

RefineExtendedTrap()

For internal use only.

History:
1999-08-11 K Teal Thompson - Original version in Isis2.
History:
2000-12-29 Randy Kirk - Add absolute error tolerance.
History:
2007-02-20 Janet Barrett - Imported to Isis3 in AtmosModel class. Original name r8qromb().
History:
2008-11-05 Jeannie Walldren - Renamed, modified input parameters, adapted to be used with data set.

Definition at line 2101 of file NumericalApproximation.cpp.

References _FILEINFO_, a, b, e, Extrapolate, interp, Isis::iException::Message(), PolynomialNeville, and ss.

void Isis::NumericalApproximation::SetCubicClampedEndptDeriv ( const double  yp1,
const double  ypn 
) throw (iException &)

Sets the values for the first derivatives of the endpoints of the data set.

This method can only be called for cubic splines with clamped boundary conditions, i.e. if NumericalApproximation::InterpType is CubicClamped.

Parameters:
yp1 First derivative of the function evaluated at the domain minimum.
ypn First derivative of the function evaluated at the domain maximum.
Exceptions:
Isis::iException::Programmer "Method only used for cspline-clamped interpolation type"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original verison.

Definition at line 535 of file NumericalApproximation.cpp.

References _FILEINFO_, and CubicClamped.

Referenced by Isis::AtmosModel::GenerateAhTable(), and Isis::AtmosModel::GenerateHahgTables().

double Isis::NumericalApproximation::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 interval (a,b).

The Simpson's 3-Point Rule for numerical integration uses a 3-point Newton-Cote formula. This rule states:

\[ \int_{a}^b f(x)dx \approx \frac{h}{3}[f(a) + f(a+h) + 4*f(a+2h)] \]

where h = (b - a)/2. This method uses a composite, or extended, Simpson's rule algorithm to approximate the integral.

Parameters:
a Lower bound of interval.
b Upper bound of interval.
Returns:
double Approximate integral of data set function from a to b.
Exceptions:
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using Simpson's 3 point rule"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1846 of file NumericalApproximation.cpp.

References _FILEINFO_, e, EvaluateForIntegration(), and Isis::iException::Message().

double Isis::NumericalApproximation::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 interval (a,b).

The Simpson's 4-point Rule for numerical integration uses a 4-point Newton-Cote formula and is sometimes called the Simpson's 3/8 Rule. This rule states:

\[ \int_{a}^b f(x)dx \approx \frac{3h}{8}[f(a) + 3f(a+h) + 3f(a+2h) + f(a+3h)] \]

where h = (b - a)/3. This method uses a composite, or extended, Simpson's 3/8 rule algorithm to approximate the integral.

Parameters:
a Lower bound of interval.
b Upper bound of interval.
Returns:
double Approximate integral of data set function from a to b.
Exceptions:
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using Simpson's 4 point rule"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1897 of file NumericalApproximation.cpp.

References _FILEINFO_, e, EvaluateForIntegration(), and Isis::iException::Message().

unsigned int Isis::NumericalApproximation::Size (  )  [inline]

Returns the number of the coordinates added to the data set.

Returns:
unsigned int Size of data set.

Definition at line 792 of file NumericalApproximation.h.

References p_x.

Referenced by ComputeCubicClamped(), ComputeGsl(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), EvaluateCubicNeighborhood(), FindIntervalLowerIndex(), and ValidateDataSet().

double Isis::NumericalApproximation::TrapezoidalRule ( const double  a,
const double  b 
)

Uses the trapezoidal rule to approximate the integral of the interpolated data set function on the interval (a, b).

The trapeziod rule for integration approximation uses a 2-point Newton-Cote formula. This rule states:

\[ \int_{a}^b f(x)dx \approx \frac{h}{2}[f(a) + f(b)] \]

where h = b - a. This method uses a composite, or extended, trapeziodal rule algorithm to approximate the integral.

Parameters:
a Lower bound of interval.
b Upper bound of interval.
Returns:
double Approximate integral of data set function from a to b.
Exceptions:
Isis::iException::Programmer "Unable to calculate the integral on the interval (a,b) using the trapezoidal rule"

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 1795 of file NumericalApproximation.cpp.

References _FILEINFO_, e, EvaluateForIntegration(), and Isis::iException::Message().

void Isis::NumericalApproximation::ValidateDataSet (  )  throw (iException &) [protected]

Validates the data set before computing interpolation.

This method is called from the ComputeCubicClamped() and ComputeGsl() methods to verify that the data set contains the minimum number of required points and that the components of the vector of domain values are unique. For all interpolation types other than polynomial-Neville's, the method verifies that the vector of domain values are also sorted in ascending order. For CubicNatPeriodic interpolation type, this method verifies that the first and last p_y values are equal, i.e. $ f(x_0) = f(x_{n-1}) $.

Exceptions:
Isis::iException::Programmer "Interpolation requires a minimim of data points"
Isis::iException::Programmer "Invalid data set, x-values must be unique"
Isis::iException::Programmer "Invalid data set, x-values must be in ascending order" (if interpolation type is not polynomial-Neville's)
Isis::iException::Programmer "First and last points of the data set must have the same y-value" (if interpolation type is cubic-periodic)

For internal use only.

History:
2008-11-05 Jeannie Walldren - Original version.

Definition at line 2477 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicNatPeriodic, MinPoints(), Name(), p_dataValidated, p_itype, p_x, p_y, PolynomialNeville, ReportException(), and Size().

Referenced by ComputeCubicClamped(), ComputeGsl(), DomainMaximum(), and DomainMinimum().

double Isis::NumericalApproximation::ValueToExtrapolate ( const double  a,
const ExtrapType etype 
) [protected]

Returns the domain value at which to evaluate.

This protected method is called by Evaluate() if a falls outside of the domain of p_x values in the data set. The return value is determined by the NumericalApproximation::ExtrapType. If it is ThrowError, an error is thrown indicating that a is out of the domain. If it is NearestEndpoint, then the nearest domain boundary value is returned. Otherwise, i.e. Extrapolate, a is returned as long as the NumericalApproximation::InterpType is not GSL or cubic neighborhood.

Parameters:
a Value passed into Evaluate() that falls outside of domain.
etype NumericalApproximation::ExtrapType enum value indicates how to evaluate if a falls outside of the domain. (Default: ThrowError)
Returns:
double Value returned to Evaluate() to be extrapolated.
Exceptions:
Isis::iException::Programmer "Invalid argument. Value entered is outside of domain
Isis::iException::Programmer "Invalid argument. Cannot extrapolate for interpolation type" (GSL or CubicNeighborhood)
See also:
Evaluate()

For internal use only.

History:
2006-06-14 Kris Becker - Original version created in DataInterp class.
History:
2008-11-05 Jeannie Walldren - Modified to allow for computation of interpolation types other than those supported by GSL.
History:
2008-12-18 Jeannie Walldren - Added address operator (&) to input variables of type NumericalApproximation::ExtrapType.

Definition at line 2739 of file NumericalApproximation.cpp.

References _FILEINFO_, CubicNeighborhood, DomainMaximum(), DomainMinimum(), Name(), NearestEndpoint, p_itype, ReportException(), and ThrowError.

Referenced by EvaluateCubicNeighborhood().


Member Data Documentation

gsl_interp_accel* Isis::NumericalApproximation::p_acc [protected]

Lookup accelorator.

Definition at line 854 of file NumericalApproximation.h.

Referenced by AddData(), GslAllocation(), GslComputed(), and GslDeallocation().

bool Isis::NumericalApproximation::p_clampedComputed [protected]

Flag variable to determine whether ComputeCubicClamped() has been called.

Definition at line 859 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), CubicClampedSecondDerivatives(), NumericalApproximation(), and Reset().

double Isis::NumericalApproximation::p_clampedDerivFirstPt [protected]

First derivative of first x-value, p_x[0]. This is only used for the CubicClamped interpolation type.

Definition at line 860 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), NumericalApproximation(), operator=(), and Reset().

double Isis::NumericalApproximation::p_clampedDerivLastPt [protected]

First derivative of last x-value, p_x[n-1]. This is only used for the CubicClamped interpolation type.

Definition at line 861 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), NumericalApproximation(), operator=(), and Reset().

bool Isis::NumericalApproximation::p_clampedEndptsSet [protected]

Flag variable to determine whether SetCubicClampedEndptDeriv() has been called after all data was added for CubicClamped interpolation.

Definition at line 858 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), NumericalApproximation(), and Reset().

vector<double> Isis::NumericalApproximation::p_clampedSecondDerivs [protected]

List of second derivatives evaluated at p_x values. This is only used for the CubicClamped interpolation type.

Definition at line 862 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), CubicClampedSecondDerivatives(), NumericalApproximation(), operator=(), and Reset().

bool Isis::NumericalApproximation::p_dataValidated [protected]

Flag variable to determine whether ValidateDataSet() has been called.

Definition at line 849 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), ComputeGsl(), DomainMaximum(), DomainMinimum(), NumericalApproximation(), operator=(), Reset(), and ValidateDataSet().

vector<double> Isis::NumericalApproximation::p_fprimeOfx [protected]

List of first derivatives corresponding to each x value in the data set (i.e. each value in p_x).

Definition at line 866 of file NumericalApproximation.h.

Referenced by EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), NumericalApproximation(), operator=(), and Reset().

gsl_spline* Isis::NumericalApproximation::p_interp [protected]

Currently active interpolator.

Definition at line 855 of file NumericalApproximation.h.

Referenced by AddData(), ComputeGsl(), DomainMaximum(), DomainMinimum(), GslAllocation(), GslComputed(), and GslDeallocation().

FunctorList Isis::NumericalApproximation::p_interpFunctors [protected]

Maintains list of interpolator options.

Definition at line 856 of file NumericalApproximation.h.

InterpType Isis::NumericalApproximation::p_itype [protected]

Interpolation type.

Definition at line 846 of file NumericalApproximation.h.

Referenced by CubicClampedSecondDerivatives(), DomainMaximum(), DomainMinimum(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), GslAllocation(), GslComputed(), InterpolationType(), MinPoints(), Name(), NumericalApproximation(), operator=(), PolynomialNevilleErrorEstimate(), Reset(), ValidateDataSet(), ValueToExtrapolate(), and ~NumericalApproximation().

vector<double> Isis::NumericalApproximation::p_polyNevError [protected]

Estimate of error for interpolation evaluated at x. This is only used for the PolynomialNeville interpolation type. 91 taken from AtmosModel.

Definition at line 864 of file NumericalApproximation.h.

Referenced by AddData(), NumericalApproximation(), operator=(), PolynomialNevilleErrorEstimate(), and Reset().

vector<double> Isis::NumericalApproximation::p_x [protected]

List of X values.

Definition at line 847 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), ComputeGsl(), Contains(), DomainMaximum(), DomainMinimum(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), EvaluateCubicNeighborhood(), FindIntervalLowerIndex(), NumericalApproximation(), operator=(), Reset(), Size(), and ValidateDataSet().

vector<double> Isis::NumericalApproximation::p_y [protected]

List of Y values.

Definition at line 848 of file NumericalApproximation.h.

Referenced by AddData(), ComputeCubicClamped(), ComputeGsl(), EvaluateCubicHermiteFirstDeriv(), EvaluateCubicHermiteSecDeriv(), EvaluateCubicNeighborhood(), NumericalApproximation(), operator=(), Reset(), and ValidateDataSet().


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