Version: 4.1.5.3
The simple-matrix Library
This library contains basic functions for manipulating matrices and
vectors. The functions come in two modules: "matrix-base.ss"
for manipulating two-dimensional collections of objects, and
"matrix.ss" for matipulating two-dimensional collections of
numbers. If you do not need the numerical operations on matrices
(matrix addition, multiplication, etc), use the
"matrix-base.ss" module; otherwise, use the
"matrix.ss" module. The "matrix.ss" module
re-exports all the definitions from "matrix-base.ss".
The functions provided from the "matrix-base.ss" library
include: iterators and looping constructs, getters and setters, and
matrix-transpose. The functions provided from the
"matrix.ss" library include: basic algebraic operations on
matrices (addition, subtraction, ...), matrix-matrix-multiplication,
matrix-vector multiplication, etc. The library does not include any
functions from traditional linear algebra (such as solving linear
equations, finding eigenvalues, etc). The library comes with an
initial module language, "matrix-lang.ss", which re-defines
the standard scheme functions +, -, *,
/ to operate on numbers, vectors and matrices, and
re-provides all of 'scheme and "matrix.ss" as well.
Use this module language when you are more concerned with clarity than
speed – basic arithmetic operations on scalars will no longer be
inlined, and performance will suffer.
This library is released under the GNU GPL v3; see the
License section for details.
1 The "matrix-base.ss" Module
A matrix with the given dimensions. The elts are stored in
row-major order.
Constructs a matrix from the given elt ..., in row-major
order.
(matrix-ref m i j) → matrix? |
m : matrix? |
|
|
Get the i, j entry in m.
(matrix-set! m i j x) → any |
m : matrix? |
|
|
x : number? |
Set the i, j entry in m to x.
(matrix-transpose m) |
→ (matrix-of-dimensions/c (matrix-cols m) (matrix-rows m)) |
m : matrix? |
The transpose of m.
1.1 Contracts
Contract for matrices which can be multiplied on the left my
m.
(matrix-mul-result/c m1 m2) → flat-contract? |
m1 : matrix? |
m2 : matrix? |
1.2 Iteration Forms
The "matrix-base.ss" library provides many iteration forms
which make manipulating vectors and matrices much more convenient.
This subsection documents these forms.
Sequence enumerating the elements of m, in row-major order.
Can also be used as a fast for-clause, as in either
(which collects all the elements of m in a list), or
which collects a list of row, column, element lists.
(for/vector length-expr (for-clause ...) body) |
(for*/vector length-expr (for-clause ...) body) |
Creates a vector of length length-expr, filled with the
successive values of body.
(for/matrix row-expr col-expr (for-clause ...) body) |
(for*/matrix row-expr col-expr (for-clause ...) body) |
Creates a matrix of dimensions row-expr by col-expr,
whose elements are the successive values of body, in
row-major order.
2 The "matrix.ss" Module
The "matrix.ss" module re-exports all the definitions from
the "matrix-base.ss" module, in addition to the following
definitions.
The n by n identity matrix.
2.1 Basic Arithmetic
The "matrix.ss" library provides functions to perform basic
arithmetic on vectors and matrices.
Adds together, elementwise, v1, and v2. If you use
the "matrix-lang.ss" module, this operation is represented by
(+ v1 v2).
Subtracts v1 from v2. Also (- v1 v2) in
"matrix-lang.ss".
Scales v by the scalar s. (* v s),
(* s v), or (/ v (/ s)) in
"matrix-lang.ss".
Dot product of v1 and v2. (* v1 v2) in
"matrix-lang.ss".
(matrix-add m1 m2) → (matrix-same-dimensions/c m1) |
m1 : matrix? |
m2 : (matrix-same-dimensions/c m1) |
Elementwise sum of m1 and m2. (+ m1 m2) in
"matrix-lang.ss".
(matrix-sub m1 m2) → (matrix-same-dimensions/c m1) |
m1 : matrix? |
m2 : (matrix-same-dimensions/c m1) |
Elementwise difference of m1 and m2. (- m1 m2) in "matrix-lang.ss".
(matrix-scale m s) → (matrix-same-dimensions/c m) |
m : matrix? |
s : number? |
Scales m by the scalar s. (* m s),
(* s m), or (/ m (/ s)) in
"matrix-lang.ss".
2.2 Matrix-vector and
Matrix-matrix Operations
(matrix-vector-mul m v) |
|
m : matrix? |
|
Basic left multiplication by a matrix. Also (* m v) in
"matrix-lang.ss".
Basic right multiplication by a matrix. Also (* v m) in
"matrix-lang.ss".
(matrix-mul m1 m2) → (matrix-mul-result/c m1 m2) |
m1 : matrix? |
m2 : (matrix-mul-compatible/c m1) |
Matrix-matrix multiplication. Also (* m1 m2) in
"matrix-lang.ss".
3 License
This software is released under the GNU General Public License,
version 3. You can find a copy of the GPL as
"gpl-3.0-standalone.html" in the root directory of this
PLaneT package, or on
the web.