Simple Matrix Arithmetic
| (require simple-matrix) | package: simple-matrix |
1 Introduction
This library is used to perform some simple matrix arithmetic like multiplication, transposition, addition, and inversion. It is truly "simple" and very naive in its implementation but it will do its job without much overhead from typed racket.
Matrices are represented as lists of rows, which are lists of numbers. So a 3x3 identity matrix would look like '((1 0 0) (0 1 0) (0 0 1)).
1.1 Exact Numbers
The library is intended to be used with exact numbers: integers and rationals. determinant and invert-matrix decide whether a matrix is singular by testing for an exact zero, with no tolerance. With floating-point entries, rounding can make a singular matrix look invertible, so invert-matrix may return a matrix of huge entries instead of #f. Floating-point numbers still work for well-behaved matrices, but nothing checks the results.
> (column '(1 2 -2)) '((1) (2) (-2))
2 Arithmetic
> (matrix+ '((1 2) (3 4)) '((10 20) (30 40)) '((100 200) (300 400))) '((111 222) (333 444))
procedure
(matrix-expt m e) → matrix?
m : matrix? e : exact-nonnegative-integer?
procedure
(determinant m) → number?
m : matrix?
3 Utilities
procedure
(invert-matrix m) → (or/c matrix? #f)
m : matrix?
> (invert-matrix '((2 1) (1 3))) '((3/5 -1/5) (-1/5 2/5))
> (invert-matrix '((1 2) (2 4))) #f