interpolation-0.1.1.2: piecewise linear and cubic Hermite interpolation
Safe HaskellSafe-Inferred
LanguageHaskell98

Numeric.Interpolation.Piecewise

Synopsis

Documentation

interpolate :: Ord x => T x y ny -> T x ny -> x -> y Source #

It is a checked error to interpolate outside of the range of nodes.

>>> Piecewise.interpolate Type.linear (Nodes.fromList [(0,0),(3,6),(5,10::Rational)]) 2
4 % 1
>>> Piecewise.interpolate Type.hermite1 (Nodes.fromList [(0,(0,0)),(3,(9,6)),(5,(25,10::Rational))]) 2
4 % 1
>>> Piecewise.interpolate Type.hermite1 (Nodes.fromList [(0,(1,-2)),(3,(4,4)),(5,(16,8::Rational))]) 2
1 % 1

interpolateConstantExt :: Ord x => T x y ny -> T x ny -> x -> y Source #

Outside the range of nodes the interpolation function takes the value of the respective border.

forAllSortedRatios $ checkEq Type.linear
forAllSortedRatios $ checkEq Type.hermite1
forAllSortedRatios $ \nodeXs x -> lengthAtLeast 4 nodeXs ==> checkEq Type.cubicLinear nodeXs x
forAllSortedRatios $ \nodeXs x -> lengthAtLeast 4 nodeXs ==> checkEq Type.cubicParabola nodeXs x

Linear interpolation can be used to compute the median, a quartile or any other quantile of a list of arbitrary numbers.

>>> quantile [2,5,3::Rational] 0.5
3 % 1
>>> quantile [2,5,3,7::Rational] 0.5
4 % 1
>>> quantile [2,5,3,7::Rational] 0.25
11 % 4
\(QC.NonEmpty xs) -> quantile (xs::[Rational]) 0 == minimum xs
\(QC.NonEmpty xs) -> quantile (xs::[Rational]) 1 == maximum xs