Next: , Previous: Infinities, Up: Data Types

5.6 Vectors and Matrices

The vector data type is flexible and general. A vector is simply a list of zero or more data objects. When these objects are numbers, the whole is a vector in the mathematical sense. When these objects are themselves vectors of equal (nonzero) length, the whole is a matrix. A vector which is not a matrix is referred to here as a plain vector.

A vector is displayed as a list of values separated by commas and enclosed in square brackets: ‘[1, 2, 3]’. Thus the following is a 2 row by 3 column matrix: ‘[[1, 2, 3], [4, 5, 6]]’. Vectors, like complex numbers, are entered as incomplete objects. See Incomplete Objects. During algebraic entry, vectors are entered all at once in the usual brackets-and-commas form. Matrices may be entered algebraically as nested vectors, or using the shortcut notation ‘[1, 2, 3; 4, 5, 6], with rows separated by semicolons. The commas may usually be omitted when entering vectors: ‘[1 2 3]’. Curly braces may be used in place of brackets: ‘{1, 2, 3}’, but the commas are required in this case.

Traditional vector and matrix arithmetic is also supported; see Basic Arithmetic and see Matrix Functions. Many other operations are applied to vectors element-wise. For example, the complex conjugate of a vector is a vector of the complex conjugates of its elements.

Algebraic functions for building vectors include ‘vec(a, b, c)’ to build ‘[a, b, c]’, ‘cvec(a, n, m)’ to build an nxm matrix of ‘a’s, and ‘index(n)’ to build a vector of integers from 1 to ‘n’.