Main Content

svd

Singular value decomposition of symbolic matrix

Description

sigma = svd(A) returns a vector sigma containing the singular values of a symbolic matrix A.

example

[U,S,V] = svd(A) returns numeric unitary matrices 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.

example

[U,S,V] = svd(A,0) returns an economy-size decomposition of matrix A. If A is an m-by-n matrix with m > n, then svd computes only the first n columns of U and S is an n-by-n matrix. For m <= n, this syntax is equivalent to svd(A).

example

[U,S,V] = svd(A,'econ') returns a different economy-size decomposition of matrix A. If A is an m-by-n matrix with m >= n, then this syntax is equivalent to svd(A,0). For m < n, svd computes only the first m columns of V and S is an m-by-m matrix.

example

[___] = svd(___,outputForm) returns the singular values in the form specified by outputForm using any of the input or output arguments in previous syntaxes. Specify outputForm as 'vector' to return the singular values as a column vector or as 'matrix' to return the singular values as a diagonal matrix.

example

Examples

collapse all

Compute the singular values of the symbolic 5-by-5 magic square. The result is a column vector.

A = sym(magic(5));
sigma = svd(A)
sigma = 

(6551345+65655+5655-5565-1345)

Alternatively, specify the 'matrix' option to return the singular values as a diagonal matrix.

S = svd(A,'matrix')
S = 

(650000051345+6500000655+500000655-500000565-1345)

Compute singular values of a matrix whose elements are symbolic expressions.

syms t real
A = [0 1; -1 0];
E = expm(t*A)
E = 

(cos(t)sin(t)-sin(t)cos(t))

sigma = svd(E)
sigma = 

(cos(t)2+sin(t)2cos(t)2+sin(t)2)

Simplify the result.

sigma = simplify(sigma)
sigma = 

(11)

For further computations, remove the assumption that t is real by recreating it using syms.

syms t

Create a 5-by-5 symbolic matrix from the magic square of order 6. Compute the singular values of the matrix using svd.

M = magic(6);
A = sym(M(1:5,1:5));
sigma = svd(A)
sigma = 

(root(σ1,z,5)root(σ1,z,4)root(σ1,z,3)root(σ1,z,2)root(σ1,z,1))where  σ1=z5-11357z4+26691022z3-17903673324z2+979310921328z-1676258447616

The svd function cannot find the exact singular values in terms of symbolic numbers. Instead, it returns them in terms of the root function.

Use vpa to numerically approximate the singular values.

sigmaVpa = vpa(sigma)
sigmaVpa = 

(91.90338229938887559838064521710541.66752364570567794703813090238733.3893117613526255506073034298057.61386514813710461179507988708961.3299296132187199146053915272808)

Compute the singular values and singular vectors of the 5-by-5 magic square.

old = digits(10);
A = sym(magic(5))
A = 

(17241815235714164613202210121921311182529)

[U,S,V] = svd(A)
U = 

(0.44721359550.54563487310.5116672736-0.1954395076-0.44975836320.44721359550.4497583632-0.19543950760.51166727360.54563487310.4472135955-1.547164189e-27-0.632455532-0.6324555321.213456644e-270.4472135955-0.4497583632-0.19543950760.5116672736-0.54563487310.4472135955-0.54563487310.5116672736-0.19543950760.4497583632)

S = 

(65.00000022.547088690000021.687425360000013.4035660000011.90078954)

V = 

(0.44721359550.40451643610.24656489620.66272600070.36927828660.44721359550.0055661597140.6627260007-0.2465648962-0.54769427410.4472135955-0.82016519161.767621593e-279.706484055e-280.35683197510.44721359550.005566159714-0.66272600070.2465648962-0.54769427410.44721359550.4045164361-0.2465648962-0.66272600070.3692782866)

digits(old)

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.024.01.08.015.023.05.07.014.016.04.06.013.020.022.010.012.019.021.03.011.018.025.02.09.0)

Calculate the full and economy-size decompositions of a rectangular matrix within 8-digit accuracy.

old = digits(8);
A = sym([1 2; 3 4; 5 6; 7 8])
A = 

(12345678)

[U,S,V] = svd(A)
U = 

(0.15248323-0.82264747-0.39450102-0.379959130.34991837-0.421375290.242796550.800655880.54735351-0.0201031030.69790998-0.461434360.744788650.38116908-0.54620550.040737612)

S = 

(14.269095000.626828230000)

V = 

(0.641423030.76718740.7671874-0.64142303)

[U,S,V] = svd(A,'econ')
U = 

(0.15248323-0.822647470.34991837-0.421375290.54735351-0.0201031030.744788650.38116908)

S = 

(14.269095000.62682823)

V = 

(0.641423030.76718740.7671874-0.64142303)

digits(old)

Since A is a 4-by-2 matrix, svd(A,'econ') returns fewer columns in U and fewer rows in S compared to a full decomposition. Extra rows of zeros in S are excluded, along with the corresponding columns in U that would multiply with those zeros in the expression A = U*S*V'.

Input Arguments

collapse all

Input matrix, specified as a symbolic matrix. For syntaxes with one output argument, the elements of A can be symbolic numbers, variables, expressions, or functions. For syntaxes with three output arguments, the elements of A must be convertible to floating-point numbers.

Since R2021b

Output format of singular values, specified as 'vector' or 'matrix'. This option allows you to specify whether the singular values are returned as a column vector or diagonal matrix. The default behavior varies according to the number of outputs specified:

  • If you specify one output, such as sigma = svd(A), then the singular values are returned as a column vector by default.

  • If you specify three outputs, such as [U,S,V] = svd(A), then the singular values are returned as a diagonal matrix, S, by default.

Output Arguments

collapse all

Singular values of a matrix, returned as a vector. If sigma is a vector of numbers, then its elements are sorted in descending order.

Singular vectors, returned as a unitary matrix. Each column of this matrix is a singular vector.

Singular values, returned as a diagonal matrix. Diagonal elements of this matrix appear in descending order.

Singular vectors, returned as a unitary matrix. Each column of this matrix is a singular vector.

Tips

  • 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.

Version History

Introduced before R2006a

expand all