Deconvolution/1D: Difference between revisions

→‎{{header|Haskell}}: Fixed a compilation error (GHC 8.02), removed redundant import, applied hlint, hindent
(→‎{{header|Go}}: add new solution using gonum library)
(→‎{{header|Haskell}}: Fixed a compilation error (GHC 8.02), removed redundant import, applied hlint, hindent)
Line 575:
 
=={{header|Haskell}}==
<lang haskell>importdeconv1d Data.List:: [Double] -> [Double] -> [Double]
deconv1d xs ys = takeWhile (/= 0) $ deconv xs ys
where
where [] `deconv` _ = []
(0:xs) `deconv` (0:ys) = xs `deconv` ys
(x:xs) `deconv` (y:ys) =
wherelet q = x / y</lang>
in q : zipWith (-) xs (scale q ys ++ repeat 0) `deconv` (y : ys)
 
h, f, gscale :: Double -> [Double] -> [Double]
scale x ys = map . (x*) ys
h = [-8,-9,-3,-1,-6,7]
f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]
g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7]
 
h, f, g :: [Double]
scale x ys = map (x*) ys
h = [-8, -9, -3, -1, -6, 7]
 
f = [-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1]
deconv1d :: (Fractional a) => [a] -> [a] -> [a]
deconv1d xs ys = takeWhile (/=0) $ deconv xs ys
where [] `deconv` _ = []
(0:xs) `deconv` (0:ys) = xs `deconv` ys
(x:xs) `deconv` (y:ys) =
q : zipWith (-) xs (scale q ys ++ repeat 0) `deconv` (y:ys)
where q = x / y</lang>
 
g =
Check:
[ 24
<lang haskell>*Main> h == deconv1d g f
, 75
True
, 71
, -34
, 3
, 22
, -45
, 23
, 245
, 25
, 52
, 25
, -67
, -96
, 96
, 31
, 55
, 36
, 29
, -43
, -7
]
 
main :: IO ()
*Main> f == deconv1d g h
main = print $ (h == deconv1d g f) && (f == deconv1d g h)</lang>
True</lang>
{{Out}}
<pre>True</langpre>
 
=={{header|J}}==
9,655

edits