Vectors and matrices

These are plain numerical containers, with no lattice and no color: they carry the output of reductions, the contents of AFF and QIO records, and the small dense linear algebra a script does on the side.

vector

A vector is a fixed-length, mutable, one-dimensional array. Indexing is from zero, #v is the length, and writing past the end raises.

vector.int

vector.int(n)                                     --> vector.int

vector.real

vector.real(n)                                    --> vector.real

vector.complex

vector.complex(n)                                 --> vector.complex
local v = vector.real(4)
v[0] = 1.5
print(#v, v[0])                                   --> 4  1.5

matrix

A matrix is a dense two-dimensional array of reals or complexes, with the linear algebra GSL provides. Indexing is m[{i,j}], from zero.

matrix.real

matrix.real{rows, cols}                           --> matrix.real
matrix.real(m)                                    --> matrix.real

matrix.complex

matrix.complex{rows, cols}                        --> matrix.complex
matrix.complex(m)                                 --> matrix.complex

Both kinds have:

MethodMeaning
m:dims()two numbers: rows, columns
m:transpose()the transpose
m:trace()the trace
m:det()the determinant
m:inverse()the inverse
m:solve(b)solves m x = b
m:qr()the QR decomposition, as two matrices

A matrix.real additionally has m:symmetric_eigen(), and a matrix.complex has m:conj(), m:adjoin() and m:hermitian_eigen(). Both eigen solvers return the eigenvalues and the matrix of eigenvectors.

Matrices add, subtract and multiply with each other and scale by a number; matrix.complex scales by a complex as well.