forked from sympy/sympy-paper
/
matrices.tex
48 lines (41 loc) · 2.16 KB
/
matrices.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Besides being an important feature in its own right, computations on
matrices with symbolic entries are important for many algorithms
within SymPy. The following code shows some basic usage of the
\texttt{Matrix} class.
\begin{verbatim}
>>> A = Matrix(2, 2, [x, x + y, y, x])
>>> A
Matrix([
[x, x + y],
[y, x]])
\end{verbatim}
SymPy matrices support common symbolic linear algebra manipulations, including
matrix addition, multiplication, exponentiation, computing determinants,
solving linear systems, and computing inverses using LU decomposition, LDL
decomposition, Gauss-Jordan elimination, Cholesky decomposition, Moore-Penrose
pseudoinverse, and adjugate matrix.
All operations are performed symbolically. For instance, eigenvalues are computed
by generating the characteristic polynomial using the Berkowitz algorithm and
then solving it using polynomial routines.
\begin{verbatim}
>>> A.eigenvals()
{x - sqrt(y*(x + y)): 1, x + sqrt(y*(x + y)): 1}
\end{verbatim}
Internally these matrices store the elements as lists of lists, making
it a dense representation.\footnote{Similar to the polynomials module, dense
here means that all entries are stored in memory, contrasted with a sparse
representation where only nonzero entries are stored.} For storing sparse
matrices, the \verb|SparseMatrix| class can be used. Sparse matrices store their
elements as a dictionary of keys.
SymPy also supports matrices with symbolic dimension values. \verb|MatrixSymbol|
represents a matrix with dimensions $m\times n$, where $m$ and $n$ can be
symbolic. Matrix addition and multiplication, scalar operations, matrix inverse,
and transpose are stored symbolically as matrix expressions.
Block matrices are also implemented in SymPy. \verb|BlockMatrix| elements can
be any matrix expression, including explicit matrices, matrix symbols, and
other block matrices. All functionalities of matrix expressions are also
present in \verb|BlockMatrix|.
When symbolic matrices are combined with the assumptions module for logical
inference, they provide powerful reasoning over invertibility,
semi-definiteness, orthogonality, etc., which are valuable in the construction
of numerical linear algebra systems.