Portability | portable |
---|---|
Stability | experimental |
Maintainer | lennart...schmitt@<nospam>gmail.com |
This module includes a few (standard) functions to work with matrixes.
- data Matrix t
- type RawMatrix a = [[a]]
- class Storable a => Element a
- flatten :: Element t => Matrix t -> Vector t
- toColumns :: Element t => Matrix t -> [Vector t]
- toLists :: Element t => Matrix t -> [[t]]
- toRows :: Element t => Matrix t -> [Vector t]
- asRow :: Storable a => Vector a -> Matrix a
- fromLists :: Element t => [[t]] -> Matrix t
- fromListToQuadraticMatrix :: [Double] -> Matrix Double
- (@@>) :: Storable t => Matrix t -> (Int, Int) -> t
- eigenvalue :: Matrix Double -> Double
- eigenvector :: Matrix Double -> Vector Double
- inv :: Field t => Matrix t -> Matrix t
- identityMatrix :: Int -> Matrix Double
- mapMatrix :: (Double -> Double) -> Matrix Double -> Matrix Double
- reduceMatrix :: Matrix Double -> Matrix Double
- scalarMultiplication :: Double -> Matrix Double -> Matrix Double
- subtractMatrix :: Matrix Double -> Matrix Double -> Matrix Double
- trans :: Matrix t -> Matrix t
- zipAllWith :: (RawVector a -> b) -> RawMatrix a -> RawVector b
Data Types
data Matrix t
Matrix representation suitable for GSL and LAPACK computations.
The elements are stored in a continuous memory array.
Joinable Matrix Matrix | |
Joinable Matrix Vector | |
Joinable Vector Matrix | |
Normed Matrix Double | |
Normed Matrix Float | |
Container Vector a => Container Matrix a | |
Normed Matrix (Complex Double) | |
Normed Matrix (Complex Float) | |
(Element a, Read a) => Read (Matrix a) | |
(Show a, Element a) => Show (Matrix a) | |
(Binary a, Element a, Storable a) => Binary (Matrix a) |
Represents a matrix
Supported matrix elements.
This class provides optimized internal
operations for selected element types.
It provides unoptimised defaults for any Storable
type,
so you can create instances simply as:
instance Element Foo
.
The elements of a matrix
Convert a Matrix into another Type
flatten :: Element t => Matrix t -> Vector t
Creates a vector by concatenation of rows
> flatten (ident
3)
9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]
Flattens a matrix to a vector
toColumns :: Element t => Matrix t -> [Vector t]
Creates a list of vectors from the columns of a matrix
Converts the representation of a matrix to a list of vectors by its columns.
Converts the representation of a matrix to a list of lists. (NOT equivalent with toRows!!!)
Converts the representation of a matrix to a list of vectors by its rows.
Convert some Data into Matrix-Type
Converts the representation of a matrix from a list of vectors to a matrix (by rows)
fromLists :: Element t => [[t]] -> Matrix t
Creates a Matrix
from a list of lists (considered as rows).
> fromLists [[1,2],[3,4],[5,6]] (3><2) [ 1.0, 2.0 , 3.0, 4.0 , 5.0, 6.0 ]
Converts the representation of a matrix from a list of lists to a matrix (NOT equivalent with asRows!!!)
fromListToQuadraticMatrix :: [Double] -> Matrix DoubleSource
Builds a quadratic matrix out of a list
Matrix calculations/transformations
Get the matrix-element in row x and col y (like (!!) for lists)
eigenvalue :: Matrix Double -> DoubleSource
Calculates the eigenvalue of a matrix, e.g.
eigenvalue (fromLists [[0.77143,-0.25714],[-0.42245,0.14082]])
returns
0.9122456375784809
eigenvector :: Matrix Double -> Vector DoubleSource
Calculates one eigenvector of a given matrix, e.g.
eigenvector (fromLists [[-0.14081563757848092,-0.25714],[-0.42245,-0.7714256375784809]])
returns
[0.8770950095147589,-0.48031692067249215]
Calculates the invariant matrix of the input matrix
identityMatrix :: Int -> Matrix DoubleSource
Calculates the identity matrix (n x n) by given scale (n)
mapMatrix :: (Double -> Double) -> Matrix Double -> Matrix DoubleSource
A simple map-Function which maps a given function on every element of the given matrix
reduceMatrix :: Matrix Double -> Matrix DoubleSource
Calculates the reduced matrix of a given matrix (by reducing the given matrix), e.g.
reduceMatrix (fromLists [[0.77143,-0.25714],[-0.42245,0.14082]])
returns
(2><2)[ -0.14081563757848092,-0.25714,-0.42245,-0.7714256375784809]
scalarMultiplication :: Double -> Matrix Double -> Matrix DoubleSource
Calculates the scalarproduct (with a scalar and matrix)
subtractMatrix :: Matrix Double -> Matrix Double -> Matrix DoubleSource
Calculates the difference (matrix) between two matrixes
Transposes a matrix
zipAllWith :: (RawVector a -> b) -> RawMatrix a -> RawVector bSource
Zipps a matrix col by col
zipAllWith sum [[1,2,3],[1,2,3],[1,2,3]] == [3,6,9]