packages feed

cubicspline (empty) → 0.1

raw patch · 4 files changed

+84/−0 lines, 4 filesdep +basedep +hmatrixdep +safesetup-changed

Dependencies added: base, hmatrix, safe

Files

+ Data/Algorithm/CubicSpline.hs view
@@ -0,0 +1,34 @@+module Data.Algorithm.CubicSpline(cubicSplineCoefficients) where+import Prelude hiding (tail, init, head, last, minimum, maximum, foldr1, foldl1, (!!), read)+import Control.Arrow+import Numeric.LinearAlgebra+import Data.List(unfoldr)+import Safe++type PolyCos = [Double]++-- | Given a list of (x,y) co-ordinates, produces a list of coefficients to cubic equations, with knots at each of the initially provided x co-ordinates. Natural cubic spline interpololation is used. See: <http://en.wikipedia.org/wiki/Spline_interpolation#Interpolation_using_natural_cubic_spline>.+cubicSplineCoefficients :: [(Double, Double)] -> [PolyCos]+cubicSplineCoefficients xs = chunkBy 4 . concat . toLists $ linearSolve matrix solution+    where+      (matrix,solution) = (fromLists *** trans . fromLists . (:[])) .+                           unzip . map (first fillOut) . (extraConditions ++) . initNote "cubicSpline" . initNote "cubicSpline" . concat .+                           zipWith (map . first . (++)) (iterate (++[0,0,0,0]) []) $+                           map genEquations (xs `zip` drop 1 xs)++      genEquations :: ((Double, Double),(Double,Double)) -> [(PolyCos, Double)]+      genEquations ((x,y),(x',y')) = [ (zipWith (^) (repeat x)  ([0..3]::[Int]) , y)+                                      ,(zipWith (^) (repeat x') ([0..3]::[Int]) , y')+                                      ,(deriv1 ++ map negate deriv1     , 0)+                                      ,(deriv2 ++ map negate deriv2     , 0)]+              where deriv1 = [0, 1, 2*x', 3*x'^(2::Int)]+                    deriv2 = [0, 0, 2   , 6*x']+      extraConditions = [ ([0, 0, 2, 6 * fst (headNote "cubicSpline" xs)], 0)+                        , (replicate (fullLen - 4) 0 ++ [0, 0, 2, 6 * fst (lastNote "cubicSpline" xs)], 0)]+      fillOut = take fullLen . (++ repeat 0)+      fullLen = 4 * (length xs - 1)++chunkBy :: Int -> [t] -> [[t]]+chunkBy n = unfoldr go+    where go [] = Nothing+          go x  = Just $ splitAt n x
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) Gershom Bazerman 2010++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.+3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cubicspline.cabal view
@@ -0,0 +1,21 @@+name:                cubicspline+version:             0.1+synopsis:            Natural cubic spline interpolation.+description:         Natural cubic spline interpolation.+category:            algorithms, math+license:             BSD3+license-file:        LICENSE+author:              Gershom Bazerman+maintainer:          gershomb@gmail.com+Tested-With:         GHC == 6.10.3+Build-Type:          Simple+Cabal-Version:       >= 1.6++library+  build-depends:     base >= 4, base < 5, hmatrix, safe+  exposed-modules:   Data.Algorithm.CubicSpline+  ghc-options:       -Wall++source-repository head+  type:      darcs+  location:  http://patch-tag.com/r/gershomb/cubicspline