HOME

TheInfoList



OR:

In the
mathematical Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
field of
numerical analysis Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic computation, symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of ...
, monotone cubic interpolation is a variant of
cubic interpolation In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the correspondin ...
that preserves
monotonicity In mathematics, a monotonic function (or monotone function) is a function between ordered sets that preserves or reverses the given order. This concept first arose in calculus, and was later generalized to the more abstract setting of orde ...
of the
data set A data set (or dataset) is a collection of data. In the case of tabular data, a data set corresponds to one or more table (database), database tables, where every column (database), column of a table represents a particular Variable (computer sci ...
being interpolated. Monotonicity is preserved by
linear interpolation In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points. Linear interpolation between two known points If the two known po ...
but not guaranteed by
cubic interpolation In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the correspondin ...
.


Monotone cubic Hermite interpolation

Monotone interpolation can be accomplished using
cubic Hermite spline In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the correspondin ...
with the tangents m_i modified to ensure the monotonicity of the resulting Hermite spline. An algorithm is also available for monotone quintic Hermite interpolation.


Interpolant selection

There are several ways of selecting interpolating tangents for each data point. This section will outline the use of the Fritsch–Carlson method. Note that only one pass of the algorithm is required. Let the data points be (x_k,y_k) indexed in sorted order for k=1,\,\dots\,n. # Compute the slopes of the
secant line In geometry, a secant is a line (geometry), line that intersects a curve at a minimum of two distinct Point (geometry), points.. The word ''secant'' comes from the Latin word ''secare'', meaning ''to cut''. In the case of a circle, a secant inter ...
s between successive points:
\delta_k =\frac
for k=1,\,\dots\,n-1.

# These assignments are provisional, and may be superseded in the remaining steps. Initialize the tangents at every interior data point as the average of the secants,
m_k = \frac
for k=2,\,\dots\,n-1.

For the endpoints, use one-sided differences:
m_1 = \delta_1 \quad \text \quad m_n = \delta_\,.
If \delta_ and \delta_k have opposite signs, set m_k = 0 .

# For k=1,\,\dots\,n-1, where ever \delta_k = 0 (where ever two successive y_k=y_ are equal),
set m_k = m_ = 0, as the spline connecting these points must be flat to preserve monotonicity.
Ignore steps 4 and 5 for those k\,.

# Let
\alpha_k = m_k/\delta_k \quad \text \quad \beta_k = m_/\delta_k.
If either \alpha_k or \beta_k is negative, then the input data points are not strictly monotone, and (x_k,\,y_k) is a local extremum. In such cases, ''piecewise'' monotone curves can still be generated by choosing m_=0\, if \alpha_k < 0 or m_=0\, if \beta_k < 0, although strict monotonicity is not possible globally.

# To prevent overshoot and ensure monotonicity, at least one of the following three conditions must be met: ::(a) the function
\phi_k = \alpha_k - \frac > 0\,, or
::(b) \alpha_k + 2\beta_k - 3 \le 0\,, or ::(c) 2\alpha_k + \beta_k - 3 \le 0\,.
::Only condition (a) is sufficient to ensure strict monotonicity: \phi_k must be positive.

::One simple way to satisfy this constraint is to restrict the vector (\alpha_k,\,\beta_k) to a circle of radius 3. That is, if \alpha_k^2 + \beta_k^2 > 9\,, then set
\tau_k = \frac\,,
and rescale the tangents via
m_k = \tau_k\, \alpha_k \,\delta_k \quad \text \quad m_ = \tau_k\, \beta_k\, \delta_k\,.
::Alternatively it is sufficient to restrict \alpha_k \le 3 and \beta_k \le 3\,. To accomplish this, if \alpha_k > 3\,, then set m_k = 3 \, \delta_k\,, and if \beta_k > 3\,, then set m_ = 3 \, \delta_k\,.


Cubic interpolation

After the preprocessing above, evaluation of the interpolated spline is equivalent to a
cubic Hermite spline In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the correspondin ...
, using the data x_k, y_k, and m_k for k=1,\,\dots\,n. To evaluate at x, find the index k in the sequence where x, lies between x_k, and x_, that is: x_k \leq x \leq x_. Calculate :\Delta = x_-x_k \quad \text \quad t = \frac then the interpolated value is :f_\text(x) = y_k\cdot h_(t) + \Delta\cdot m_k\cdot h_(t) + y_\cdot h_(t) + \Delta\cdot m_\cdot h_(t) where h_ are the basis functions for the
cubic Hermite spline In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the correspondin ...
.


Example implementation

The following
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
implementation takes a data set and produces a monotone cubic spline interpolant function: /* * Monotone cubic spline interpolation * Usage example listed at bottom; this is a fully-functional package. For * example, this can be executed either at sites like * https://www.programiz.com/javascript/online-compiler/ * or using nodeJS. */ function DEBUG(s) var j = 0; var createInterpolant = function(xs, ys) ; /* Usage example below will approximate x^2 for 0 <= x <= 4. Command line usage example (requires installation of nodejs): node monotone-cubic-spline.js */ var X = , 1, 2, 3, 4 var F = , 1, 4, 9, 16 var f = createInterpolant(X,F); var N = X.length; console.log("# BLOCK 0 :: Data for monotone-cubic-spline.js"); console.log("X" + "\t" + "F"); for (var i = 0; i < N; i += 1) console.log(" "); console.log(" "); console.log("# BLOCK 1 :: Interpolated data for monotone-cubic-spline.js"); console.log(" x " + "\t\t" + " P(x) " + "\t\t" + " dP(x)/dx "); var message = ''; var M = 25; for (var i = 0; i <= M; i += 1) console.log(message);


References

* *{{cite journal , last = Dougherty , first = R.L. , author2=Edelman, A. , author3=Hyman, J.M. , title = Positivity-, monotonicity-, or convexity-preserving cubic and quintic Hermite interpolation , journal =
Mathematics of Computation ''Mathematics of Computation'' is a bimonthly mathematics journal focused on computational mathematics. It was established in 1943 as ''Mathematical Tables and Other Aids to Computation'', obtaining its current name in 1960. Articles older than f ...
, volume = 52 , number = 186 , pages = 471–494 , date = April 1989 , doi=10.2307/2008477 , doi-access = free , jstor = 2008477


External links

* GPLv2 licensed C++ implementation
MonotCubicInterpolator.cppMonotCubicInterpolator.hpp
Interpolation Splines (mathematics) Articles with example JavaScript code