qlinear-0.1.0.0: Typesafe library for linear algebra

Safe HaskellNone
LanguageHaskell2010

QLinear.Operations

Synopsis

Documentation

length :: (Real a, Floating b) => Vector n a -> b Source #

Length of vector

>>> length [vector| 3 4 |]
5.0
>>> length [vector| 1 1 |]
1.4142135623730951

mulMatricesWith Source #

Arguments

:: (a -> b -> c)

operation "*"

-> ([c] -> d)

operation `"+"`. "Summarizes" elements of list

-> Matrix m n a 
-> Matrix n k b 
-> Matrix m k d 

Generalized matrices multiplication

neg :: Num a => Matrix m n a -> Matrix m n a Source #

Nagates all elements of matrix

>>> neg [matrix| 1 2 3 |]
[-1,-2,-3]

transpose :: Matrix m n a -> Matrix n m a Source #

Transposes matrix

>>> transpose [matrix| 1 2 3; 4 5 6 |]
[1,4]
[2,5]
[3,6]

zipMatricesWith Source #

Arguments

:: (a -> b -> c)

operation "+"

-> Matrix m n a 
-> Matrix m n b 
-> Matrix m n c 

Generalized matrices addition

det :: Num a => Matrix n n a -> a Source #

Determinant of matrix

>>> det [matrix| 1 0; 0 1|]
1
>>> det [matrix| 1 3; 4 2|]
-10

algebraicComplement :: forall n a i j. (KnownNat i, KnownNat j, KnownNat n, Num a, i <= n, j <= n) => Matrix n n a -> Index i j -> a Source #

Typesafe algebraic complement

To use it you have to know i and j at compile time

>>> algebraicComplement [matrix| 1 2; 3 4 |] (Index @1 @1)
4
>>> algebraicComplement [matrix| 1 2 3; 4 5 6; 7 8 9 |] (Index @1 @1)
-3

algebraicComplement' :: Num a => Matrix n n a -> (Int, Int) -> Maybe a Source #

Algebraic complement.

Use it if you don't know indices at compile time

>>> algebraicComplement' [matrix| 1 2; 3 4 |] (1, 1)
Just 4
>>> algebraicComplement' [matrix| 1 2; 3 4 |] (34, 43)
Nothing
>>> algebraicComplement' [matrix| 1 2 3; 4 5 6; 7 8 9 |] (1, 1)
Just (-3)

adjugate :: Num a => Matrix n n a -> Matrix n n a Source #

Adjugate matrix

>>> adjugate [matrix| 1 2; 3 4|]
[4,-2]
[-3,1]

inverted :: forall a b n. (Fractional b, Eq a, Real a) => Matrix n n a -> Maybe (Matrix n n b) Source #

Inverted matrix

>>> inverted [matrix| 1 2; 3 4|]
Just [-2.0,1.0]
     [1.5,-0.5]
>>> inverted [matrix| 1 4; 1 4|]
Nothing

(*~) Source #

Arguments

:: Num a 
=> a

k

-> Matrix m n a

m

-> Matrix m n a 

Multuplies all elements of matrix m by k

>>> 5 *~ [matrix| 1 2 3; 4 5 6 |]
[5,10,15]
[20,25,30]

(~*~) :: Num a => Matrix m n a -> Matrix n k a -> Matrix m k a Source #

Multiplies two matrix

>>> [matrix| 1 2; 3 4 |] ~*~ [matrix| 1; 2 |]
[5]
[11]

(~+) :: Num a => Matrix m n a -> a -> Matrix m n a Source #

Adds a to all elements of matrix m

>>> [matrix| 1 2 3 |] ~+ 8
[9,10,11]

(+~) :: Num a => a -> Matrix m n a -> Matrix m n a Source #

Flipped ~+ :)

(~+~) :: Num a => Matrix m n a -> Matrix m n a -> Matrix m n a Source #

Adds two matrices

>>> [matrix| 1 2 |] ~+~ [matrix| 2 3 |]
[3,5]

(~-~) :: Num a => Matrix m n a -> Matrix m n a -> Matrix m n a Source #

Substracts second matrix from first one

>>> [matrix| 1 2 3 |] ~-~ [matrix| 3 2 1 |]
[-2,0,2]