For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs
0.1. Determinant (import (slib determinant))
This library is a little misnamed. Apart from determinants, it also provides a range of functions on single and pairs of matrices.
All the functions take either a SRFI-63 array or a list of lists as the matrix definition.
0.1.1. determinant
determinant
returns the determinant of a given matrix.
sash[r7rs]> (determinant '((1 2) (3 4))) -2
0.1.2. matrix→array
matrix→array
returns a SRFI-63 array from given matrix
definition (e.g. list-of-lists):
sash[r7rs]> (matrix->array '((1 2) (3 4))) #<<array> 0x2a6a400>
0.1.3. matrix→lists
matrix→lists
converts a given matrix definition into a list of lists:
sash[r7rs]> (matrix->lists (matrix->array '((1 2) (3 4)))) ((1 2) (3 4)) sash[r7rs]> (matrix->lists '((1 2) (3 4))) ((1 2) (3 4))
0.1.4. matrix:difference
matrix:difference
takes two matrices of numbers and
returns their element-wise difference. If the matrices are not of equal dimension,
returns a matrix of the smallest size.
sash[r7rs]> (matrix:difference '((1 2) (3 4)) '((5 6) (7 8))) ((-4 -4) (-4 -4)) sash[r7rs]> (matrix:difference '((1 2) (3 4)) '((5 6 7) (8 9 10))) ((-4 -4) (-5 -5))
0.1.5. matrix:inverse
matrix:inverse
returns the inverse of a given square matrix. If the
matrix is singular, the function returns #f
.
sash[r7rs]> (matrix:inverse '((1 2) (3 4))) ((-2 1) (3/2 -1/2)) sash[r7rs]> (matrix:inverse '((0 0) (0 0))) #f
0.1.6. matrix:product
matrix:product
takes two arguments, at least one of which must be
a matrix. If the other argument is a scalar, returns the element-wise product
of the scalar with the matrix. If the other argument is a matrix, returns the
matrix product.
sash[r7rs]> (matrix:product '((1 2) (3 4)) '((5 6) (7 8))) ((19 22) (43 50)) sash[r7rs]> (matrix:product '((1 2) (3 4)) 2) ((2 4) (6 8)) sash[r7rs]> (matrix:product 2 '((1 2) (3 4))) ((2 4) (6 8))
0.1.7. matrix:sum
matrix:sum
takes two matrices of numbers and
returns their element-wise sum. If the matrices are not of equal dimension,
returns a matrix of the smallest size.
sash[r7rs]> (matrix:sum '((1 2) (3 4)) '((5 6) (7 8))) ((6 8) (10 12)) sash[r7rs]> (matrix:sum '((1 2 3) (4 5 6)) '((7 8) (9 10))) ((8 10) (13 15))
0.1.8. transpose
transpose
returns a copy of the given matrix with
entries flipped about the diagonal.
sash[r7rs]> (transpose '((1 2 3) (4 5 6) (7 8 9))) ((1 4 7) (2 5 8) (3 6 9))