- Source: Monotone cubic interpolation
In the mathematical field of numerical analysis, monotone cubic interpolation is a variant of cubic interpolation that preserves monotonicity of the data set being interpolated.
Monotonicity is preserved by linear interpolation but not guaranteed by cubic interpolation.
Monotone cubic Hermite interpolation
Monotone interpolation can be accomplished using cubic Hermite spline with the tangents
m
i
{\displaystyle 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
)
{\displaystyle (x_{k},y_{k})}
indexed in sorted order for
k
=
1
,
…
n
{\displaystyle k=1,\,\dots \,n}
.
Compute the slopes of the secant lines between successive points:
δ
k
=
y
k
+
1
−
y
k
x
k
+
1
−
x
k
{\displaystyle \delta _{k}={\frac {y_{k+1}-y_{k}}{x_{k+1}-x_{k}}}}
for
k
=
1
,
…
n
−
1
{\displaystyle 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
=
δ
k
−
1
+
δ
k
2
{\displaystyle m_{k}={\frac {\delta _{k-1}+\delta _{k}}{2}}}
for
k
=
2
,
…
n
−
1
{\displaystyle k=2,\,\dots \,n-1}
.For the endpoints, use one-sided differences:
m
1
=
δ
1
and
m
n
=
δ
n
−
1
{\displaystyle m_{1}=\delta _{1}\quad {\text{ and }}\quad m_{n}=\delta _{n-1}\,}
.If
δ
k
−
1
{\displaystyle \delta _{k-1}}
and
δ
k
{\displaystyle \delta _{k}}
have opposite signs, set
m
k
=
0
{\displaystyle m_{k}=0}
.
For
k
=
1
,
…
n
−
1
{\displaystyle k=1,\,\dots \,n-1}
, where ever
δ
k
=
0
{\displaystyle \delta _{k}=0}
(where ever two successive
y
k
=
y
k
+
1
{\displaystyle y_{k}=y_{k+1}}
are equal),set
m
k
=
m
k
+
1
=
0
,
{\displaystyle m_{k}=m_{k+1}=0,}
as the spline connecting these points must be flat to preserve monotonicity.Ignore steps 4 and 5 for those
k
{\displaystyle k\,}
.
Let
α
k
=
m
k
/
δ
k
and
β
k
=
m
k
+
1
/
δ
k
{\displaystyle \alpha _{k}=m_{k}/\delta _{k}\quad {\text{ and }}\quad \beta _{k}=m_{k+1}/\delta _{k}}
.If either
α
k
{\displaystyle \alpha _{k}}
or
β
k
{\displaystyle \beta _{k}}
is negative, then the input data points are not strictly monotone, and
(
x
k
,
y
k
)
{\displaystyle (x_{k},\,y_{k})}
is a local extremum. In such cases, piecewise monotone curves can still be generated by choosing
m
k
=
0
{\displaystyle m_{k}=0\,}
if
α
k
<
0
{\displaystyle \alpha _{k}<0}
or
m
k
+
1
=
0
{\displaystyle m_{k+1}=0\,}
if
β
k
<
0
{\displaystyle \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
ϕ
k
=
α
k
−
(
2
α
k
+
β
k
−
3
)
2
3
(
α
k
+
β
k
−
2
)
>
0
{\displaystyle \phi _{k}=\alpha _{k}-{\frac {(2\alpha _{k}+\beta _{k}-3)^{2}}{3(\alpha _{k}+\beta _{k}-2)}}>0\,}
, or
(b)
α
k
+
2
β
k
−
3
≤
0
{\displaystyle \alpha _{k}+2\beta _{k}-3\leq 0\,}
, or
(c)
2
α
k
+
β
k
−
3
≤
0
{\displaystyle 2\alpha _{k}+\beta _{k}-3\leq 0\,}
.
Only condition (a) is sufficient to ensure strict monotonicity:
ϕ
k
{\displaystyle \phi _{k}}
must be positive.
One simple way to satisfy this constraint is to restrict the vector
(
α
k
,
β
k
)
{\displaystyle (\alpha _{k},\,\beta _{k})}
to a circle of radius 3. That is, if
α
k
2
+
β
k
2
>
9
{\displaystyle \alpha _{k}^{2}+\beta _{k}^{2}>9\,}
, then set
τ
k
=
3
α
k
2
+
β
k
2
{\displaystyle \tau _{k}={\frac {3}{\sqrt {\alpha _{k}^{2}+\beta _{k}^{2}}}}\,}
, and rescale the tangents via
m
k
=
τ
k
α
k
δ
k
and
m
k
+
1
=
τ
k
β
k
δ
k
{\displaystyle m_{k}=\tau _{k}\,\alpha _{k}\,\delta _{k}\quad {\text{ and }}\quad m_{k+1}=\tau _{k}\,\beta _{k}\,\delta _{k}\,}
.
Alternatively it is sufficient to restrict
α
k
≤
3
{\displaystyle \alpha _{k}\leq 3}
and
β
k
≤
3
{\displaystyle \beta _{k}\leq 3\,}
. To accomplish this, if
α
k
>
3
{\displaystyle \alpha _{k}>3\,}
, then set
m
k
=
3
δ
k
{\displaystyle m_{k}=3\,\delta _{k}\,}
, and if
β
k
>
3
{\displaystyle \beta _{k}>3\,}
, then set
m
k
+
1
=
3
δ
k
{\displaystyle m_{k+1}=3\,\delta _{k}\,}
.
= Cubic interpolation
=After the preprocessing above, evaluation of the interpolated spline is equivalent to cubic Hermite spline, using the data
x
k
{\displaystyle x_{k}}
,
y
k
{\displaystyle y_{k}}
, and
m
k
{\displaystyle m_{k}}
for
k
=
1
,
…
n
{\displaystyle k=1,\,\dots \,n}
.
To evaluate at
x
{\displaystyle x}
, find the index
k
{\displaystyle k}
in the sequence where
x
{\displaystyle x}
, lies between
x
k
{\displaystyle x_{k}}
, and
x
k
+
1
{\displaystyle x_{k+1}}
, that is:
x
k
≤
x
≤
x
k
+
1
{\displaystyle x_{k}\leq x\leq x_{k+1}}
. Calculate
Δ
=
x
k
+
1
−
x
k
and
t
=
x
−
x
k
Δ
{\displaystyle \Delta =x_{k+1}-x_{k}\quad {\text{ and }}\quad t={\frac {x-x_{k}}{\Delta }}}
then the interpolated value is
f
interpolated
(
x
)
=
y
k
⋅
h
00
(
t
)
+
Δ
⋅
m
k
⋅
h
10
(
t
)
+
y
k
+
1
⋅
h
01
(
t
)
+
Δ
⋅
m
k
+
1
⋅
h
11
(
t
)
{\displaystyle f_{\text{interpolated}}(x)=y_{k}\cdot h_{00}(t)+\Delta \cdot m_{k}\cdot h_{10}(t)+y_{k+1}\cdot h_{01}(t)+\Delta \cdot m_{k+1}\cdot h_{11}(t)}
where
h
i
i
{\displaystyle h_{ii}}
are the basis functions for the cubic Hermite spline.
Example implementation
The following JavaScript implementation takes a data set and produces a monotone cubic spline interpolant function:
References
Fritsch, F. N.; Carlson, R. E. (1980). "Monotone Piecewise Cubic Interpolation". SIAM Journal on Numerical Analysis. 17 (2). SIAM: 238–246. doi:10.1137/0717021.
Dougherty, R.L.; Edelman, A.; Hyman, J.M. (April 1989). "Positivity-, monotonicity-, or convexity-preserving cubic and quintic Hermite interpolation". Mathematics of Computation. 52 (186): 471–494. doi:10.2307/2008477.
External links
GPLv2 licensed C++ implementation: MonotCubicInterpolator.cpp MonotCubicInterpolator.hpp
Kata Kunci Pencarian:
- Monotone cubic interpolation
- Cubic Hermite spline
- Spline interpolation
- Monotonic function
- List of numerical analysis topics
- List of algorithms
- Percentile
- Double descent
- Time series
- Interquartile range