module Numeric.Interpolation.Private.Piece where
sqr :: (Num a) => a -> a
sqr x = x*x
type T x y ny = (x, ny) -> (x, ny) -> x -> y
linear :: (Fractional a) => T a a a
linear (x0,y0) (x1,y1) x =
(y0*(x1x) + y1*(xx0)) / (x1x0)
hermite1 :: (Fractional a) => T a a (a, a)
hermite1 (x0,(y0,dy0)) (x1,(y1,dy1)) x =
let d = (y1y0)/(x1x0)
in linear (x0,y0) (x1,y1) x +
(dy0d) * sqr ((xx1)/(x0x1)) * (xx0) +
(dy1d) * sqr ((xx0)/(x1x0)) * (xx1)
hermite1' :: (Fractional a) => T a a (a, a)
hermite1' (x0,(y0,dy0)) (x1,(y1,dy1)) x =
let d = (y1y0)/(x1x0)
in d +
(dy0d) / sqr (x0x1) * (2*(xx1) * (xx0) + sqr (xx1)) +
(dy1d) / sqr (x1x0) * (2*(xx0) * (xx1) + sqr (xx0))
hermite1'' :: (Fractional a) => T a a (a, a)
hermite1'' (x0,(y0,dy0)) (x1,(y1,dy1)) x =
let d = (y1y0)/(x1x0)
in 2*(dy0d) / sqr (x0x1) * (3*x2*x1x0) +
2*(dy1d) / sqr (x1x0) * (3*x2*x0x1)