numeric
::singularvectors
Numerical singular value decomposition of a matrix
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
numeric::singularvectors(A
, options
)
numeric::singularvectors(A)
and the equivalent
call numeric::svd(A)
return numerical singular
values and singular vectors of the matrix A
.
All entries of A
must be numerical. Numerical
expressions such as etc.
are accepted and converted to floats. Nonnumerical symbolic entries
lead to an error.
Cat::Matrix
objects,
i.e., matrices A
of a matrix domain such as Dom::Matrix(…)
or Dom::SquareMatrix(…)
are
internally converted to arrays over expressions via expr(A)
.
The list [U, d, V, res_{U}, res_{V}]
returned
by numeric::singularvectors
corresponds to the
singular data of an m×n matrix A as
described below.
Let V^{H} denote the Hermitian transpose of the matrix V, i.e., the complex conjugate of the transpose. The singular value decomposition of an m×n matrix A is a factorization A = U D V^{H}. D is an m×n “diagonal” matrix with real nonnegative entries D_{ii} = d_{i}, i = 1, …, p where p = min(m, n):
or
,
respectively. The list d =
[d_{1}, …, d_{p}] returned
by numeric::singularvectors
are the “singular
values” of A.
They are sorted by numeric::sort
,
i.e., d_{1} ≥
… ≥ d_{p} ≥
0.0.
U is
a unitary m×m matrix.
Its ith
column is an eigenvector of A A^{H} associated
with the eigenvalue d_{i}^{2} (d_{i} =
0 for i > p).
These are the “left singular vectors” of A.
They are returned by numeric::singularvectors
as
a matrix of floatingpoint numbers.
V is
a unitary n×n matrix.
Its ith
column is an eigenvector of A^{H} A associated
with the eigenvalue d_{i}^{2} (d_{i} =
0 for i > p).
These are the “right singular vectors” of A.
They are returned by numeric::singularvectors
as
an array of floatingpoint numbers. The matrix V
is
normalized such that, in each column, the first entry of absolute
size larger than is
real and positive.
If no return type is specified via the option ReturnType
= t
, the domain type of the singular vectors U and V depends
on the type of the input matrix A
:
The singular vectors of an hfarray are returned as hfarrays.
The singular vectors of a dense matrix of type Dom::DenseMatrix()
are
returned as dense matrices of type Dom::DenseMatrix()
over
the ring of MuPAD^{®} expressions.
For all other matrices of category Cat::Matrix
, the singular
vectors are returned as matrices of
type Dom::Matrix()
over the ring of MuPAD expressions.
This includes input matrices A
of type Dom::Matrix(…)
, Dom::SquareMatrix(…)
, Dom::MatrixGroup(…)
etc.
res_{U} = [resU_{1}, …, resU_{m}] is a list of float residues associated with the left singular vectors:
.
Here, u_{i} is
the (normalized) ith
column of U
, is
the usual complex Euclidean scalar product and d_{i} =
0 for p < i ≤ m.
res_{V} = [resV_{1}, …, resV_{n}] is a list of float residues associated with the right singular vectors:
.
Here, v_{i} is
the (normalized) ith
column of V
, d_{i} =
0 for p < i ≤ n.
The residues res_{U}, res_{V} vanish
for exact singular data U, d, V.
Their sizes indicate the quality of the numerical data U,
d, V
.
Singular values are approximated with an absolute precision
of ,
where r is
the largest singular value of A
. Consequently,
large singular values should be computed correctly to DIGITS
decimal
places. The numerical approximations of small singular values are
less accurate.
Singular data may also be computed via [d2, U, resU]
:= numeric::eigenvectors(A*A^H)
or [d2, V, resV]
:= numeric::eigenvectors(A^H*A)
, respectively. The list d2
is
related to the singular values by
.
The use of numeric::singularvectors
avoids
the costs of the matrix multiplication. Further, the eigenvector routine
requires about twice as many DIGITS
to compute the data associated
with small singular values with the same precision as numeric::singularvectors
.
Also note that the normalization of U
and V
may
be different.
The function is sensitive to the environment variable DIGITS
,
which determines the numerical working precision.
Numerical expressions are converted to floats:
DIGITS := 5: A := array(1..3, 1..2, [[1, PI], [2, 3], [3, exp(sqrt(2))]]): [U, d, V, resU, resV] := numeric::singularvectors(A):
The singular data are:
U, d, V
The small residues indicate that these results are not severely affected by roundoff:
resU, resV
delete DIGITS, A, U, d, V, resU, resV:
We demonstrate how to reconstruct a matrix from its singular
data. With the specified ReturnType
, the singular
vectors are returned as matrices of type Dom::Matrix()
and
can be handled with the overloaded arithmetic:
DIGITS := 3: A := array(1..2, 1..3, [[1.0, I, PI], [2, 3, I]]): [U, d, V, resU, resV] := numeric::singularvectors(A, NoResidues, ReturnType = Dom::Matrix())
A “diagonal” matrix is built from the singular values:
d := matrix(2, 3, d, Diagonal)
We use the methods conjugate
and transpose
of
the matrix domain to compute the Hermitian transpose of V
and
reconstruct A
. Numerical roundoff is eliminated
via numeric::complexRound
:
VH := V::dom::conjugate(V::dom::transpose(V)): map(U*d*VH, numeric::complexRound)
delete DIGITS, A, U, d, V, resU, resV, VH:
We demonstrate the use of hardware floats. The following matrix A is
degenerate: it has rank 1.
For the double eigenvalue 0 of
the matrix A^{H} A,
different base vectors of the corresponding eigenspace are returned
with HardwareFloats
and SoftwareFloats
,
respectively:
A := array(1..2, 1..3, [[1, 2, 3], [30, 60, 90]]): [U1, d1, V1, resU1, resV1] := numeric::singularvectors(A, HardwareFloats): [U2, d2, V2, resU2, resV2] := numeric::singularvectors(A, SoftwareFloats): V1, V2
delete A, U1, d1, V1, resU1, resV1, U2, d2, V2, resU2, resV2:

A numerical matrix of domain type 

With With Compared to the If no If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried. If the current value of There may be several reasons for hardware arithmetic to fail:
If neither If Note that The trailing digits in floatingpoint results computed with NoteFor illconditioned matrices, the result is subject to roundoff
errors. The results returned with 

Suppresses the computation of left singular vectors If only right singular vectors are required, this option may
be used to suppress the computation of Depending on the size of 

Suppresses the computation of right singular vectors If only left singular vectors are required, this option may
be used to suppress the computation of Depending on the size of 

Suppresses the computation of error estimates If no error estimates are required, this option may be used
to suppress the computation of the residues The alternative option name 

Option, specified as Return the left and right singular vectors as matrices of domain type This option determines the domain type of the matrices containing the singular vectors. 

Suppresses warnings 
List [U, d, V, res_{U}, res_{V}]
. U
is
a unitary square float matrix whose columns are left singular vectors.
The list d
contains the singular values. V
is
a unitary square float matrix whose columns are right singular vectors.
The lists of float residues res_{U}
and res_{V}
provide
error estimates for the numerical data.