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>
deconv1d xs ys = takeWhile (/= 0) $ deconv xs ys▼
where
h = [-8,-9,-3,-1,-6,7]▼
f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]▼
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 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 =
[ 24
, 75
, 71
, -34
, 3
, 22
, -45
, 23
, 245
, 25
, 52
, 25
, -67
, -96
, 96
, 31
, 55
, 36
, 29
, -43
, -7
]
main :: IO ()
main = print $ (h == deconv1d g f) && (f == deconv1d g h)</lang>
True</lang>▼
{{Out}}
=={{header|J}}==
|