7#include "NumericalApproximation.h" 
   16#include "SpecialPixel.h" 
   17#include "IException.h" 
   49                       "NumericalApproximation() - Unable to construct NumericalApproximation object",
 
 
   96                       "NumericalApproximation() - Unable to construct object using the given arrays, size and interpolation type",
 
 
  140                       "NumericalApproximation() - Unable to construct an object using the given vectors and interpolation type",
 
 
  173      Init(oldObject.p_itype);
 
  191                       "NumericalApproximation() - Unable to copy the given object",
 
 
  222      if(&oldObject != 
this) {
 
  240                       "operator=() - Unable to copy the given object",
 
 
  284      return "cspline-neighborhood";
 
  287      return "cspline-clamped";
 
  290      return "polynomial-Neville's";
 
  293      return "cspline-Hermite";
 
  298        return name + 
"-natural";
 
  305                       "Name() - GSL interpolation type not found",
 
 
  352                       "MinPoints() - GSL interpolation not found",
 
 
  390        return (nam.GslFunctor(itype)->min_size);
 
  395                         "MinPoints() - GSL interpolation type not found",
 
  412                     "MinPoints() - Invalid argument. Unknown interpolation type: " 
 
  474    for(
unsigned int i = 0; i < n; i++) {
 
 
  513                                       const vector <double> &y)
 
  519                      "Invalid arguments. The sizes of the input vectors do " 
  526    if(!
p_x.empty() || !
p_y.empty()) {
 
  527      for(
int i = 0; i < n; i++) {
 
 
  568                      "This method is only valid for cspline-clamped interpolation, may not be used for " 
  569                      + 
Name() + 
" interpolation",
 
 
  595                      "This method is only valid for cspline-Hermite interpolation, may not be used for " 
  596                      + 
Name() + 
" interpolation",
 
  599    for(
unsigned int i = 0; i < n; i++) {
 
 
  618      const vector <double> &fprimeOfx) {
 
  621                      "This method is only valid for cspline-Hermite interpolation, may not be used for " 
  622                      + 
Name() + 
" interpolation",
 
  628      for(
unsigned int i = 0; i < fprimeOfx.size(); i++) {
 
 
  655                      "This method is only valid for cspline-Hermite interpolation, may not be used for " 
  656                      + 
Name() + 
" interpolation",
 
 
  691                        "This method is only valid for cspline-clamped interpolation type may not be used for " 
  692                        + 
Name() + 
" interpolation",
 
  700                       "CubicClampedSecondDerivatives() - Unable to compute clamped cubic spline interpolation",
 
 
  732        return *min_element(
p_x.begin(), 
p_x.end());
 
  738                       "DomainMinimum() - Unable to calculate the domain minimum for the data set",
 
 
  769        return *max_element(
p_x.begin(), 
p_x.end());
 
  775                       "DomainMaximum() - Unable to calculate the domain maximum for the data set",
 
 
  794    return binary_search(
p_x.begin(), 
p_x.end(), x);
 
 
  868                       "Evaluate() - Unable to evaluate the function at the point a = " 
 
  920      vector <double> result(a.size());
 
  925        for(
unsigned int i = 0; i < result.size(); i++) {
 
  936      for(
unsigned int i = 0; i < result.size(); i++) {
 
  944                       "Evaluate() - Unable to evaluate the function at the given vector of points",
 
 
  973                      "This method is only valid for polynomial-Neville's, may not be used for " 
  974                      + 
Name() + 
" interpolation",
 
  979                      "Error not calculated. This method only valid after Evaluate() has been called",
 
 
 1027                       "GslFirstDerivative() - Unable to compute the first derivative at a = " 
 1028                       + 
IString(a) + 
" using the GSL interpolation",
 
 1033                      "Invalid argument. Value entered, a = " 
 1034                      + 
IString(a) + 
", is outside of domain = [" 
 1041                      "Method only valid for GSL interpolation types, may not be used for " 
 1042                      + 
Name() + 
" interpolation",
 
 1053                       "GslFirstDerivative() - Unable to compute the first derivative at a = " 
 1054                       + 
IString(a) + 
". GSL integrity check failed",
 
 
 1074                      "This method is only valid for cspline-Hermite interpolation, may not be used for " 
 1075                      + 
Name() + 
" interpolation",
 
 1080                      "Invalid arguments. The size of the first derivative vector does not match the number of (x,y) data points.",
 
 1088    if(a == 
p_x[lowerIndex]) {
 
 1091    if(a == 
p_x[lowerIndex+1]) {
 
 1095    double x0, x1, y0, y1, m0, m1;
 
 1097    x0 = 
p_x[lowerIndex];
 
 1098    x1 = 
p_x[lowerIndex+1];
 
 1100    y0 = 
p_y[lowerIndex];
 
 1101    y1 = 
p_y[lowerIndex+1];
 
 1110      return ((6 * t * t - 6 * t) * y0 + (3 * t * t - 4 * t + 1) * h * m0 + (-6 * t * t + 6 * t) * y1 + (3 * t * t - 2 * t) * h * m1) / h;
 
 
 1162                      "Invalid argument. Value entered, a = " 
 1163                      + 
IString(a) + 
", is outside of domain = [" 
 1170                      "Formula steps outside of domain. For " 
 1171                      + 
IString((
int) n) + 
"-point backward difference, a-(n-1)h = " 
 1172                      + 
IString(a - (n - 1)*h) + 
" is smaller than domain min = " 
 1174                      + 
".  Try forward difference or use smaller value for h or n",
 
 1181      for(
double i = 0; i < n; i++) {
 
 1182        xi = a + h * (i - (n - 1));
 
 1189                       "BackwardFirstDifference() - Unable to calculate backward first difference for (a, n, h) = (" 
 1195        return (-f[0] + f[1]) / h;              
 
 1197        return (3 * f[2] - 4 * f[1] + f[0]) / (2 * h); 
 
 1200                         "BackwardFirstDifference() - Invalid argument. There is no " 
 1201                         + 
IString((
int) n) + 
"-point backward difference formula in use",
 
 
 1251                      "Invalid argument. Value entered, a = " 
 1252                      + 
IString(a) + 
", is outside of domain = [" 
 1259                      "Formula steps outside of domain. For " 
 1260                      + 
IString((
int) n) + 
"-point forward difference, a+(n-1)h = " 
 1261                      + 
IString(a + (n - 1)*h) + 
" is greater than domain max = " 
 1263                      + 
".  Try backward difference or use smaller value for h or n",
 
 1270      for(
double i = 0; i < n; i++) {
 
 1278                       "ForwardFirstDifference() - Unable to calculate forward first difference for (a, n, h) = (" 
 1284        return (-f[0] + f[1]) / h;              
 
 1286        return (-3 * f[0] + 4 * f[1] - f[2]) / (2 * h); 
 
 1289                         "ForwardFirstDifference() - Invalid argument. There is no " 
 1290                         + 
IString((
int) n) + 
"-point forward difference formula in use",
 
 
 1341                      "Invalid argument. Value entered, a = " 
 1342                      + 
IString(a) + 
", is outside of domain = [" 
 1349                      "Formula steps outside of domain. For " 
 1350                      + 
IString((
int) n) + 
"-point center difference, a-(n-1)h = " 
 1351                      + 
IString(a - (n - 1)*h) + 
" or a+(n-1)h = " 
 1352                      + 
IString(a + (n - 1)*h) + 
" is out of domain = [" 
 1354                      + 
"].  Use smaller value for h or n",
 
 1361      for(
double i = 0; i < n; i++) {
 
 1362        xi = a + h * (i - (n - 1) / 2);
 
 1369                       "CenterFirstDifference() - Unable to calculate center first difference for (a, n, h) = (" 
 1375        return (-f[0] + f[2]) / (2 * h);              
 
 1377        return (f[0] - 8 * f[1] + 8 * f[3] - f[4]) / (12 * h); 
 
 1380                         "CenterFirstDifference() - Invalid argument. There is no " 
 1381                         + 
IString((
int) n) + 
"-point center difference formula in use",
 
 
 1429                       "GslSecondDerivative() - Unable to compute the second derivative at a = " 
 1430                       + 
IString(a) + 
" using the GSL interpolation",
 
 1435                      "Invalid argument. Value entered, a = " 
 1436                      + 
IString(a) + 
", is outside of domain = [" 
 1442                      "Method only valid for GSL interpolation types, may not be used for " 
 1443                      + 
Name() + 
" interpolation",
 
 1455                       "GslSecondDerivative() - Unable to compute the second derivative at a = " 
 1456                       + 
IString(a) + 
". GSL integrity check failed",
 
 
 1477                      "This method is only valid for cspline-Hermite interpolation, may not be used for " 
 1478                      + 
Name() + 
" interpolation",
 
 1483                      "Invalid arguments. The size of the first derivative vector does not match the number of (x,y) data points.",
 
 1488    double x0, x1, y0, y1, m0, m1;
 
 1490    x0 = 
p_x[lowerIndex];
 
 1491    x1 = 
p_x[lowerIndex+1];
 
 1493    y0 = 
p_y[lowerIndex];
 
 1494    y1 = 
p_y[lowerIndex+1];
 
 1503      return ((12 * t - 6) * y0 + (6 * t - 4) * h * m0 + (-12 * t + 6) * y1 + (6 * t - 2) * h * m1) / h;
 
 
 1549                      "Invalid argument. Value entered, a = " 
 1550                      + 
IString(a) + 
", is outside of domain = [" 
 1557                      "Formula steps outside of domain. For " 
 1558                      + 
IString((
int) n) + 
"-point backward difference, a-(n-1)h = " 
 1559                      + 
IString(a - (n - 1)*h) + 
" is smaller than domain min = " 
 1561                      + 
".  Try forward difference or use smaller value for h or n",
 
 1568      for(
double i = 0; i < n; i++) {
 
 1569        xi = a + h * (i - (n - 1));
 
 1576                       "BackwardSecondDifference() - Unable to calculate backward second difference for (a, n, h) = (" 
 1582        return (f[0] - 2 * f[1] + f[2]) / (h * h);                   
 
 1585                         "BackwardSecondDifference() - Invalid argument. There is no " 
 1586                         + 
IString((
int) n) + 
"-point backward second difference formula in use",
 
 
 1631                      "Invalid argument. Value entered, a = " 
 1632                      + 
IString(a) + 
", is outside of domain = [" 
 1639                      "Formula steps outside of domain. For " 
 1640                      + 
IString((
int) n) + 
"-point forward difference, a+(n-1)h = " 
 1641                      + 
IString(a + (n - 1)*h) + 
" is greater than domain max = " 
 1643                      + 
".  Try backward difference or use smaller value for h or n",
 
 1650      for(
double i = 0; i < n; i++) {
 
 1658                       "ForwardSecondDifference() - Unable to calculate forward second difference for (a, n, h) = (" 
 1664        return (f[0] - 2 * f[1] + f[2]) / (h * h);                   
 
 1667                         "ForwardSecondDifference() - Invalid argument. There is no " 
 1668                         + 
IString((
int) n) + 
"-point forward second difference formula in use",
 
 
 1719                      "Invalid argument. Value entered, a = " 
 1720                      + 
IString(a) + 
", is outside of domain = [" 
 1727                      "Formula steps outside of domain. For " 
 1728                      + 
IString((
int) n) + 
"-point center difference, a-(n-1)h = " 
 1729                      + 
IString(a - (n - 1)*h) + 
" or a+(n-1)h = " 
 1730                      + 
IString(a + (n - 1)*h) + 
" is out of domain = [" 
 1732                      + 
"].  Use smaller value for h or n",
 
 1739      for(
double i = 0; i < n; i++) {
 
 1740        xi = a + h * (i - (n - 1) / 2);
 
 1747                       "CenterSecondDifference() - Unable to calculate center second difference for (a, n, h) = (" 
 1753        return (f[0] - 2 * f[1] + f[2]) / (h * h);                   
 
 1755        return (-f[0] + 16 * f[1] - 30 * f[2] + 16 * f[3] - f[4]) / (12 * h * h); 
 
 1758                         "CenterSecondDifference() - Invalid argument. There is no " 
 1759                         + 
IString((
int) n) + 
"-point center second difference formula in use",
 
 
 1804                       "GslIntegral() - Unable to compute the integral on the interval (a,b) = (" 
 1806                       + 
") using the GSL interpolation",
 
 1811                      "Invalid interval entered: [a,b] = [" 
 1817                      "Invalid arguments. Interval entered [" 
 1819                      + 
"] is not contained within domain [" 
 1826                      "Method only valid for GSL interpolation types, may not be used for " 
 1827                      + 
Name() + 
" interpolation",
 
 1838                       "GslIntegral() - Unable to compute the integral on the interval (a,b) = (" 
 1840                       + 
"). GSL integrity check failed",
 
 
 1874      double h = f.back();
 
 1878      for(
unsigned int i = 0; i < (f.size() - 1) / (n - 1); i++) {
 
 1879        ii = (i + 1) * (n - 1);
 
 1880        result += (f[ii-1] + f[ii]) * h / 2;
 
 1887                       "TrapezoidalRule() - Unable to calculate the integral on the interval (a,b) = (" 
 1889                       + 
") using the trapeziodal rule",
 
 
 1926      double h = f.back();
 
 1929      for(
unsigned int i = 0; i < (f.size() - 1) / (n - 1); i++) {
 
 1930        ii = (i + 1) * (n - 1);
 
 1931        result += (f[ii-2] + 4 * f[ii-1] + f[ii]) * h / 3;
 
 1938                       "Simpsons3PointRule() - Unable to calculate the integral on the interval (a,b) = (" 
 1940                       + 
") using Simpson's 3 point rule",
 
 
 1978      double h = f.back();
 
 1981      for(
unsigned int i = 0; i < (f.size() - 1) / (n - 1); i++) {
 
 1982        ii = (i + 1) * (n - 1);
 
 1983        result += (f[ii-3] + 3 * f[ii-2] + 3 * f[ii-1] + f[ii]) * h * 3 / 8;
 
 1990                       "Simpsons4PointRule() - Unable to calculate the integral on the interval (a,b) = (" 
 1992                       + 
") using Simpson's 4 point rule",
 
 
 2033      double h = f.back();
 
 2036      for(
unsigned int i = 0; i < (f.size() - 1) / (n - 1); i++) {
 
 2037        ii = (i + 1) * (n - 1);
 
 2038        result += (7 * f[ii-4] + 32 * f[ii-3] + 12 * f[ii-2] + 32 * f[ii-1] + 7 * f[ii]) * h * 2 / 45;
 
 2045                       "BoolesRule() - Unable to calculate the integral on the interval (a,b) = (" 
 2047                       + 
") using Boole's rule",
 
 
 2113        return (0.5 * (b - a) * (begin + end));
 
 2117        double delta, tnm, x, sum;
 
 2118        it = (int)(pow(2.0, (
double)(n - 2)));
 
 2120        delta = (b - a) / tnm; 
 
 2121        x = a + 0.5 * delta;
 
 2123        for(
int i = 0; i < it; i++) {
 
 2132        return (0.5 * (s + (b - a) * sum / tnm));
 
 2138                       "RefineExtendedTrap() - Unable to calculate the integral on the interval (a,b) = (" 
 2140                       + 
") using the extended trapeziodal rule",
 
 
 2186    double trap[maxits+1]; 
 
 2197      for(
int i = 0; i < maxits; i++) {
 
 2202          interp.AddData(5, &h[i-4], &trap[i-4]);
 
 2205          dss = interp.PolynomialNevilleErrorEstimate()[0];
 
 2208          if(fabs(dss) <= epsilon * fabs(ss)) 
return ss;
 
 2209          if(fabs(dss) <= epsilon2) 
return ss;
 
 2211        trap[i+1] = trap[i];
 
 2212        h[i+1] = 0.25 * h[i];
 
 2223                       "RombergsMethod() - Unable to calculate the integral on the interval (a,b) = (" 
 2225                       + 
") using Romberg's method",
 
 2229                     "RombergsMethod() - Unable to calculate the integral using RombergsMethod() - Failed to converge in " 
 2230                     + 
IString(maxits) + 
" iterations",
 
 
 2292                       "Reset() - Unable to reset interpolation type",
 
 
 2328                         "SetInterpType() - Unable to set interpolation type",
 
 2332    else if(itype > 9) {    
 
 2334                      "Invalid argument. Unknown interpolation type: " 
 
 2393                       "Init() - Unable to initialize NumericalApproximation object",
 
 2398    gsl_set_error_handler_off();
 
 
 2447    p_acc = gsl_interp_accel_alloc();
 
 
 2497                      "Invalid argument. Unable to find GSL interpolator with id = " 
 2501    return (fItr->second);
 
 
 2525    if(gsl_status != GSL_SUCCESS) {
 
 2526      if(gsl_status != GSL_EDOM) {
 
 2528                        "GslIntegrityCheck(): GSL error occured: " 
 2529                        + 
string(gsl_strerror(gsl_status)), src, line);
 
 
 2566                      Name() + 
" interpolation requires a minimum of " 
 2571    for(
unsigned int i = 1; i < 
Size(); i++) {
 
 2575                        "Invalid data set, x-values must be unique: \n\t\tp_x[" 
 2577                        + 
" = p_x[" + 
IString((
int) i) + 
"]",
 
 2585                          "Invalid data set, x-values must be in ascending order for " 
 2586                          + 
Name() + 
" interpolation: \n\t\tx[" 
 2596                        "First and last points of the data set must have the same y-value for " 
 2597                        + 
Name() + 
"interpolation to prevent discontinuity at the boundary",
 
 
 2631                       "InsideDomain() - Unable to compute domain boundaries",
 
 
 2657                       "GslComputed() - Method only valid for GSL interpolation types, may not be used for " 
 2658                       + 
Name() + 
" interpolation",
 
 
 2694                       "ComputeGsl() - Unable to compute GSL interpolation",
 
 
 2747                         "ComputeCubicClamped() - Unable to compute cubic clamped interpolation",
 
 2753                      "Must set endpoint derivative values after adding data in order to compute cubic spline with clamped boundary conditions",
 
 2759    double p, sig, qn, un;
 
 2769    for(
int i = 1; i < n - 1; i++) { 
 
 2774                     (
p_x[i] - 
p_x[i-1])) / (
p_x[i+1] - 
p_x[i-1]) - sig * u[i-1]) / p;
 
 2786    for(
int i = n - 2; i >= 0; i--) { 
 
 
 2833                      "Invalid argument. Value entered, a = " 
 2834                      + 
IString(a) + 
", is outside of domain = [" 
 2851                        "Invalid argument. Cannot extrapolate for type " 
 2852                        + 
Name() + 
", must choose to throw error or return nearest neighbor",
 
 
 2895      int s = 0, s_old, s0;
 
 2896      vector <double> x0(4), y0(4);
 
 2898      for(
unsigned int n = 0; n < 
Size(); n++) {
 
 2899        if(
p_x[n] < a) s = n;
 
 2903      else if(s > (
int) 
Size() - 3) s = 
Size() - 3;
 
 2907        for(
int n = 0; n < 4; n++) {
 
 2910          spline.AddData(x0[n], y0[n]);
 
 2921                       "EvaluateCubicNeighborhood() - Unable to evaluate cubic neighborhood interpolation at a = " 
 
 2975    vector <double> result(a.size());
 
 2977    vector <double> x0(4), y0(4);
 
 2981    for(
unsigned int i = 0; i < a.size(); i++) {
 
 2982      for(
unsigned int n = 0; n < 
Size(); n++) {
 
 2990      if(s[i] > ((
int) 
Size()) - 3) {
 
 2997      for(
unsigned int i = 0; i < a.size(); i++) {
 
 3001          for(
int n = 0; n < 4; n++) {
 
 3004            spline.AddData(x0[n], y0[n]);
 
 3021                       "EvaluateCubicNeighborhood() - Unable to evaluate the function at the given vector of points using cubic neighborhood interpolation",
 
 
 3076    while(k_Hi - k_Lo > 1) {
 
 3077      k = (k_Hi + k_Lo) / 2;
 
 3086    h = 
p_x[k_Hi] - 
p_x[k_Lo];
 
 3087    A = (
p_x[k_Hi] - a) / h;
 
 3088    B = (a - 
p_x[k_Lo]) / h;
 
 3089    result = A * 
p_y[k_Lo] + B * 
p_y[k_Hi] + ((pow(A, 3.0) - A) *
 
 
 3127                      "Invalid arguments. The size of the first derivative vector does not match the number of (x,y) data points.",
 
 3135    if(a == 
p_x[lowerIndex]) {
 
 3136      return p_y[lowerIndex];
 
 3138    if(a == 
p_x[lowerIndex+1]) {
 
 3139      return p_y[lowerIndex+1];
 
 3142    double x0, x1, y0, y1, m0, m1;
 
 3144    x0 = 
p_x[lowerIndex];
 
 3145    x1 = 
p_x[lowerIndex+1];
 
 3147    y0 = 
p_y[lowerIndex];
 
 3148    y1 = 
p_y[lowerIndex+1];
 
 3160    return (2 * t * t * t - 3 * t * t + 1) * y0 + (t * t * t - 2 * t * t + t) * h * m0 + (-2 * t * t * t + 3 * t * t) * y1 + (t * t * t - t * t) * h * m1;
 
 
 3186      std::vector<double>::iterator pos;
 
 3188      pos = upper_bound(
p_x.begin(), 
p_x.end(), a);
 
 3190      if(pos != 
p_x.end()) {
 
 3191        upperIndex = distance(
p_x.begin(), pos);
 
 3194        upperIndex = 
Size() - 1;
 
 3196      return upperIndex - 1;
 
 
 3250    double den, dif, dift, c[n], d[n], ho, hp, w;
 
 3253    dif = fabs(a - 
p_x[0]);
 
 3254    for(
int i = 0; i < n; i++) { 
 
 3255      dift = fabs(a - 
p_x[i]);
 
 3265    for(
int m = 1; m < n; m++) {
 
 3266      for(
int i = 1; i <= n - m; i++) { 
 
 3268        hp = 
p_x[i+m-1] - a;
 
 3275      if(2 * ns < n - m) { 
 
 
 3309                      "Invalid interval entered: [a,b] = [" 
 3315                      "Invalid arguments. Interval entered [" 
 3317                      + 
"] is not contained within domain [" 
 3326    int xSegments = 
Size() - 1;
 
 3327    while(xSegments % (n - 1) != 0) {
 
 3334    double h = (xMax - xMin) / xSegments;
 
 3337      for(
double i = 0; i < (xSegments + 1); i++) {
 
 3338        double xi = h * i + xMin;
 
 3347                       "EvaluateForIntegration() - Unable to evaluate the data set for integration",
 
 
 3373      const char *filesrc, 
int lineno)
 
 3375    string msg = methodName + 
" - " + message;
 
 3376    throw IException(type, msg.c_str(), filesrc, lineno);
 
 
ErrorType
Contains a set of exception error types.
 
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
 
@ Programmer
This error is for when a programmer made an API call that was illegal.
 
Adds specific functionality to C++ strings.
 
NumericalApproximation provides various numerical analysis methods of interpolation,...
 
void ValidateDataSet()
Validates the data set before computing interpolation.
 
gsl_interp_accel * p_acc
Lookup accelorator.
 
void GslDeallocation()
Deallocate GSL interpolator resources, if used.
 
void GslAllocation(unsigned int npoints)
Allocates GSL interpolation functions.
 
double EvaluatePolynomialNeville(const double a)
Performs polynomial interpolation using Neville's algorithm.
 
vector< double > p_x
List of X values.
 
vector< double > p_fprimeOfx
List of first derivatives corresponding to each x value in the data set (i.e. each value in p_x)
 
void ReportException(IException::ErrorType type, const string &method, const string &message, const char *filesrc, int lineno) const
Generalized error report generator.
 
double GslFirstDerivative(const double a)
Approximates the first derivative of the data set function evaluated at the given domain value for GS...
 
double p_clampedDerivLastPt
First derivative of last x-value, p_x[n-1]. This is only used for the CubicClamped interpolation type...
 
int FindIntervalLowerIndex(const double a)
Find the index of the x-value in the data set that is just below the input value, a.
 
vector< double > CubicClampedSecondDerivatives()
Retrieves the second derivatives of the data set.
 
double DomainMinimum()
Input data domain minimum value.
 
bool GslInterpType(NumericalApproximation::InterpType itype) const
Returns whether an interpolation type is adapted from the GSL library.
 
InterpFunctor GslFunctor(NumericalApproximation::InterpType itype) const
Search for a GSL interpolation function.
 
bool p_clampedComputed
Flag variable to determine whether ComputeCubicClamped() has been called.
 
double Evaluate(const double a, const ExtrapType &etype=ThrowError)
Calculates interpolated or extrapolated value of tabulated data set for given domain value.
 
void Init(NumericalApproximation::InterpType itype)
Initializes the object upon instantiation.
 
bool InsideDomain(const double a)
Returns whether the passed value is greater than or equal to the domain minimum and less than or equa...
 
bool p_dataValidated
Flag variable to determine whether ValidateDataSet() has been called.
 
void GslIntegrityCheck(int gsl_status, const char *src, int line)
Checks the status of the GSL interpolation operations.
 
void AddCubicHermiteDeriv(unsigned int n, double *fprimeOfx)
Adds values for the first derivatives of the data points.
 
const gsl_interp_type * InterpFunctor
GSL Interpolation specs.
 
void ComputeGsl()
Computes the GSL interpolation for a set of (x,y) data points.
 
string Name() const
Get name of interpolating function assigned to object.
 
map< InterpType, InterpFunctor > FunctorList
Set up a std::map of GSL interpolator functors. List of function types.
 
double RombergsMethod(double a, double b)
Uses Romberg's method to approximate the integral of the interpolated data set function on the interv...
 
InterpType
This enum defines the types of interpolation supported in this class.
 
@ CubicClamped
Cubic Spline interpolation with clamped boundary conditions.
 
@ CubicNatPeriodic
Cubic Spline interpolation with periodic boundary conditions.
 
@ Linear
Linear interpolation.
 
@ CubicHermite
Cubic Spline interpolation using the Hermite cubic polynomial.
 
@ CubicNeighborhood
Cubic Spline interpolation using 4-pt Neighborhoods with natural boundary conditions.
 
@ PolynomialNeville
Polynomial interpolation using Neville's algorithm.
 
@ CubicNatural
Cubic Spline interpolation with natural boundary conditions.
 
@ AkimaPeriodic
Non-rounded Akima Spline interpolation with periodic boundary conditions.
 
@ Polynomial
Polynomial interpolation.
 
@ Akima
Non-rounded Akima Spline interpolation with natural boundary conditions.
 
NumericalApproximation & operator=(const NumericalApproximation &numApMeth)
NumericalApproximation assigmment operator sets this object "equal to" another.
 
double TrapezoidalRule(const double a, const double b)
Uses the trapezoidal rule to approximate the integral of the interpolated data set function on the in...
 
double RefineExtendedTrap(double a, double b, double s, unsigned int n)
Calculates refinements extended trapezoidal rule to approximate the integral of the interpolated data...
 
double ValueToExtrapolate(const double a, const ExtrapType &etype)
Returns the domain value at which to evaluate.
 
double GslSecondDerivative(const double a)
Approximates the second derivative of the interpolated data set function evaluated at the given domai...
 
void ComputeCubicClamped()
Computes the cubic clamped interpolation for a set of (x,y) data points, given the first derivatives ...
 
bool Contains(double x)
Returns whether the passed value is an element of the set of x-values in the data set.
 
void SetInterpType(NumericalApproximation::InterpType itype)
Sets interpolation type.
 
double Simpsons4PointRule(const double a, const double b)
Uses Simpson's 4-point rule to approximate the integral of the interpolated data set function on the ...
 
double BackwardFirstDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point backward first difference formula to approximate the first derivative evaluated at a ...
 
double EvaluateCubicHermite(const double a)
Performs interpolation using the Hermite cubic polynomial.
 
bool GslComputed() const
Returns whether a GSL interpolation computation of the data set has been performed.
 
gsl_spline * p_interp
Currently active interpolator.
 
double GslIntegral(const double a, const double b)
Approximates the integral of the data set function evaluated on the given interval for GSL supported ...
 
void Reset()
Resets the state of the object.
 
FunctorList::const_iterator FunctorConstIter
GSL Iterator.
 
vector< double > p_clampedSecondDerivs
List of second derivatives evaluated at p_x values. This is only used for the CubicClamped interpolat...
 
bool p_clampedEndptsSet
Flag variable to determine whether SetCubicClampedEndptDeriv() has been called after all data was add...
 
NumericalApproximation(const NumericalApproximation::InterpType &itype=CubicNatural)
Default constructor creates NumericalApproximation object.
 
double CenterSecondDifference(const double a, const unsigned int n=5, const double h=0.1)
Uses an n point center second difference formula to approximate the second derivative evaluated at a ...
 
double p_clampedDerivFirstPt
First derivative of first x-value, p_x[0]. This is only used for the CubicClamped interpolation type.
 
InterpType p_itype
Interpolation type.
 
double EvaluateCubicHermiteSecDeriv(const double a)
Approximates the second derivative of the data set function evaluated at the given domain value for C...
 
double Simpsons3PointRule(const double a, const double b)
Uses Simpson's 3-point rule to approximate the integral of the interpolated data set function on the ...
 
static FunctorList p_interpFunctors
Maintains list of interpolator options.
 
double DomainMaximum()
Input data domain maximum value.
 
double EvaluateCubicClamped(const double a)
Performs cubic spline interpolation with clamped boundary conditions, if possible.
 
virtual ~NumericalApproximation()
Destructor deallocates memory being used.
 
double BackwardSecondDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point backward second difference formula to approximate the second derivative evaluated at ...
 
double ForwardFirstDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point forward first difference formula to approximate the first derivative evaluated at a g...
 
double BoolesRule(const double a, const double b)
Uses Boole's Rule to approximate the integral of the interpolated data set function on the interval (...
 
vector< double > p_polyNevError
Estimate of error for interpolation evaluated at x. This is only used for the PolynomialNeville inter...
 
double EvaluateCubicNeighborhood(const double a)
Performs cubic spline interpolation for a neighborhood about a.
 
double CenterFirstDifference(const double a, const unsigned int n=5, const double h=0.1)
Uses an n point center first difference formula to approximate the first derivative evaluated at a gi...
 
double EvaluateCubicHermiteFirstDeriv(const double a)
Approximates the first derivative of the data set function evaluated at the given domain value for Cu...
 
ExtrapType
This enum defines the manner in which a value outside of the domain should be handled if passed to th...
 
@ NearestEndpoint
Evaluate() returns the y-value of the nearest endpoint if a is outside of the domain.
 
@ ThrowError
Evaluate() throws an error if a is outside of the domain.
 
@ Extrapolate
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
 
unsigned int Size()
Returns the number of the coordinates added to the data set.
 
int MinPoints()
Minimum number of points required by interpolating function.
 
double ForwardSecondDifference(const double a, const unsigned int n=3, const double h=0.1)
Uses an n point forward second difference formula to approximate the second derivative evaluated at a...
 
vector< double > PolynomialNevilleErrorEstimate()
Retrieves the error estimate for the Neville's polynomial interpolation type.
 
vector< double > p_y
List of Y values.
 
void SetCubicClampedEndptDeriv(const double yp1, const double ypn)
Sets the values for the first derivatives of the endpoints of the data set.
 
void AddData(const double x, const double y)
Add a datapoint to the set.
 
vector< double > EvaluateForIntegration(const double a, const double b, const unsigned int n)
Evaluates data set in order to have enough data points to approximate the function to be integrated.
 
This is free and unencumbered software released into the public domain.
 
Namespace for the standard library.