Monotone cubic interpolation
   HOME

TheInfoList



OR:

In the
mathematical Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
field of
numerical analysis Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods ...
, 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 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 database tables, where every column of a table represents a particular variable, and each row corresponds to a given record of the ...
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 poi ...
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 correspondi ...
with the tangents m_i modified to ensure the monotonicity of the resulting Hermite spline. An algorithm is also available for monotone
quintic In algebra, a quintic function is a function of the form :g(x)=ax^5+bx^4+cx^3+dx^2+ex+f,\, where , , , , and are members of a field, typically the rational numbers, the real numbers or the complex numbers, and is nonzero. In other words, a ...
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 Secant is a term in mathematics derived from the Latin ''secare'' ("to cut"). It may refer to: * a secant line, in geometry * the secant variety, in algebraic geometry * secant (trigonometry) (Latin: secans), the multiplicative inverse (or recipr ...
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\text\beta_k > 3\,, then set m_k = 3 \, \delta_k\,.


Cubic interpolation

After the preprocessing above, evaluation of the interpolated spline is equivalent to
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 correspondi ...
, 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 correspondi ...
.


Example implementation

The following
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
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 fiv ...
, volume = 52 , number = 186 , pages = 471–494 , date = April 1989 , doi=10.2307/2008477 , doi-access = free


External links

* GPLv2 licensed
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
implementation
MonotCubicInterpolator.cppMonotCubicInterpolator.hpp
Interpolation Splines (mathematics) Articles with example JavaScript code