MatrixSymbol(name, n, m) is a symbolic n by m matrix. Identity(n),
ZeroMatrix(m, n) and OneMatrix(m, n) are the special matrices. +,
-, * and ^ build the canonical MatAdd, MatMul and MatPow
(like terms combine, identities and zeros simplify, shapes are checked
and mismatches raise a ShapeError). t() transposes and distributes;
Transpose(), Inverse() and Adjoint() build unevaluated nodes
(A^-1 is Inverse(A)). Trace(), Determinant() and Permanent()
are scalar functions of a matrix; doit() applies their rules. MatrixElement(A, i, j)
is the entry with SymPy's zero based indices. as_explicit() turns an
expression with integer shape into an explicit Matrix().
mat_shape() gives the shape and matrix_symbols() the matrix symbols.
Usage
MatrixSymbol(name, n, m)
Identity(n)
ZeroMatrix(n, m)
OneMatrix(n, m)
mat_shape(e)
MatMul(..., evaluate = FALSE)
MatAdd(..., evaluate = FALSE)
MatPow(A, k)
Transpose(A)
Inverse(A)
Adjoint(A)
Trace(A)
Determinant(A)
Permanent(A)
HadamardProduct(..., evaluate = FALSE)
HadamardPower(A, k)
KroneckerProduct(...)
MatrixElement(A, i, j)
FunctionMatrix(n, m, f)
DiagMatrix(A)
diagonalize_vector(A)
DiagonalOf(A)
DiagonalMatrix(A)
PermutationMatrix(perm)
MatrixPermute(A, perm, axis = 0)
DotProduct(A, B)
MatrixSlice(A, rowslice, colslice)
blockcut(A, rowsizes, colsizes)
BlockMatrix(blocks)
BlockDiagMatrix(...)
block_collapse(e)
matrix_symbols(e)
as_explicit(e)Arguments
- name
The name.
- n, m
Dimensions.
- e, A, B
A matrix expression.
- ...
Matrices, or for
MatMul()matrices and scalars.- evaluate
If
TRUE,MatAdd()andMatMul()put their arguments in canonical form, asdoit()does; by default they keep them as given, as in SymPy. AMatMul()of scalars only is their product.- k
An exponent.
- i, j
Zero based indices.
- f
A
Lambda()of two variables giving the entries.- perm
A
Permutation()or a vector of zero based images.- axis
0 to permute rows, 1 for columns.
- rowslice, colslice
A zero based index,
c(start, stop)orc(start, stop, step);NA(orNULLin a list) takes the default end, and negative values count from the end, as Python slices.- rowsizes, colsizes
Block sizes along rows and columns.
- blocks
A list of rows, each a list of matrices.
Examples
A <- MatrixSymbol("A", 2, 2); B <- MatrixSymbol("B", 2, 2)
A * B + A * B
#> 2*A*B
t(A * B)
#> B.T*A.T
A^-1 * A
#> I
as_explicit(A * B)
#> Matrix(2, 2)
#> [A[0, 0]*B[0, 0] + A[0, 1]*B[1, 0], A[0, 0]*B[0, 1] + A[0, 1]*B[1, 1]]
#> [A[1, 0]*B[0, 0] + A[1, 1]*B[1, 0], A[1, 0]*B[0, 1] + A[1, 1]*B[1, 1]]
doit(Trace(A + B))
#> Trace(A) + Trace(B)