interpolation-0.0: src/Numeric/Interpolation/Basis.hs
module Numeric.Interpolation.Basis (
Compact.linear,
Compact.hermite1,
Compact.cubicLinear,
Compact.cubicParabola,
coefficientsToLinear,
coefficientsToHermite1,
coefficientsToCubicLinear,
coefficientsToCubicParabola,
) where
import qualified Numeric.Interpolation.Basis.Compact as Compact
import qualified Numeric.Interpolation.NodeList as Nodes
import Numeric.Interpolation.Private.Basis
(parabolaDerivativeCenterNode, hermite1Split)
import qualified Data.List as List
{- |
@coefficientsToLinear nodes coefficients@
creates an interpolation function for @nodes@,
where the @coefficients@ correspond to the basis functions
constructed with @Basis.linear nodes@.
-}
coefficientsToLinear :: [a] -> [b] -> Nodes.T a b
coefficientsToLinear xs = Nodes.fromList . zip xs
{- |
Cf. 'coefficientsToLinear'
-}
coefficientsToHermite1 :: [a] -> [b] -> Nodes.T a (b, b)
coefficientsToHermite1 xs =
Nodes.fromList . zip xs . hermite1Split xs
mapAdjacent3 :: (a -> a -> a -> b) -> [a] -> [b]
mapAdjacent3 f xs0 =
let xs1 = drop 1 xs0
xs2 = drop 1 xs1
in List.zipWith3 f xs0 xs1 xs2
{- |
Cf. 'coefficientsToLinear'
-}
coefficientsToCubicLinear :: (Fractional a) => [a] -> [a] -> Nodes.T a (a, a)
coefficientsToCubicLinear xs =
Nodes.fromList .
mapAdjacent3 (\(xl,yl) (xn,yn) (xr,yr) -> (xn, (yn, (yr-yl)/(xr-xl)))) .
zip xs
{- |
Cf. 'coefficientsToLinear'
-}
coefficientsToCubicParabola :: (Fractional a) => [a] -> [a] -> Nodes.T a (a, a)
coefficientsToCubicParabola xs =
Nodes.fromList .
mapAdjacent3
(\pl pn@(xn,yn) pr ->
(xn, (yn, parabolaDerivativeCenterNode pl pn pr))) .
zip xs