Dom::Matrix
-- matricesDom::Matrix
(R)
creates a domain of
matrices over the component ring R.
Dom::Matrix( <R>)
R |
- | a ring, i.e., a domain of category Cat::Rng ; default is Dom::ExpressionField() |
Dom::Matrix
(R)
creates domains of
matrices over a component domain R
of category Cat::Rng
(a ring, possibly without
unit).
If the optional parameter R
is not given, the domain
Dom::ExpressionField()
is
used.
E.g., if A
and B
are two matrices defined
by Dom::Matrix
(R)
, A + B
computes the sum, and A * B
computes the product of the
two matrices, provided that the dimensions are correct.
Similarly, A^(-1)
or 1/A
computes the
inverse of a square matrix A
if it exists, and returns
FAIL
otherwise. See
example 1.
map
, subs
, has
, zip
, conjugate
to compute the complex
conjugate of a matrix, norm
to compute matrix norms, or
exp
to compute the
exponential of a matrix.linalg
work with
matrices. For example, to compute the determinant of a square matrix
A
, call linalg::det(A)
. The command linalg::gaussJordan(A)
performs Gauss-Jordan elimination on A
to transform
A
to its reduced row echelon form.
See the documentation of linalg
for a list of available
functions of this package.
Dom::Matrix
(R)
represents
matrices over R
of arbitrary size, and it therefore does
not have any algebraic structure (other than being a set of
matrices).
The domain Dom::SquareMatrix(n, R)
represents
the ring of n x n matrices over R. The
domain Dom::MatrixGroup(m,
n, R)
represents the Abelian group of m x n
matrices over R.
Dom::Matrix
(R)
):
Dom::Matrix
(R)(Array)
Dom::Matrix
(R)(List)
Dom::Matrix
(R)(ListOfRows)
Dom::Matrix
(R)(Matrix)
Dom::Matrix
(R)(m, n)
Dom::Matrix
(R)(m, n, ListOfRows)
Dom::Matrix
(R)(m, n, f)
Dom::Matrix
(R)(m, n, List, Diagonal)
Dom::Matrix
(R)(m, n, g, Diagonal)
Dom::Matrix
(R)(m, n, List, Banded)
Dom::Matrix
(R)(1, n, List)
Dom::Matrix
(R)(m, 1, List)
Array |
- | a one- or two-dimensional array |
Matrix |
- | a matrix, i.e., an element of a domain of category
Cat::Matrix |
m, n |
- | matrix dimension (positive integers) |
List |
- | a list of matrix components |
ListOfRows |
- | a list of at most m rows; each row given
as a list of at most n matrix components |
f |
- | a function or a functional expression with two parameters (the row and column index) |
g |
- | a function or a functional expression with one parameter (the row index) |
Diagonal |
- | create a diagonal matrix |
Banded |
- | create a banded Toeplitz matrix |
Cat::Matrix(R)
Dom::SquareMatrix
, Dom::MatrixGroup
Dom::Matrix
(R)(Array)
and
Dom::Matrix
(R)(Matrix)
create a new matrix
with the dimension and the components of Array
and
Matrix
, respectively.
The components of Array
or Matrix
are
converted into elements of the domain R
. An error message
is issued if one of these conversions fails.
Dom::Matrix
(R)(List)
creates an m x
1 column vector with components taken from the nonempty list, where m is the number of entries of
List
.Dom::Matrix
(R)(ListOfRows)
creates an
m x n matrix with components taken from the nested list ListOfRows
, where m is
the number of inner lists of ListOfRows
, and n
is the maximal number of elements of an inner list. Each inner list
corresponds to a row of the matrix. Both m and n
must be nonzero.
If an inner list has less than n entries, then the remaining components in the corresponding row of the matrix are set to zero.
The entries of the inner lists are converted into elements of the
domain R
. An error message is issued if one of these
conversions fails.
Dom::Matrix
(R)(m, n)
returns the
m x n zero matrix.
Use the method "identity"
to create the n x
n identity matrix.
Dom::Matrix
(R)(m, n, ListOfRows)
creates
an m x n matrix with components taken from the list ListOfRows
.
If m >= 2 and n >= 2, then
ListOfRows
must consist of at most m
inner
lists, each having at most n
entries. The inner lists
correspond to the rows of the returned matrix.
If an inner list has less than n
entries, then the
remaining components of the corresponding row of the matrix are set to
zero. If there are less than m
inner lists, then the
remaining lower rows of the matrix are filled with zeroes.
Dom::Matrix
(R)(m, n, f)
returns the
matrix whose (i,j)th component is the value of the function
call f(i,j)
. The row index i ranges from
1 to m and the column index j from
1 to n.
The function values are converted into elements of the domain
R
. An error message is issued if one of these conversions
fails.
Dom::Matrix
(R)(1, n, List)
returns the
1 x n row vector with components taken from
List
. The list List
must have at most
n
entries. If there are fewer entries, then the remaining
vector components are set to zero.
The entries of the list are converted into elements of the domain
R
. An error message is issued if one of these conversions
fails.
Dom::Matrix
(R)(m, 1, List)
returns the
m x 1 column vector with components taken from
List
. The list List
must have at most
m
entries. If there are fewer entries, then the remaining
vector components are set to zero.
The entries of the list are converted into elements of the domain
R
. An error message is issued if one of these conversions
fails.
Dom::Matrix
(R)(m, n, List, Diagonal)
creates the m x n diagonal
matrix whose diagonal elements are the entries of List
.
List
must have at most min(m, n) entries. If
it has fewer elements, the remaining diagonal elements are set to
zero.
The entries of List
are converted into elements of the
domain R
. An error message is issued if one of these
conversions fails.
Dom::Matrix
(R)(m, n, g, Diagonal)
returns the matrix whose ith
diagonal element is g(i)
, where the index i
runs from 1 to min(n,m).
The function values are converted into elements of the domain
R
. An error message is issued if one of these conversions
fails.
Dom::Matrix
(R)(m, n, List, Banded)
creates an m x n banded Toeplitz
matrix with the elements of List
as entries. The number of
entries of List
must be odd, say 2h+1, and must
not exceed n
. The resulting matrix has bandwidth at most
2h+1.
A Toeplitz matrix is a matrix where the elements of each band are identical. See also example 7.
All elements of the main diagonal of the created matrix are
initialized with the middle element of List
. All elements
of the ith subdiagonal are initialized with the
(h+1-i)th element of List
. All elements of the
ith superdiagonal are initialized with the
(h+1+i)th element of List
. All entries on the
remaining sub- and superdiagonals are set to zero.
The entries of List
are converted into elements of the
domain R
. An error message is issued if one of these
conversions fails.
is always FALSE
, as elements of
Dom::Matrix
(R)
use a dense representation of
their matrix components.
is set to [10,10]
. See the method "random"
below for details.
_divide(dom A, dom
B)
B
must be nonsingular, otherwise FAIL
is
returned.A
and
B
do not match.R
is an integral domain,
i.e., a domain of category Cat::IntegralDomain
._divide
for matrices, i.e., one may
use it in the form A / B
, or in functional notation:
_divide(A, B)
._invert(dom A)
A
. If
A
is singular, FAIL
is returned.R
is the domain Dom::Float
, a floating-point
approximation of the inverse matrix is computed by the function
numeric::inverse
.R
is a domain of category
Cat::IntegralDomain
._invert
for matrices, i.e., one may
use it in the form 1/A
or A^(-1)
, or in
functional notation: _invert(A)
._mult(dom x, any
y)
y
is a matrix of the same domain type as
x
, the matrix product x*y is computed. An error
message is issued if the dimensions of the matrices do not match.y
is of the domain type R
or can be
converted into such an element, the corresponding scalar multiplication
is computed.
Otherwise, y
is converted into a matrix of the domain
type of x
. If this conversion fails, then this method
calls the method "_mult"
of the domain of y
giving all arguments in the same order.
_mult(any x, dom
y)
x
is a matrix of the same domain type as
y
, then the matrix product x*y is computed. An
error message is issued if the dimensions of the matrices do not
match.x
is of the domain type R
or can be
converted into such an element, the corresponding scalar multiplication
is computed.
Otherwise, x
is converted into a matrix of the domain
type of y
. If this conversion fails, then
FAIL
is returned.
_mult
._mult
for matrices, i.e., one may use
it in the form x * y
, or in functional notation:
_mult(x, y)
._negate(dom A)
_negate
for matrices, i.e., one may
use it in the form -A
, or in functional notation:
_negate(A)
._plus(matrix A, matrix B...)
An error message is issued if the given matrices do not have the same dimensions.
A,
B... are converted into matrices of
the domain type Dom::Matrix
(R)
.
FAIL
is returned if one of these conversions fails._plus
for matrices, i.e., one may use
it in the form A + B
, or in functional notation:
_plus(A, B)
._power(dom A, integer
n)
A
is not
square, FAIL
is returned.n
is a negative integer then
A
must be nonsingular and R
must be a domain
of category Cat::IntegralDomain
. Otherwise
FAIL
is returned.n
is zero and the component ring R
is
a ring with no unit (i.e., of category Cat::Rng
, but not of category Cat::Ring
), FAIL
is
returned._power
for matrices, i.e., one may
use it in the form A^n
, or in functional notation:
_power(A, n)
.conjugate(dom A)
A
is the matrix
obtained by computing the complex conjugate of each component of
A
.R
implements the method
"conjugate"
, which computes the complex conjugate of an
element of the domain R
.conjugate
for matrices, i.e., one
may use it in the form conjugate(A)
.diff(dom A...)
A
using the method "diff"
of the component
ring R
.
Additional arguments are passed to the method "diff"
of
the domain R
. See the system function diff
for details.
R
implements the method
"diff"
.diff
for matrices,
i.e., one may use it in the form diff(A...)
.equal(dom A, dom
B)
A
and
B
are equal and returns TRUE
,
FALSE
, or UNKNOWN
, respectively.R
has the axiom Ax::systemRep
then normal
is used to simplify the
components of A
and B
before testing their
equality.exp(dom A <, R
t>)
A
, defined by I + A*t + 1/2(A*t)^2 +
..., where I is the n x n identity matrix.
The default value of t
is 1.A
is not square, an error message is issued.numeric::expMatrix
for a
floating-point approximation of the exponential of A
if
A
is defined over the domain Dom::Float
and if t = 1.A
do not exist in
R
or cannot be computed, then FAIL
is
returned.linalg::jordanForm
is called,
which may not be able to compute the Jordan form of A
. In
this case FAIL
is returned. Increasing the level of
information (see setuserinfo
) can yield useful
information.R
is a domain of category
Cat::Field
.exp
for matrices, i.e., one may use it
in the form exp(A...)
.expand(dom A)
expand
to each component of the
matrix A
.R
implements the method
"expand"
, or if R
has the axiom Ax::systemRep
(in this case, the
system function expand
is used).expand
for matrices, i.e., one may
use it in the form expand(A)
.factor(dom A)
A
into the form A =
s*B, where s is a scalar of the component ring
R
.
The result is a factored object, i.e., an element of the domain
Factored
. It has the
factorization type "unknown"
.
A
. Hence, this method only exists if R
is of
category Cat::GcdDomain
.factor
for matrices, i.e., one may
use it in the form factor(A)
.float(dom A)
float
to the matrix components of
A
, i.e., it computes a floating-point approximation of the
matrix components.R
implements the method
"float"
.Usually the floating-point approximations are not
elements of R
! For example, Dom::Integer
implements such a method,
but the floating-point approximation of an integer cannot be
re-converted into an integer.
This method checks whether the resulting matrix can be converted
into the domain type of A
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
Otherwise, one has to take care that the matrix returned is compatible to its component ring.
gaussElim(dom A)
A
and
reduces A
to an upper row echelon form T.
It returns a list containing the matrix T, the rank and
determinant of A
, and the set of characteristic column
indices of T (in this order).
A
is not defined, then the third entry of the list
returned is the value FAIL
.R
is an
integral domain, i.e., a domain of category Cat::IntegralDomain
.R
has the method "pivotSize"
, then the
pivot element of smallest size is chosen at every pivoting step,
whereby pivotSize
must return a positive integer
representing the ``size'' of an element.
If no such method is defined, Gaussian elimination without a pivot
strategy is applied to A
.
R
has the axiom Ax::efficientOperation
("_invert")
and is of category Cat::Field
, then ordinary Gaussian
elimination is used. Otherwise, fraction-free elimination is performed
on A
.R
implements the method "normal"
, it
is used to simplify subsequent computations of the Gaussian elimination
process.
Note that if R
does not implement the method
"normal"
, but the elements of R
are
represented by kernel domains, i.e., R
has the axiom
Ax::systemRep
, the
system function normal
is used instead.
identity(positive integer n)
R
is of
category Cat::Ring
, i.e., a
ring with unit.iszero(dom A)
A
is a zero matrix.R
does not have Ax::canonicalRep
.R
implements the method "normal"
, it
is used to simplify the components of A
for the zero-test.
Note that if R
does not implement such a method, but
the elements of R
are represented by kernel domains, i.e.,
R
has the axiom Ax::systemRep
, the system function
normal
is used
instead.
iszero
for matrices, i.e., one may
use it in the form iszero(A)
.matdim(dom A)
A
as a list of two positive integers.norm(dom A <, Infinity>)
A
, which is
the maximum row sum (the row sum is the sum of norms of each component
in a row).
If the domain R
does not implement the methods
"max"
and "norm"
, FAIL
is
returned.
norm(dom v <, Infinity>)
v
the maximum norm of all elements is
returned.
If the domain R
does not implement the methods
"max"
and "norm"
, FAIL
is
returned.
norm(dom A, Frobenius)
A
, which is the square
root of the sum of the squares of the norms of each component.
If the result is no longer an element of the domain R
,
or if R
does not implement the method "norm"
,
FAIL
is returned.
norm(dom A, 1)
A
, which is the
maximum sum of the norms of the elements of each column. If
R
does not implement the methods "max"
and
"norm"
, FAIL
is returned.norm(dom v, positive
integer k)
v
, which
is defined to be the kth root of the sum of the norms of the
elements of v
raised to the kth power.
FAIL
is returned if the result is no longer an element
of the domain R
. For k=2, the function linalg::scalarProduct
is
used to compute the 2-norm of v
.
If R
does not implement the method "norm"
,
FAIL
is returned.
norm
for matrices, i.e., one may use it
in the form norm(A <, k>)
, where k
is
either Infinity, Frobenius,
or a positive integer. The default value of k
is Infinity.normal(dom A)
"normal"
of R
is applied to
the components of A
.R
does not implement the method
"normal"
, but the elements of R
are
represented by kernel domains, i.e., R
has the axiom
Ax::systemRep
, then the
system function normal
is applied to the components of A
. Otherwise
normal(A)
returns A
without any changes.normal
for matrices, i.e., one may
use it in the form normal(A)
.nonZeros(dom A)
A
for
which the method "iszero"
of the component ring
R
returns FALSE
.random()
"random"
of the component ring R
to randomly
generate the components of the matrix.R
implements the method
"random"
."randomDimen"
(see
``Entries'' above)."randomDimen"
for a
domain MatR
created with Dom::Matrix
, one
must first unprotect the domain Dom
(see unprotect
for details).tr(dom A)
A
,
which is defined to be the sum of its diagonal entries.A
is not square, then an error message is
issued.transpose(dom A)
A
._concat(dom A, dom
B...)
B
... to the right
side of the matrix A
._concat
for matrices, i.e., one may
use it in the form A . B . ...
, or in functional notation:
_concat(A, B, ...)
._index(dom A, row
index i, column index j)
A
._index(dom A, row-range r1..r2, column-range
c1..c2)
A
created by the
rows of A
with indices from r1
to
r2
and the columns of A
with indices from
c1
to c2
._index(dom v, index
i)
v
.v
is not a vector._index(dom v, index-range i1..i2)
v
, formed by the
entries with index i1
to i2
. See also the
method "op"
.v
is not a vector._index
for matrices, i.e., one may
use it in the form A[i, j]
, A[r1..r2,
c1..c2]
, v[i]
and v[i1..i2]
,
respectively, or in functional notation:
_index(A...)
.concatMatrix(dom A, dom B...)
"_concat"
.col(dom A, column
index c)
c
of the
matrix A
and returns it as a column vector, i.e., as an
element of type Dom::Matrix
(R)
.c
is less than one or
greater than the number of columns of A
.delCol(dom A, column
index c)
c
of the matrix A
.NIL
is returned if A
consists of only one
column.c
is less than one or
greater than the number of columns of A
.delRow(dom A, row
index r)
r
of the matrix A
.NIL
is returned if A
consists of only one
row.r
is less than one or
greater than the number of rows of A
.evalp(dom A, equation
x = a...)
A
at the point x = a
. See the system function evalp
for details.
The matrix returned is of the domain
Dom::Matrix
(R::coeffRing)
if the evaluation
of all components leads to an element of the coefficient ring of the
polynomial domain. Otherwise the matrix returned is of the domain of
A
.
R
is a polynomial ring
of category Cat::Polynomial
.evalp
for matrices,
i.e., one may use it in the form evalp(A, x = a)
.length(dom A)
A
, which
is the length of the array holding the components of A
.
See the system function length
for details.length
for
matrices, i.e., one may use it in the form length(A)
.map(dom A, function
func <, any expr...>)
func
to the components
of the matrix A
, with the additional function parameters
expr...
passed to func
, if given.
See the system function map
for details.
Note that the function values are converted into
elements of the domain R
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
If testargs
returns FALSE
, then one must guarantee that the function
calls return elements of the domain type R
, otherwise the
resulting matrix, which is of domain type
Dom::Matrix
(R)
, would have components which
are not elements of the domain R
!
map
for matrices,
i.e., one may use it in the form map(A, func...)
.nops(dom A)
A
.nops
for matrices, i.e., one may use it
in the form nops(A)
.op(dom A, positive
integer i)
A
, where the components are numbered starting at row one
from left to right and up to down.op(dom A)
A
."_index"
.op
for matrices, i.e., one may use it in
the form op(A, i)
and op(A)
,
respectively.row(dom A, row index
r)
r
of the
matrix A
and returns it as a row vector, i.e., as an
element of type Dom::Matrix
(R)
.r
is less than one or
greater than the number of rows of A
.setCol(dom A, column
index c, dom v)
c
of the
matrix A
by the column vector v
. The vector
v
must have nrows(A) elements.c
is less than one or
greater than the number of rows of A
.setRow(dom A, row
index r, dom v)
r
of the
matrix A
by the row vector v
. The vector
v
must have ncols(A) elements.r
is less than one or
greater than the number of rows of A
.stackMatrix(dom A, dom B...)
A
on the top of the
matrix B
. If further arguments are given, then the result
is stacked on the top of the third matrix, and so on.subs(dom A...)
subs
with additionally
given parameters to the components of the matrix A
. See
the system function subs
for details.Note that the function values are converted into
elements of the domain R
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
If testargs
returns FALSE
, then one must guarantee that the function
calls return elements of the domain type R
, otherwise the
resulting matrix, which is of domain type
Dom::Matrix
(R)
, would have components which
are not elements of the domain R
!
subs
for matrices,
i.e., one may use it in the form subs(A...)
.subsex(dom A...)
subsex
with additionally
given parameters to the components of the matrix A
. See
the system function subsex
for details.Note that the results of the substitutions are
converted into elements of the domain R
only if testargs
returns
TRUE
(e.g., if one calls this method from the interactive
level of MuPAD).
If testargs
returns FALSE
, then one must guarantee that the results of
the substitutions are of the domain type R
, otherwise the
resulting matrix, which is of domain type
Dom::Matrix
(R)
, would have components which
are not elements of the domain R
!
subsex
for
matrices, i.e., one may use it in the form
subsex(A...)
.subsop(dom A, equation i = x...)
A
by x
.Note that x
is converted into the
domain R
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
If testargs
returns FALSE
, then x
must be an element of
R
, otherwise the resulting matrix, which is of domain type
Dom::Matrix
(R)
, would have components which
are not elements of the domain R
!
"set_index"
.subsop
for
matrices, i.e., one may use it in the form
subsop(A...)
.swapCol(dom A, column
indices c1, c2)
c1
with the column with index
c2
of the matrix A
.A
.swapCol(dom A, column
indices c1, c2, row range r1..r2)
c1
and the
column with index c2
of A
, but by taking only
those column components which lie in the rows with indices
r1
to r2
.A
, or if
one of the row indices is less than one or greater than the number of
rows of A
.swapRow(dom A, row
indices r1, r2)
r1
with row with index r2
of the
matrix A
.A
.swapRow(dom A, row
indices r1, r2, column range
c1..c2)
r1
and the row
with index r2
of A
, but by taking only those
row components which lie in the columns with indices c1
to
c2
.A
, or if one of
the column indices is less than one or greater than the number of
columns of A
.set_index(dom A, row
index i, column index j, any x)
A
by x
.Note that x
is converted into an
element of the domain R
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
Otherwise one has to take care that x
is of domain type
R
.
"subsop"
.set_index(dom v, index i, any x)
v
by
x
.set_index
for
matrices, i.e., one may use it in the form A[i, j] := x
and v[i] := x
, respectively, or in functional notation:
A := set_index(A, i, j, x)
or v := set_index(v, i,
x)
.zip(dom A, B, function func <, any
expr...>)
A
and B
component-wise, where the function func(a, b <,
expr...>)
is applied to each pair (A[i, j], B[i,
j]) (for all i and j).A
and B
, and its column number is
the minimum of the column numbers of A
and
B
.Note that the function values are converted into
elements of the domain R
only if testargs
returns TRUE
(e.g., if one calls this method from the interactive level of
MuPAD).
If testargs
returns FALSE
, then one must guarantee that the function
calls return elements of the domain type R
, otherwise the
resulting matrix, which is of domain type
Dom::Matrix
(R)
, would have components which
are not elements of the domain R
!
zip
for matrices, i.e., one may use it
in the form zip(A, B...)
.convert(any x)
x
into a matrix of type
Dom::Matrix
(R)
.FAIL
is returned if the conversion fails.x
may either be an array, a matrix, or a list (of
sublists, see the parameter ListOfRows
in ``Creating
Elements'' above). Their entries must then be convertible into elements
of the domain R
.convert_to(dom A, any
T)
A
into an
element of domain type T
. FAIL
is returned if
the conversion fails.T
may either be DOM_ARRAY
, DOM_LIST
, or a domain constructed
by Dom::Matrix
or Dom::SquareMatrix
. The elements of
A
must be convertible into elements of the domain
R
.expr
to convert A
into an object of a kernel domain (see
below).create(any x...)
R
.
See ``Creating Elements'' above for a complete description of the parameters, with one exception: one cannot use this method to create a matrix from a function or a functional expression.
"new"
of the domain, because it avoids
any conversion of the components. One must guarantee that the
components have the correct domain type, otherwise run-time errors can
be caused.expr(dom A)
A
into an array, i.e., an object
of type DOM_ARRAY
,
and applies the function expr
to each component of
A
.A
where
each entry is an object of a kernel domain.expr
for matrices, i.e., one may use it
in the form expr(A)
.expr2text(dom A)
A
into a string s
such that the evaluation of the function call text2expr(s)
gives the matrix A
.expr2text
for matrices, i.e., one
may use it in the form expr2text(A)
.TeX(dom A)
A
in form of a TeX array environment."TeX"
of the component ring R
is used to get the TeX-representation of each component of
A
.generate::TeX
.assignElements(dom A...)
A
.
See the system function assignElements
for
details.
R
,
an implicit conversion of the components into elements of domain type
R
is not performed.assignElements
for matrices,
i.e., one may use it in the form
assignElements(A...)
.mkDense(array Array)
Array
into an
element of the component ring R
. The result is either
FAIL
if one of these conversions is not possible, or the
list [r, c, Array]
, where the positive integers
r
and c
give the dimension of
Array
.mkDense(list List)
List
into an
array a
. The result is either FAIL
if this is
not possible, or the list [r, c, a]
, where the positive
integers r
and c
give the dimension of
a
. See the parameters List
and
ListOfRows
in ``Creating Elements'' above for admissible
formats of List
.
The array a
has dimension one if r
or
c
is equal to one. The entries of a
have been
converted into elements of the domain R
.
mkDense(positive integers r, c, list List)
List
into an
array a
of the dimension r
times
c
.
The result is either FAIL
if this is not possible, or
the list [r, c, a]
.
The array a
has dimension one if r
or
c
is equal to one. The entries of a
have been
converted into elements of the domain R
.
print(dom A)
A
. Thus, matrices are printed like arrays.unapply(dom A <, identifier x...>)
A
as
functions in x
..., and returns a procedure representing
this matrix function. See fp::unapply
for details.fp::unapply
for
matrices, i.e., one may use it in the form
fp::unapply(A)
.First we create the domain of matrices over the field of rational numbers:
>> MatQ := Dom::Matrix(Dom::Rational)
Dom::Matrix(Dom::Rational)
We assigned this domain to the identifier
MatQ
. Next we define the 2 x 2 matrix
+- -+ | 1 5 | | | | 2 0 | +- -+
by a list of two rows, where each row is a list of two elements:
>> A := MatQ([[1, 5], [2, 3]])
+- -+ | 1, 5 | | | | 2, 3 | +- -+
In the same way we define the following 2 x 3 matrix:
>> B := MatQ([[-1, 5/2, 3], [1/3, 0, 2/5]])
+- -+ | -1, 5/2, 3 | | | | 1/3, 0, 2/5 | +- -+
and perform matrix arithmetic using the standard arithmetical operators of MuPAD, e.g., the matrix product A * B, the 4th power of A as well as the scalar multiplication of A times 1/3:
>> A * B, A ^ 4, 1/3 * A
+- -+ +- -+ +- -+ | 2/3, 5/2, 5 | | 281, 600 | | 1/3, 5/3 | | |, | |, | | | -1, 5, 36/5 | | 240, 521 | | 2/3, 1 | +- -+ +- -+ +- -+
The matrices A and B have different dimensions, and therefore the sum of A and B is not defined. MuPAD issues an error message:
>> A + B
Error: dimensions don't match [(Dom::Matrix(Dom::Rational))\ ::_plus]
To compute the inverse of A, just enter:
>> 1/A
+- -+ | -3/7, 5/7 | | | | 2/7, -1/7 | +- -+
If a matrix is not invertible, FAIL
is the
result of this operation. For example, the matrix:
>> C := matrix(2, 2, [[2]])
+- -+ | 2, 0 | | | | 0, 0 | +- -+
is not invertible, hence:
>> C^(-1)
FAIL
We create the domain of matrices over the reals:
>> MatR := Dom::Matrix(Dom::Real)
Dom::Matrix(Dom::Real)
Beside standard matrix arithmetic, the library linalg
offers a lot of
functions dealing with matrices. For example, if one wants to compute
the rank of a matrix, use linalg::rank
:
>> A := MatR([[1, 2], [2, 4]])
+- -+ | 1, 2 | | | | 2, 4 | +- -+
>> linalg::rank(A)
1
Use linalg::eigenvectors
to compute
eigenvalues and eigenvectors of the matrix A:
>> linalg::eigenvectors(A)
-- -- -- +- -+ -- -- -- -- +- -+ -- -- -- | | | | -2 | | | | | | 1/2 | | | | | | 0, 1, | | | | |, | 5, 1, | | | | | | | | | | 1 | | | | | | 1 | | | | -- -- -- +- -+ -- -- -- -- +- -+ -- -- --
Try info(linalg)
for a list of available
functions, or enter help(linalg)
for details about the
library linalg
.
Some of the functions in the linalg
package simply
serve as ``interface'' functions for methods of a matrix domain
described above. For example, linalg::transpose
uses the method
"transpose"
to get the transposed matrix. The function
linalg::gaussElim
applies Gaussian elimination to a matrix, such as:
>> linalg::gaussElim(A)
+- -+ | 1, 2 | | | | 0, 0 | +- -+
The computation is performed by the method
"gaussElim"
as described above. Such functions of the
linalg
packages, in contrast to the corresponding methods
of the domain Dom::Matrix
(R)
, check their
incoming parameters, and some of them offer extended
functionalities.
In this example, we use the default matrix domain which
is created by Dom::Matrix()
. This domain represents
matrices whose components can be arbitrary arithmetical expressions
(i.e., the component ring is the domain Dom::ExpressionField()
).
This domain is already known to MuPAD by the name matrix
:
>> A := matrix( [[1, 2, 3, 4], [2, 0, 4, 1], [-1, 0, 5, 2]] )
+- -+ | 1, 2, 3, 4 | | | | 2, 0, 4, 1 | | | | -1, 0, 5, 2 | +- -+
>> domtype(A)
Dom::Matrix()
Matrix components can be extracted by the index operator
[]
:
>> A[2, 1] * A[1, 2] - A[3, 1] * A[1, 3]
7
If one of the indices is not in its valid range, an error message is issued. Assignments to matrix components are performed similarly:
>> delete a: A[1, 2] := a^2: A
+- -+ | 2 | | 1, a , 3, 4 | | | | 2, 0, 4, 1 | | | | -1, 0, 5, 2 | +- -+
Beside the usual indexing of matrix components, it is also possible to extract submatrices from a given matrix. The following call creates the submatrix of A which consists of the rows 2 to 3 and columns 1 to 3 of A:
>> A[2..3, 1..3]
+- -+ | 2, 0, 4 | | | | -1, 0, 5 | +- -+
The index operator does not allow to insert submatrices
into a given matrix. This is implemented by the function linalg::substitute
.
In the following examples, we demonstrate the different
ways of creating matrices. We work with matrices defined over the field
Z19, i.e., the field of integers modulo 19.
This component ring can be created with the domain constructor Dom::IntegerMod
.
We start by giving a list of rows, where each row is a list of row entries:
>> MatZ19 := Dom::Matrix(Dom::IntegerMod(19)): MatZ19([[1, 2], [2]])
+- -+ | 1 mod 19, 2 mod 19 | | | | 2 mod 19, 0 mod 19 | +- -+
The elements of the two inner lists, the row entries,
were converted into elements of the domain
Dom::IntegerMod(19)
.
The number of rows is the number of sublists of the argument, i.e., m = 2. The number of columns is determined by the length of the inner list with the most entries, which is the first inner list with two entries. Missing entries in the other inner lists are treated as zero components. The call:
>> MatZ19(4, 4, [[1, 2], [2]])
+- -+ | 1 mod 19, 2 mod 19, 0 mod 19, 0 mod 19 | | | | 2 mod 19, 0 mod 19, 0 mod 19, 0 mod 19 | | | | 0 mod 19, 0 mod 19, 0 mod 19, 0 mod 19 | | | | 0 mod 19, 0 mod 19, 0 mod 19, 0 mod 19 | +- -+
fixes the dimension of the matrix. Missing entries and inner lists are treated as zero components and zero rows, respectively.
An error message is issued if one of the given entries cannot be converted into an element over Z19:
>> MatZ19([[2, 3], [-1, I]])
Error: unable to define matrix over Dom::IntegerMod(19) \ [(Dom::Matrix(Dom::IntegerMod(19)))::new]
This example illustrates how to create a matrix with
components given as values of an index function. First we create the
2 x 2 Hilbert matrix (see also the functions linalg::hilbert
and linalg::invhilbert
):
>> matrix(2, 2, (i, j) -> 1/(i + j - 1))
+- -+ | 1, 1/2 | | | | 1/2, 1/3 | +- -+
Note the difference when working with expressions and functions. If you give an expression it is treated as a function in the row and column indices:
>> delete x: matrix(2, 2, x), matrix(2, 2, (i, j) -> x)
+- -+ +- -+ | x(1, 1), x(1, 2) | | x, x | | |, | | | x(2, 1), x(2, 2) | | x, x | +- -+ +- -+
Diagonal matrices can be created with the option Diagonal and a list of diagonal components:
>> MatC := Dom::Matrix(Dom::Complex): MatC(3, 4, [1, 2, 3], Diagonal)
+- -+ | 1, 0, 0, 0 | | | | 0, 2, 0, 0 | | | | 0, 0, 3, 0 | +- -+
Hence, to define the n x n identity matrix, you can enter:
>> MatC(3, 3, [1 $ 3], Diagonal)
+- -+ | 1, 0, 0 | | | | 0, 1, 0 | | | | 0, 0, 1 | +- -+
or even call:
>> MatC(3, 3, x -> 1, Diagonal)
+- -+ | 1, 0, 0 | | | | 0, 1, 0 | | | | 0, 0, 1 | +- -+
The easiest way to create the identity matrix, however,
is to use the method "identity"
:
>> MatC::identity(3)
+- -+ | 1, 0, 0 | | | | 0, 1, 0 | | | | 0, 0, 1 | +- -+
Toeplitz matrices can be defined with the option Banded. The following call defines a three-banded matrix with the component 2 on the main diagonal and the component -1 on the first subdiagonals:
>> matrix(4, 4, [-1, 2, -1], Banded)
+- -+ | 2, -1, 0, 0 | | | | -1, 2, -1, 0 | | | | 0, -1, 2, -1 | | | | 0, 0, -1, 2 | +- -+
Some system functions can be applied to matrices, such
as norm
, expand
, diff
, conjugate
, or exp
.
For example, to expand the components of the matrix:
>> delete a, b: A := matrix( [[(a - b)^2, a^2 + b^2], [a^2 + b^2, (a - b)*(a + b)]] )
+- -+ | 2 2 2 | | (a - b) , a + b | | | | 2 2 | | a + b , (a + b) (a - b) | +- -+
enter:
>> expand(A)
+- -+ | 2 2 2 2 | | - 2 a b + a + b , a + b | | | | 2 2 2 2 | | a + b , a - b | +- -+
If you want to differentiate the matrix components, then call for example:
>> diff(A, a)
+- -+ | 2 a - 2 b, 2 a | | | | 2 a, 2 a | +- -+
To substitute matrix components by some values, enter:
>> subs(A, a = 1, b = -1)
+- -+ | 4, 2 | | | | 2, 0 | +- -+
The function zip
can also be applied to matrices. The
following call combines two matrices A and B by
dividing each component of A by the corresponding component
of B:
>> A := matrix([[4, 2], [9, 3]]): B := matrix([[2, 1], [3,-1]]): zip(A, B, `/`)
+- -+ | 2, 2 | | | | 3, -3 | +- -+
The quoted character `/`
is another
notation for the function _divide
, the functional form of
the division operator /
.
If one needs to apply a function to the components of a matrix, then
use the function map
. For
example, to simplify the components of the matrix:
>> C := matrix( [[sin(x)^2 + cos(x)^2, exp(x) - exp(x/2)^2], [(a^2 - b^2)/(a + b), 1]] )
+- -+ | 2 2 / x \2 | | cos(x) + sin(x) , exp(x) - exp| - | | | \ 2 / | | | | 2 2 | | a - b | | -------, 1 | | a + b | +- -+
call:
>> map(C, simplify)
+- -+ | 1, 0 | | | | a - b, 1 | +- -+
A column vector is represented as a 2 x 1 matrix:
>> MatR := Dom::Matrix(Dom::Real): v := MatR(2, 1, [1, 2])
+- -+ | 1 | | | | 2 | +- -+
The dimension of this vector is:
>> MatR::matdim(v)
[2, 1]
Use linalg::vecdim
, or even call
nops(v)
to get the length of a vector:
>> linalg::vecdim(v)
2
The ith component of this vector can be
extracted in two ways: either by v[i,1]
or by
v[i]
:
>> v[1], v[2]
1, 2
We get the 2-norm of v
by the following
call:
>> norm(v, 2)
1/2 5
"dimen"
was renamed to
"matdim"
."newThis"
was renamed to
"create"
."_invert"
now uses the function numeric::inverse
for certain
component rings R
."diff"
which applies the function diff
to the components of a
matrix."evalp"
for matrices over polynomial
rings.exp
now uses the function numeric::expMatrix
for a
floating-point approximation of the exponential of a matrix, i.e., if
the component ring R
is the domain Dom::Float
."expand"
which applies the function
expand
to the
components of a matrix."factor"
for rewriting the matrix
A in the form A = s B with a scalar
s."float"
for computing a floating-point
approximation of matrix components."identity"
to ease the construction of
identity matrices."normal"
for simplification of matrix
components."unapply"
for overloading the function
fp::unapply
.