]>
Book Contents Previous Section 1.5 Data Structures Next Section 1.7 Writing Your Own Functions Book Index

## 1.6 Expanding to Higher Dimensions

To get higher dimensional aggregates, you can create one-dimensional aggregates with elements that are themselves aggregates, for example, lists of lists, one-dimensional arrays of lists of multisets, and so on. For applications requiring two-dimensional homogeneous aggregates, you will likely find two-dimensional arrays matrix and matrices most useful. array:two-dimensional

The entries in TwoDimensionalArray and Matrix objects are all the same type, except that those for Matrix must belong to a Ring. You create and access elements in roughly the same way. Since matrices have an understood algebraic structure, certain algebraic operations are available for matrices but not for arrays. Because of this, we limit our discussion here to Matrix, that can be regarded as an extension of TwoDimensionalArray. See TwoDimensionalArray for more information about arrays. For more information about Axiom's linear algebra facilities, see Matrix, Permanent, SquareMatrix, Vector, see Section ugProblemEigen (computation of eigenvalues and eigenvectors), and Section ugProblemLinPolEqn (solution of linear and polynomial equations).

You can create a matrix from a list of lists, matrix:creating where each of the inner lists represents a row of the matrix.

m := matrix([ [1,2], [3,4] ])

[1 2 3 4]

Type: Matrix Integer

The ``collections'' construct (see ugLangIts) is useful for creating matrices whose entries are given by formulas. matrix:Hilbert

matrix([ [1/(i + j - x) for i in 1..4] for j in 1..4])

[-1 x-2-1 x-3-1 x-4-1 x-5-1 x-3-1 x-4-1 x-5-1 x-6-1 x-4-1 x-5-1 x-6-1 x-7-1 x-5-1 x-6-1 x-7-1 x-8]

Type: Matrix Fraction Polynomial Integer

Let vm denote the three by three Vandermonde matrix.

vm := matrix [ [1,1,1], [x,y,z], [x*x,y*y,z*z] ]

[1 1 1 x y z x 2 y 2 z 2]

Type: Matrix Polynomial Integer

Use this syntax to extract an entry in the matrix.

vm(3,3)

z 2

Type: Polynomial Integer

You can also pull out a row or a column.

column(vm,2)

[1,y,y 2]

Type: Vector Polynomial Integer

You can do arithmetic.

vm * vm

[x 2+x+1 y 2+y+1 z 2+z+1 x 2 z+x y+x y 2 z+y 2+x z 3+y z+x x 2 z 2+x y 2+x 2 y 2 z 2+y 3+x 2 z 4+y 2 z+x 2]

Type: Matrix Polynomial Integer

You can perform operations such as transpose, trace, and determinant.

factor determinant vm

(y-x)(z-y)(z-x)

Type: Factored Polynomial Integer
Book Contents Previous Section 1.5 Data Structures Next Section 1.7 Writing Your Own Functions Book Index