summaryrefslogtreecommitdiff
path: root/lib/Numeric/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/Matrix.hs')
-rw-r--r--lib/Numeric/Matrix.hs53
1 files changed, 5 insertions, 48 deletions
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs
index 7bb79f3..bab5a27 100644
--- a/lib/Numeric/Matrix.hs
+++ b/lib/Numeric/Matrix.hs
@@ -15,40 +15,20 @@
15-- Stability : provisional 15-- Stability : provisional
16-- Portability : portable 16-- Portability : portable
17-- 17--
18-- Numeric instances and functions for 'Matrix'.
19-- In the context of the standard numeric operators, one-component
20-- vectors and matrices automatically expand to match the dimensions of the other operand.
21--
22-- Provides instances of standard classes 'Show', 'Read', 'Eq', 18-- Provides instances of standard classes 'Show', 'Read', 'Eq',
23-- 'Num', 'Fractional', and 'Floating' for 'Matrix'. 19-- 'Num', 'Fractional', and 'Floating' for 'Matrix'.
24-- 20--
21-- In arithmetic operations one-component
22-- vectors and matrices automatically expand to match the dimensions of the other operand.
23
25----------------------------------------------------------------------------- 24-----------------------------------------------------------------------------
26 25
27module Numeric.Matrix ( 26module Numeric.Matrix (
28 -- * Basic functions
29 module Data.Packed.Matrix,
30 module Numeric.Vector,
31 -- * Matrix creation
32 diag, ident,
33 -- * matrix operations
34 ctrans,
35 optimiseMult,
36 -- * Operators
37 (<>), (<\>),
38 -- * IO
39 dispf, disps, dispcf, vecdisp, latexFormat, format,
40 loadMatrix, saveMatrix, fromFile, fileDimensions,
41 readMatrix
42 ) where 27 ) where
43 28
44------------------------------------------------------------------- 29-------------------------------------------------------------------
45 30
46import Data.Packed.Matrix 31import Numeric.Container
47import Numeric.Vector
48import Numeric.Chain
49import Numeric.MatrixBoot
50import Numeric.IO
51import Numeric.LinearAlgebra.Algorithms
52 32
53------------------------------------------------------------------- 33-------------------------------------------------------------------
54 34
@@ -90,26 +70,3 @@ instance (Floating a, Container Vector a, Floating (Vector a), Fractional (Matri
90 (**) = liftMatrix2Auto (**) 70 (**) = liftMatrix2Auto (**)
91 sqrt = liftMatrix sqrt 71 sqrt = liftMatrix sqrt
92 pi = (1><1) [pi] 72 pi = (1><1) [pi]
93
94--------------------------------------------------------
95
96class Mul a b c | a b -> c where
97 infixl 7 <>
98 -- | Matrix-matrix, matrix-vector, and vector-matrix products.
99 (<>) :: Product t => a t -> b t -> c t
100
101instance Mul Matrix Matrix Matrix where
102 (<>) = mXm
103
104instance Mul Matrix Vector Vector where
105 (<>) m v = flatten $ m <> (asColumn v)
106
107instance Mul Vector Matrix Vector where
108 (<>) v m = flatten $ (asRow v) <> m
109
110--------------------------------------------------------
111
112-- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD).
113(<\>) :: (Field a) => Matrix a -> Vector a -> Vector a
114infixl 7 <\>
115m <\> v = flatten (linearSolveSVD m (reshape 1 v))