From: Michael Orlitzky Date: Wed, 5 Feb 2014 20:30:26 +0000 (-0500) Subject: Rename zipcol to colzip. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=4b7a8137a75e9fe186d1eb8976f7a47e82afc12b;p=numerical-analysis.git Rename zipcol to colzip. Add a new function, colzipwith. --- diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index 7c0f84a..dd89a9f 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -91,6 +91,11 @@ type Col3 a = Col N3 a type Col4 a = Col N4 a type Col5 a = Col N5 a +-- We need a big column for Gaussian quadrature. +type N10 = S (S (S (S (S N5)))) +type Col10 a = Col N10 a + + instance (Eq a) => Eq (Mat m n a) where -- | Compare a row at a time. -- @@ -775,16 +780,36 @@ trace matrix = -- -- >>> let m1 = fromList [[1],[1],[1]] :: Col3 Int -- >>> let m2 = fromList [[1],[2],[3]] :: Col3 Int --- >>> zipcol m1 m2 +-- >>> colzip m1 m2 -- (((1,1)),((1,2)),((1,3))) -- -zipcol :: Arity m => Col m a -> Col m a -> Col m (a,a) -zipcol c1 c2 = +colzip :: Arity m => Col m a -> Col m a -> Col m (a,a) +colzip c1 c2 = construct lambda where lambda i j = (c1 !!! (i,j), c2 !!! (i,j)) +-- | Zip together two column matrices using the supplied function. +-- +-- Examples: +-- +-- >>> let c1 = fromList [[1],[2],[3]] :: Col3 Integer +-- >>> let c2 = fromList [[4],[5],[6]] :: Col3 Integer +-- >>> colzipwith (^) c1 c2 +-- ((1),(32),(729)) +-- +colzipwith :: Arity m + => (a -> a -> b) + -> Col m a + -> Col m a + -> Col m b +colzipwith f c1 c2 = + construct lambda + where + lambda i j = f (c1 !!! (i,j)) (c2 !!! (i,j)) + + -- | Map a function over a matrix of any dimensions. -- -- Examples: