[Haskell-cafe] HMatrix Vector/Matrix interpolation ala Matlab interp/interp2 ??

gutti philipp.guttenberg at gmx.net
Tue Jan 25 22:05:34 CET 2011



Hi, 

I created some code from scratch - probably "ugly" beginners style - so I'm
keen to get 
tips how to make it more pretty and faster

Cheers Phil

import Data.List

-- Input Data
xi :: [Double]
xi = [0 .. 10]
yi :: [Double]
yi = [2, 3, 5, 6, 7, 8, 9, 10 , 9, 8, 7]	
x = 11 :: Double

-- Functions
limIndex xi idx 
    | idx < 0 = 0
    | idx > (length xi)-2 = (length xi)-2
    | otherwise = idx 				

getIndex xi x = limIndex xi (maybe (length xi) id (findIndex (>x) xi)-1)

getPnts xi yi idx = [xi !! idx, xi !! (idx+1), yi !! idx, yi !! (idx+1)]

interp xi yi x = 
	let pts = getPnts xi yi (getIndex xi x) 		
	in (pts!!3-pts!!2)/(pts!!1-pts!!0)*(x-pts!!0)+pts!!2

-- Calc 
y = interp xi yi x

main = do 
	-- Output Data
    	print (y)



 
-- 
View this message in context: http://haskell.1045720.n5.nabble.com/HMatrix-Vector-Matrix-interpolation-ala-Matlab-interp-interp2-tp3352833p3356966.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list