# Matrix Manipulation

ApplyOverMatrix
 `ApplyOverMatrix (a,func)`

Apply a function over all entries of a matrix and return a matrix of the results.

ApplyOverMatrix2
 `ApplyOverMatrix2 (a,b,func)`

Apply a function over all entries of 2 matrices (or 1 value and 1 matrix) and return a matrix of the results.

ColumnsOf
 `ColumnsOf (M)`

Gets the columns of a matrix as a horizontal vector.

ComplementSubmatrix
 `ComplementSubmatrix (m,r,c)`

Remove column(s) and row(s) from a matrix.

CompoundMatrix
 `CompoundMatrix (k,A)`

Calculate the kth compound matrix of A.

CountZeroColumns
 `CountZeroColumns (M)`

Count the number of zero columns in a matrix. For example Once you column reduce a matrix you can use this to find the nullity. See cref and Nullity.

DeleteColumn
 `DeleteColumn (M,col)`

Delete a column of a matrix.

DeleteRow
 `DeleteRow (M,row)`

Delete a row of a matrix.

DiagonalOf
 `DiagonalOf (M)`

Gets the diagonal entries of a matrix as a column vector.

DotProduct
 `DotProduct (u,v)`

Get the dot product of two vectors. The vectors must be of the same size. No conjugates are taken so this is a bilinear form even if working over the complex numbers.

ExpandMatrix
 `ExpandMatrix (M)`

Expands a matrix just like we do on unquoted matrix input. That is we expand any internal matrices as blocks. This is a way to construct matrices out of smaller ones and this is normally done automatically on input unless the matrix is quoted.

HermitianProduct
 `HermitianProduct (u,v)`

Aliases: InnerProduct

Get the Hermitian product of two vectors. The vectors must be of the same size. This is a sesquilinear form using the identity matrix.

I
 `I (n)`

Aliases: eye

Return an identity matrix of a given size, that is `n` by `n`. If `n` is zero, returns `null`.

IndexComplement
 `IndexComplement (vec,msize)`

Return the index complement of a vector of indexes. Everything is one based. For example for vector [2,3] and size 5, we return [1,4,5]. If `msize` is 0, we always return `null`.

IsDiagonal
 `IsDiagonal (M)`

Is a matrix diagonal.

IsIdentity
 `IsIdentity (x)`

Check if a matrix is the identity matrix. Automatically returns `false` if the matrix is not square. Also works on numbers, in which case it is equivalent to x==1. When `x` is `null` (we could think of that as a 0 by 0 matrix), no error is generated and `false` is returned.

IsLowerTriangular
 `IsLowerTriangular (M)`

Is a matrix lower triangular. That is, are all the entries above the diagonal zero.

IsMatrixInteger
 `IsMatrixInteger (M)`

Check if a matrix is a matrix of an integers (non-complex).

IsMatrixNonnegative
 `IsMatrixNonnegative (M)`

Check if a matrix is non-negative, that is if each element is non-negative. Do not confuse positive matrices with positive semi-definite matrices.

IsMatrixPositive
 `IsMatrixPositive (M)`

Check if a matrix is positive, that is if each element is positive (and hence real). In particular, no element is 0. Do not confuse positive matrices with positive definite matrices.

IsMatrixRational
 `IsMatrixRational (M)`

Check if a matrix is a matrix of rational (non-complex) numbers.

IsMatrixReal
 `IsMatrixReal (M)`

Check if a matrix is a matrix of real (non-complex) numbers.

IsMatrixSquare
 `IsMatrixSquare (M)`

Check if a matrix is square, that is its width is equal to its height.

IsUpperTriangular
 `IsUpperTriangular (M)`

Is a matrix upper triangular? That is, a matrix is upper triangular if all all the entries below the diagonal are zero.

IsValueOnly
 `IsValueOnly (M)`

Check if a matrix is a matrix of numbers only. Many internal functions make this check. Values can be any number including complex numbers.

IsVector
 `IsVector (v)`

Is argument a horizontal or a vertical vector. Genius does not distinguish between a matrix and a vector and a vector is just a 1 by `n` or `n` by 1 matrix.

IsZero
 `IsZero (x)`

Check if a matrix is composed of all zeros. Also works on numbers, in which case it is equivalent to x==0. When `x` is `null` (we could think of that as a 0 by 0 matrix), no error is generated and `true` is returned as the condition is vacuous.

LowerTriangular
 `LowerTriangular (M)`

Returns a copy of the matrix `M` with all the entries above the diagonal set to zero.

MakeDiagonal
 `MakeDiagonal (v,arg...)`

Aliases: diag

Make diagonal matrix from a vector.

MakeVector
 `MakeVector (A)`

Make column vector out of matrix by putting columns above each other. Returns `null` when given `null`.

MatrixProduct
 `MatrixProduct (A)`

Calculate the product of all elements in a matrix or vector. That is we multiply all the elements and return a number that is the product of all the elements.

MatrixSum
 `MatrixSum (A)`

Calculate the sum of all elements in a matrix or vector. That is we add all the elements and return a number that is the sum of all the elements.

MatrixSumSquares
 `MatrixSumSquares (A)`

Calculate the sum of squares of all elements in a matrix or vector.

OuterProduct
 `OuterProduct (u,v)`

Get the outer product of two vectors. That is, suppose that `u` and `v` are vertical vectors, then the outer product is v * u.'.

ReverseVector
 `ReverseVector (v)`

Reverse elements in a vector. Return `null` if given `null`

RowSum
 `RowSum (m)`

Calculate sum of each row in a matrix and return a vertical vector with the result.

RowSumSquares
 `RowSumSquares (m)`

Calculate sum of squares of each row in a matrix.

RowsOf
 `RowsOf (M)`

Gets the rows of a matrix as a vertical vector. Each element of the vector is a horizontal vector which is the corresponding row of `M`. This function is useful if you wish to loop over the rows of a matrix. For example, as for r in RowsOf(M) do something(r).

SetMatrixSize
 `SetMatrixSize (M,rows,columns)`

Make new matrix of given size from old one. That is, a new matrix will be returned to which the old one is copied. Entries that don't fit are clipped and extra space is filled with zeros. if `rows` or `columns` are zero then `null` is returned.

ShuffleVector
 `ShuffleVector (v)`

Shuffle elements in a vector. Return `null` if given `null`

SortVector
 `SortVector (v)`

Sort vector elements in an increasing order.

StripZeroColumns
 `StripZeroColumns (M)`

Removes any all-zero columns of `M`.

StripZeroRows
 `StripZeroRows (M)`

Removes any all-zero rows of `M`.

Submatrix
 `Submatrix (m,r,c)`

Return column(s) and row(s) from a matrix. This is just equivalent to m@(r,c). `r` and `c` should be vectors of rows and columns (or single numbers if only one row or column is needed).

SwapRows
 `SwapRows (m,row1,row2)`

Swap two rows in a matrix.

UpperTriangular
 `UpperTriangular (M)`

Returns a copy of the matrix `M` with all the entries below the diagonal set to zero.

columns
 `columns (M)`

Get the number of columns of a matrix.

elements
 `elements (M)`

Get the total number of elements of a matrix. This is the number of columns times the number of rows.

ones
 `ones (rows,columns...)`

Make an matrix of all ones (or a row vector if only one argument is given). Returns `null` if either rows or columns are zero.

rows
 `rows (M)`

Get the number of rows of a matrix.

zeros
 `zeros (rows,columns...)`

Make a matrix of all zeros (or a row vector if only one argument is given). Returns `null` if either rows or columns are zero.