Module

Data.Sparse.Matrix

#Matrix

newtype Matrix a

Representation of a matrix without storage of the zero coefficients.

> -- Working with Sparse Matrices
> import Data.Sparse.Matrix
> -- Define a matrix with sum of terms (see Data.Sparse.Polynomial)
> a = Matrix {height:3, width:2, coefficients: 5.0^2^0+7.0^0^1}
> a
 0.0 7.0
 0.0 0.0
 5.0 0.0

> -- Modify all the non-zero elements with the functor
> b = (_ + 2.0) <$> a
> b
 0.0 9.0
 0.0 0.0
 7.0 0.0

> -- Set a specific element
> c = 2.0^1^0 ~ b
> c
 0.0 9.0
 2.0 0.0
 7.0 0.0

> -- Inspect a specific location
> c??[1,0]
2.0

> -- transpose, multiply
> d = a * transpose c
> d
 63.0 0.0 0.0
 0.0 0.0 0.0
 0.0 10.0 35.0

> -- Weight a specific element
> e = 0.5^0^0 ~* d
> e
 31.5 0.0 0.0
 0.0 0.0 0.0
 0.0 10.0 35.0


> -- Increment a specific element
> f = 4.0^1^1 ~+ e
> f
 31.5 0.0 0.0
 0.0 4.0 0.0
 0.0 10.0 35.0

> -- Identity, subtraction
> g = f - eye 3
> g
 30.5 0.0 0.0
 0.0 3.0 0.0
 0.0 10.0 34.0

> -- Vectors are just column matrices
> v = Matrix {height:3, width:1, coefficients: 1.0^0^0+2.0^1^0+3.0^2^0}
> v
 1.0
 2.0
 3.0

> -- Solve the linear system
> luSolve g v
 0.03278688524590164
 0.6666666666666666
 -0.1078431372549019

Constructors

Instances

#Poly2

#Square

type Square a = Matrix a

#Symmetric

#Vector

type Vector a = Matrix a

#applyPoly

applyPoly :: forall a. Eq a => Semiring a => Polynomial (Square a) -> Square a -> Square a

Polynomial application

#determinant

determinant :: forall a. Eq a => Semiring a => Ring a => EuclideanRing a => Square a -> a

Determinant of a square matrix

#diagonalize

diagonalize :: Symmetric -> { val :: Symmetric, vec :: Square Number }

Square real matrix diagonalization such that m = vec * val * recip vec

#eigenValues

eigenValues :: Square Number -> Array (Cartesian Number)

Eigen vlaues of a real square matrix

#extract

extract :: forall a. Eq a => Semiring a => Matrix a -> Array Int -> a

Coefficient extraction

#eye

eye :: forall a. Eq a => Semiring a => Int -> Square a

Identity matrix

#faddeev

faddeev :: Square Number -> Polynomial Number

Characteristic polynomial of a real square matrix

#height

height :: forall a. Matrix a -> Int

#increment

increment :: forall a. Eq a => Semiring a => Ring a => Poly2 a -> Matrix a -> Matrix a

Element increment

#internalMap

internalMap :: forall a. Polynomial a -> Map Int a

Returns the polynomial internal structure

#lu

lu :: forall a. Eq a => Semiring a => Ring a => EuclideanRing a => Square a -> { l :: Square a, u :: Square a }

Returns the 2 square matrices L and U such that

  • LU = A where A is a square matrix
  • L is triangular inferior with unitary diagonal elements
  • U is triangular superior

#luSolve

luSolve :: forall a. Eq a => Semiring a => Ring a => EuclideanRing a => Square a -> Matrix a -> Matrix a

Solves the system Ax=B for x, for A square inversible and any B

#monoPol

monoPol :: forall a. a -> Int -> Polynomial a

Imported from Data.Sparse.Polynomial

#parseMonom

parseMonom :: forall a. Eq a => Semiring a => Poly2 a -> Maybe { i :: Int, j :: Int, v :: a }

#pow

pow :: forall a. Eq a => Semiring a => Square a -> Int -> Square a

Integer power of a square matrix

#replace

replace :: forall a. Eq a => Semiring a => Ring a => Poly2 a -> Matrix a -> Matrix a

Element replacement

#scale

scale :: forall a. Eq a => Semiring a => Ring a => EuclideanRing a => Poly2 a -> Matrix a -> Matrix a

Element weighting

#trace

trace :: forall a. Eq a => Semiring a => Matrix a -> a

#transpose

transpose :: forall a. Eq a => Semiring a => Ring a => Matrix a -> Matrix a

Matrix transposition

#width

width :: forall a. Matrix a -> Int

#zeros

zeros :: forall a. Eq a => Semiring a => Int -> Int -> Matrix a

Zero matrix

#(??)

Operator alias for Data.Sparse.Matrix.extract (left-associative / precedence 8)

Coefficient extraction infix notation

#(^)

Operator alias for Data.Sparse.Matrix.monoPol (left-associative / precedence 8)

#(~)

Operator alias for Data.Sparse.Matrix.replace (non-associative / precedence 7)

Element replacement infix notation

#(~*)

Operator alias for Data.Sparse.Matrix.scale (non-associative / precedence 7)

Element weighting infix notation

#(~+)

Operator alias for Data.Sparse.Matrix.increment (non-associative / precedence 7)

Element increment infix notation

Modules