module Numeric.Interpolation.Private.Basis where
import Numeric.Interpolation.Private.Piece (sqr)
import qualified Data.List.Match as Match
hermite1Split :: [a] -> [b] -> [(b, b)]
hermite1Split xs = uncurry zip . Match.splitAt xs
parabolaDerivative ::
(Fractional a) => (a,a) -> (a,a) -> (a,a) -> a -> (a,a)
parabolaDerivative (x0,y0) (x1,y1) (x2,y2) x =
let l0 = (xx1)*(xx2)/((x0x1)*(x0x2))
l1 = (xx0)*(xx2)/((x1x0)*(x1x2))
l2 = (xx0)*(xx1)/((x2x0)*(x2x1))
dl0 = (2*xx1x2)/((x0x1)*(x0x2))
dl1 = (2*xx0x2)/((x1x0)*(x1x2))
dl2 = (2*xx0x1)/((x2x0)*(x2x1))
in (y0*l0 + y1*l1 + y2*l2, y0*dl0 + y1*dl1 + y2*dl2)
parabolaBasisDerivativeLeft,
parabolaBasisDerivativeCenter,
parabolaBasisDerivativeRight ::
(Fractional a) => a -> a -> a -> a
parabolaBasisDerivativeLeft x0 x1 x2 = (x1x2)/((x0x1)*(x0x2))
parabolaBasisDerivativeCenter x0 x1 x2 = 1/(x1x0) + 1/(x1x2)
parabolaBasisDerivativeRight x0 x1 x2 = (x1x0)/((x2x0)*(x2x1))
parabolaDerivativeCenterNode ::
(Fractional a) => (a,a) -> (a,a) -> (a,a) -> a
parabolaDerivativeCenterNode (x0,y0) (x1,y1) (x2,y2) =
y0 * parabolaBasisDerivativeLeft x0 x1 x2 +
y1 * parabolaBasisDerivativeCenter x0 x1 x2 +
y2 * parabolaBasisDerivativeRight x0 x1 x2
parabola2ndDerivativeCenterNode ::
(Fractional a) => (a,a) -> (a,a) -> (a,a) -> (a,a) -> a
parabola2ndDerivativeCenterNode (xl,yl) (x0,y0) (x1,y1) (x2,y2) =
let dy0 =
yl * (x0x1)/((xlx0)*(xlx1)) +
y0 * (1/(x0xl) + 1/(x0x1)) +
y1 * (x0xl)/((x1xl)*(x1x0))
dy1 =
y0 * (x1x2)/((x0x1)*(x0x2)) +
y1 * (1/(x1x0) + 1/(x1x2)) +
y2 * (x1x0)/((x2x0)*(x2x1))
d = (y1y0)/(x1x0)
x = x0
in 2*(dy0d) / sqr (x0x1) * (3*x2*x1x0) +
2*(dy1d) / sqr (x1x0) * (3*x2*x0x1)