-- | Matrix multiplication.
mtimes :: Num a => (Matrix a) -> (Matrix a) -> (Matrix a)
-mtimes m1@(Matrix rows1) m2@(Matrix rows2) =
+mtimes m1 m2 =
Matrix (V.fromList rows)
where
- row i = V.fromList [ sum [ (m1 ! (i,k)) * (m2 ! (k,j)) | k <- [0..(ncols m1)-1] ]
- | j <- [0..(ncols m2)-1] ]
+ row i =
+ V.fromList [ sum [ (m1 ! (i,k)) * (m2 ! (k,j)) | k <- [0..(ncols m1)-1] ]
+ | j <- [0..(ncols m2)-1] ]
rows = [row i | i <- [0..(nrows m1)-1]]
-- | Is @m@ symmetric?
construct imax jmax lambda =
Matrix rows
where
- row i = V.fromList [ lambda i j | j <- [0..jmax] ]
+ row i = V.fromList [ lambda i j | j <- [0..jmax] ]
rows = V.fromList [ row i | i <- [0..imax] ]
-- | Given a positive-definite matrix @m@, computes the
construct (nrows m - 1) (ncols m - 1) r
where
r :: Int -> Int -> a
- r i j | i > j = 0
- | i == j = sqrt(m ! (i,j) - sum [(r k i)**2 | k <- [0..i-1]])
- | i < j = (((m ! (i,j)) - sum [(r k i)*(r k j) | k <- [0..i-1]]))/(r i i)
+ r i j | i == j = sqrt(m ! (i,j) - sum [(r k i)**2 | k <- [0..i-1]])
+ | i < j =
+ (((m ! (i,j)) - sum [(r k i)*(r k j) | k <- [0..i-1]]))/(r i i)
+ | otherwise = 0
-- | It's not correct to use Num here, but I really don't want to have
-- to define my own addition and subtraction.
signum _ = error "signum of matrices is undefined"
- fromInteger x = error "fromInteger of matrices is undefined"
+ fromInteger _ = error "fromInteger of matrices is undefined"