Singular value decomposition of symbolic matrix
[
returns numeric unitary matrices U
,S
,V
]
= svd(A
)U
and
V
with the columns containing the
singular vectors, and a diagonal matrix S
containing the singular values. The matrices satisfy the condition
A = U*S*V'
, where V'
is the Hermitian transpose (the complex conjugate transpose) of
V
. The singular vector computation uses
variable-precision arithmetic. svd
does not
compute symbolic singular vectors. Therefore, the input matrix
A
must be convertible to floating-point
numbers. For example, it can be a matrix of symbolic numbers.
Compute the singular values of the symbolic
5
-by-5
magic
square:
A = sym(magic(5)); sigma = svd(A)
sigma = 65 5^(1/2)*(1345^(1/2) + 65)^(1/2) 65^(1/2)*(5^(1/2) + 5)^(1/2) 65^(1/2)*(5 - 5^(1/2))^(1/2) 5^(1/2)*(65 - 1345^(1/2))^(1/2)
Now, compute singular values of the matrix whose elements are symbolic expressions:
syms t real A = [0 1; -1 0]; E = expm(t*A) sigma = svd(E)
E = [ cos(t), sin(t)] [ -sin(t), cos(t)] sigma = (cos(t)^2 + sin(t)^2)^(1/2) (cos(t)^2 + sin(t)^2)^(1/2)
Simplify the result:
sigma = simplify(sigma)
sigma = 1 1
For further computations, remove the assumption on t
by recreating it using
syms
:
syms t
Convert the elements of the symbolic
5
-by-5
magic
square to floating-point numbers, and compute the singular
values of the matrix:
A = sym(magic(5)); sigma = svd(vpa(A))
sigma = 65.0 22.547088685879657984674226396467 21.687425355202639411956035427154 13.403565997991492328585154445703 11.900789544861194527298509087321
Compute the singular values and singular vectors of the
5
-by-5
magic
square:
old = digits(10); A = sym(magic(5)) [U, S, V] = svd(A) digits(old)
A = [ 17, 24, 1, 8, 15] [ 23, 5, 7, 14, 16] [ 4, 6, 13, 20, 22] [ 10, 12, 19, 21, 3] [ 11, 18, 25, 2, 9] U = [ 0.4472135955, 0.5456348731, 0.5116672736, -0.1954395076, -0.4497583632] [ 0.4472135955, 0.4497583632, -0.1954395076, 0.5116672736, 0.5456348731] [ 0.4472135955, 2.420694008e-15, -0.632455532, -0.632455532, 1.29906993e-15] [ 0.4472135955, -0.4497583632, -0.1954395076, 0.5116672736, -0.5456348731] [ 0.4472135955, -0.5456348731, 0.5116672736, -0.1954395076, 0.4497583632] S = [ 65.0, 0, 0, 0, 0] [ 0, 22.54708869, 0, 0, 0] [ 0, 0, 21.68742536, 0, 0] [ 0, 0, 0, 13.403566, 0] [ 0, 0, 0, 0, 11.90078954] V = [ 0.4472135955, 0.4045164361, 0.2465648962, 0.6627260007, 0.3692782866] [ 0.4472135955, 0.005566159714, 0.6627260007, -0.2465648962, -0.5476942741] [ 0.4472135955, -0.8201651916, -3.091014288e-15, 6.350407543e-16, 0.3568319751] [ 0.4472135955, 0.005566159714, -0.6627260007, 0.2465648962, -0.5476942741] [ 0.4472135955, 0.4045164361, -0.2465648962, -0.6627260007, 0.3692782866]
Compute the product of U
, S
,
and the Hermitian transpose of V
with the 10-digit
accuracy. The result is the original matrix A
with
all its elements converted to floating-point numbers:
vpa(U*S*V',10)
ans = [ 17.0, 24.0, 1.0, 8.0, 15.0] [ 23.0, 5.0, 7.0, 14.0, 16.0] [ 4.0, 6.0, 13.0, 20.0, 22.0] [ 10.0, 12.0, 19.0, 21.0, 3.0] [ 11.0, 18.0, 25.0, 2.0, 9.0]
Use the second input argument 0
to compute the thin, or
economy, SVD of this
3
-by-2
matrix:
old = digits(10); A = sym([1 1;2 2; 2 2]); [U, S, V] = svd(A, 0)
U = [ 0.3333333333, -0.6666666667] [ 0.6666666667, 0.6666666667] [ 0.6666666667, -0.3333333333] S = [ 4.242640687, 0] [ 0, 0] V = [ 0.7071067812, 0.7071067812] [ 0.7071067812, -0.7071067812]
Now, use the second input argument 'econ'
to compute the thin, or economy,
of matrix B
. Here, the
3
-by-2
matrix
B
is the transpose of
A
.
B = A'; [U, S, V] = svd(B, 'econ') digits(old)
U = [ 0.7071067812, -0.7071067812] [ 0.7071067812, 0.7071067812] S = [ 4.242640687, 0] [ 0, 0] V = [ 0.3333333333, 0.6666666667] [ 0.6666666667, -0.6666666667] [ 0.6666666667, 0.3333333333]
The second arguments 0
and 'econ'
only
affect the shape of the returned matrices. These arguments do not
affect the performance of the computations.
Calling svd
for numeric matrices
that are not symbolic objects invokes the MATLAB® svd
function.
Matrix computations involving many symbolic variables can be slow. To increase the computational speed, reduce the number of symbolic variables by substituting the given values for some variables.