The functions described here perform various operations on vectors and matrices.

__Function:__ **math-concat** *x y*

Do a vector concatenation; this operation is written `` x | y'`
in a symbolic formula. See section Building Vectors.

__Function:__ **vec-length** *v*

Return the length of vector `v`. If `v` is not a vector, the
result is zero. If `v` is a matrix, this returns the number of
rows in the matrix.

__Function:__ **mat-dimens** *m*

Determine the dimensions of vector or matrix `m`. If `m` is not
a vector, the result is an empty list. If `m` is a plain vector
but not a matrix, the result is a one-element list containing the length
of the vector. If `m` is a matrix with `r` rows and `c` columns,
the result is the list ``( r c)'`. Higher-order tensors
produce lists of more than two dimensions. Note that the object

__Function:__ **dimension-error**

Abort the current function with a message of "Dimension error."
The Calculator will leave the function being evaluated in symbolic
form; this is really just a special case of `reject-arg`

.

__Function:__ **build-vector** *args*

Return a Calc vector with the zero-or-more `args` as elements.
For example, ``(build-vector 1 2 3)'` returns the Calc vector
``[1, 2, 3]'`, stored internally as the list ``(vec 1 2 3)'`.

__Function:__ **make-vec** *obj dims*

Return a Calc vector or matrix all of whose elements are equal to
`obj`. For example, ``(make-vec 27 3 4)'` returns a 3x4 matrix
filled with 27's.

__Function:__ **row-matrix** *v*

If `v` is a plain vector, convert it into a row matrix, i.e.,
a matrix whose single row is `v`. If `v` is already a matrix,
leave it alone.

__Function:__ **col-matrix** *v*

If `v` is a plain vector, convert it into a column matrix, i.e., a
matrix with each element of `v` as a separate row. If `v` is
already a matrix, leave it alone.

__Function:__ **map-vec** *f v*

Map the Lisp function `f` over the Calc vector `v`. For example,
``(map-vec 'math-floor v)'` returns a vector of the floored components
of vector `v`.

__Function:__ **map-vec-2** *f a b*

Map the Lisp function `f` over the two vectors `a` and `b`.
If `a` and `b` are vectors of equal length, the result is a
vector of the results of calling ``( f ai bi)'`
for each pair of elements

`defmath`

does not expand function names everywhere,
just where they are in the function position of a Lisp expression.
__Function:__ **reduce-vec** *f v*

Reduce the function `f` over the vector `v`. For example, if
`v` is ``[10, 20, 30, 40]'`, this calls ``(f (f (f 10 20) 30) 40)'`.
If `v` is a matrix, this reduces over the rows of `v`.

__Function:__ **reduce-cols** *f m*

Reduce the function `f` over the columns of matrix `m`. For
example, if `m` is ``[[1, 2], [3, 4], [5, 6]]'`, the result
is a vector of the two elements ``(f (f 1 3) 5)'` and ``(f (f 2 4) 6)'`.

__Function:__ **mat-row** *m n*

Return the `n`th row of matrix `m`. This is equivalent to
``(elt m n)'`. For a slower but safer version, use `mrow`

.
(See section Extracting Vector Elements.)

__Function:__ **mat-col** *m n*

Return the `n`th column of matrix `m`, in the form of a vector.
The arguments are not checked for correctness.

__Function:__ **mat-less-row** *m n*

Return a copy of matrix `m` with its `n`th row deleted. The
number `n` must be in range from 1 to the number of rows in `m`.

__Function:__ **mat-less-col** *m n*

Return a copy of matrix `m` with its `n`th column deleted.

__Function:__ **transpose** *m*

Return the transpose of matrix `m`.

__Function:__ **flatten-vector** *v*

Flatten nested vector `v` into a vector of scalars. For example,
if `v` is ``[[1, 2, 3], [4, 5]]'` the result is ``[1, 2, 3, 4, 5]'`.

__Function:__ **copy-matrix** *m*

If `m` is a matrix, return a copy of `m`. This maps
`copy-sequence`

over the rows of `m`; in Lisp terms, each
element of the result matrix will be `eq`

to the corresponding
element of `m`, but none of the `cons`

cells that make up
the structure of the matrix will be `eq`

. If `m` is a plain
vector, this is the same as `copy-sequence`

.

__Function:__ **swap-rows** *m r1 r2*

Exchange rows `r1` and `r2` of matrix `m` in-place. In
other words, unlike most of the other functions described here, this
function changes `m` itself rather than building up a new result
matrix. The return value is `m`, i.e., ``(eq (swap-rows m 1 2) m)'`
is true, with the side effect of exchanging the first two rows of
`m`.

Go to the first, previous, next, last section, table of contents.