source: trunk/yat/regression/GSLInterpolation.h @ 1648

Last change on this file since 1648 was 1648, checked in by Jari Häkkinen, 12 years ago

Addresses #466. Added more GSL functionality, added constructor tests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1#ifndef _theplu_yat_regression_gslinterpolation_
2#define _theplu_yat_regression_gslinterpolation_
3
4// $Id: GSLInterpolation.h 1648 2008-12-13 09:28:39Z jari $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include <gsl/gsl_interp.h>
26
27namespace theplu {
28namespace yat {
29namespace utility {
30  class VectorBase;
31}
32namespace regression {
33
34  /**
35     \brief Base class for interfacing GSL interpolation.
36
37     The GSL interpolation is descibed in
38     http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html. The
39     GSL library provides a variety of interpolation methods,
40     including Cubic splines and Akima splines. Interpolations can be
41     defined for both normal and periodic boundary
42     conditions. Additional functions are available for computing
43     derivatives and integrals of interpolating functions.
44
45     Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$
46     the sub classescompute a continuous interpolating function \f$
47     y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is
48     piecewise smooth, and its behavior at the end-points is
49     determined by the type of interpolation used.
50  */
51  class GSLInterpolation
52  {
53
54  public:
55    /**
56       \brief Search index.
57
58       This function returns the index \f$ i \f$ of the array \a
59       x_array such that \f$ x_array[i] <= x < x_array[i+1] \f$. The
60       index is searched for in the range
61       \f$ [index_lo, index_hi] \f$.
62    */
63    size_t bsearch(const double x_array[], double x, size_t index_lo,
64                   size_t index_hi) const;
65
66    /**
67       \brief Calculate the interpolated value for \a x.
68
69       \return The interpolated value of \f$ y \f$ for a given point
70       \a x.
71    */
72    double evaluate(double x);
73
74    /**
75       \brief Calculate the derivative of the interpolated function at
76       \a x.
77
78       \return The derivative.
79    */
80    double evaluate_derivative(double x);
81
82    /**
83       \brief Calculate the 2nd derivative of the interpolated
84       function at \a x.
85
86       \return The 2nd derivative.
87    */
88    double evaluate_derivative2(double x);
89
90    /**
91       \brief Calculate the numerical integral of the interpolated
92       function over the range \f$ [a,b] \f$.
93
94       \return The integral.
95    */
96    double evaluate_integral(double a, double b);
97
98    /**
99       \brief This function returns the minimum number of points
100       required by the interpolation type.
101
102       For example, Akima spline interpolation requires a minimum of 5
103       points.
104
105       \return The minimum number of points required.
106    */
107    unsigned int min_size(void) const;
108
109  protected:
110    /**
111       \brief The default constructor
112
113       Initializion of the interpolation object for the data \f$ (x,
114       y) \f$ where \a x and \a y are vector like objects of the same
115       size. The content of \a x and \a y are copied for internal
116       storage. \a x is always assumed to be strictly ordered, with
117       increasing \a x values; the behavior for other arrangements is
118       not defined.
119    */
120    GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x,
121                     const utility::VectorBase& y);
122
123    /**
124       \brief The destructor
125    */
126    virtual ~GSLInterpolation(void);
127
128  private:
129    /**
130       \brief Copy Constructor. (not implemented)
131    */
132    GSLInterpolation(const GSLInterpolation&);
133
134    gsl_interp_accel* accelerator_;
135    gsl_interp* interpolator_;
136    double* x_;
137    double* y_;
138  };
139
140}}} // of namespaces regression, yat, and theplu
141
142#endif
Note: See TracBrowser for help on using the repository browser.