This series of tutorials comes from the publication of the "Matlabbased programming basics and typical application books". If copyright concerns are involved, please contact [email protected]. Press: People's post and telecommunications press. The number of pages is 525.
This series of tutorials is currently based on MATLAB r2006a and may differ from functions in more advanced versions. If you have any questions in this tutorial, contact [email protected].
# Matrix decomposition
Matrix decomposition is an important part of matrixrelated operations. MATLAB provides multiple functions for matrix decomposition operations. This section describes the functions and usage of Matrix Factorization functions provided by Matlab.
### 3.2.1 Lu Decomposition
The triangle decomposition of a matrix, also known as Gaussian elimination, aims to break down a matrix into a lower triangle matrix L and the product of an upper Triangle Matrix U, that is, a = Lu. MATLAB provides a special function Lu to calculate the Lu decomposition of the matrix. The Calling format of this function is as follows:
① [L,U] = lu(X)
② [L,U,P] = lu(X)
Where, the return matrix U is the upper triangle array, and the matrix L is the lower triangle array or its transformation form, and meets Lu = x. Returns the row transformation matrix of the matrix P, which is Lu = px.
(Example 3.24) Lu decomposition of matrix X
In the command window, enter the following content to create the matrix X:
>> X=[5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9;4 5 6 7 8];
① Perform Lu decomposition on matrix X and input the following in the Command window:
& Gt; [L, u] = LU (x) % lu decomposition of matrix X
### 3.2.2 Singular Value Decomposition
Singular Value Decomposition plays an extremely important role in matrix analysis. MATLAB provides the SVD function for Matrix Singular Value Decomposition, which is developed by zsvdc in the linpack library. In the calculation process, if a singular value is still not obtained after 75 steps of QR decomposition, the system will prompt "no convergence. The Calling formats of the SVD function are as follows:
① s = svd (X)
② [U,S,V] = svd (X)
③ [U,S,V] = svd (X,0)
Command ① returns the vector S, which contains all the singular value vectors obtained by matrix X decomposition. Command ② returns a diagonal matrix s with the same size as X and two original matrices U and V, and the value = uSV '. Command ③ to obtain a decomposition of "valid size". If M> N in m × ndimensional matrix X, only the first n columns of matrix u are calculated, the size of matrix S is n × n.
(Example 3.25) Singular Value Decomposition.
In the command window, enter the following content to create the matrix B1.
>> b1=[1 2 3;4 5 6;7 8 9;2 4 6;5 7 5];
① Perform Singular Value Decomposition on B1, and return a diagonal matrix s with the same size as B1, and two Udas u and v. In the command window, enter:
& Gt; [U, S, V] = SVD (B1) % Singular Value Decomposition for B1
② Perform Singular Value Decomposition on B1 and call the function to obtain a "valid size" decomposition Function Format. Return the diagonal matrix s and the two original matrices u and v. In the command window, enter:
& Gt; [U, S, V] = SVD (B1, 0) % Singular Value Decomposition for B1
### 3.2.3 feature value decomposition
MATLAB provides the EIG function to break down the matrix feature values. The Calling formats of this function are as follows:
① d = eig(A)
② d = eig(A,B)
③ [V,D] = eig(A)
④ [V,D] = eig(A,‘nobalance‘)
⑤ [V,D] = eig(A,B)
⑥ [V,D] = eig(A,B,flag)
Where, ① calculate the feature value D of matrix A, and the returned results are saved as vectors. ② Calculate the generalized feature value D of square matrix A and B and store the returned results in Vector Form. ③ Calculate the feature value diagonal matrix D and feature vector array V of matrix A to enable AV = VD. ④ Calculate the feature value diagonal matrix D and feature vector array V of matrix A to enable AV = VD. This command may be more accurate when there is a value not far from the truncation error order in matrix. 'Nobalance 'plays a role in error adjustment. ⑤ Calculate the generalized feature value vector arrays V and the generalized feature value arrays D of matrices A and B, satisfying AV = BVD. The last line of command 6 is the feature value D and feature vector V of matrix A and matrix B specified by the flag. The possible flag values are 'chol 'and 'qz '. When the flag value is 'chol ', it indicates that Cholesky decomposition algorithm is used for B, where A is a symmetric Hermitian Matrix and B is a positive definite matrix. When the flag value is 'qz', The qz algorithm is used, where A and B are asymmetric or nonHermitian matrices.
[3.26] feature value decomposition
In the command window, enter the following content to create matrix.
>> A=[1 2 3 4 5;5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9];
Break down the feature values of matrix A in the Command window:
& Gt; [V, d] = EIG (a) % decomposed the feature values of matrix
### 3.2.4 Cholesky Decomposition
MATLAB provides the Chol function to perform Cholesky decomposition on the matrix. The call format of this function is:
①R = chol(X)
②[R,p] = chol(X)
Function call format ① if X is an norder symmetric positive definite matrix, there is a real nonsingular upper triangle array R, meeting the R' * r = x; if X is not positive, the error message is generated. ② No error message is generated. If X is a positive definite array, P = 0, r is the same as above. If X is not positive definite, P is a positive integer, R is an ordered upper triangle array.
[Example 3.27] Cholesky Decomposition
In the command window, enter the following content to create matrix.
>> A=[1 2 3 4 5;5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9];
Perform Cholesky decomposition on matrix A and enter the following in the Command window:
& Gt; [R, p] = Chol (a) % Cholesky Decomposition of matrix
### 3.2.5 QR decomposition Orthogonal matrix refers to the fact that the column vectors of the matrix are orthogonal to each other, and the length of each column vector is equal. QR decomposition is the product of dividing matrix A into an orthogonal matrix and an upper triangle matrix. MATLAB provides functions for Matrix QR decomposition. Table 3.7 describes the call formats and functions for Matrix QR decomposition. Table 3.7 matrix QR decomposition

Function Name 
Function 
[Q,R] = qr(A) 
Obtain the orthogonal matrix Q and the upper triangle arrays R. Q and R meet the requirements of a = QR. 
[Q,R,E] = qr(A) 
The transformation form matrix e of orthogonal matrix Q, upper triangle array R and unit matrix are obtained. The diagonal elements of R are arranged in descending order of size to meet the requirements of AE = QR. 
[Q,R] = qr(A,0) 
Produce the "economic size" decomposition of matrix 
[Q,R,E] = qr(A,0) 
E is used to sort the diagonal elements of R in descending order, and Q * r = a (:, E) 
R = qr(A) 
The decomposition of sparse matrix A generates only one upper triangle array R, satisfying the R'R ='A. This method reduces the loss of inner digital information when calculating a' *. 
[C,R] = qr(A,b) 
Twostep solution for sparse Least Squares: [C, R] = QR (a, B), x = r \ c 
R = qr(A,0) 
Economical decomposition for sparse matrix 
[C,R] = qr(A,b,0) 
Economical decomposition for sparse Least Squares 
[Q,R]= qrdelete(Q,R,j) 
Returns the QR decomposition of the new matrix after column J of matrix A is removed. 
[Q,R]= qrinsert(Q,R,j,x) 
In matrix A, the new matrix after vector X is inserted in column J for QR decomposition. If J is greater than the number of columns of A, it indicates that column X is inserted at the end of column. 
### 3.2.6 Schur Decomposition
Schur decomposition uses the Schur function. The call format of this function is:
①T = schur(A)
②T = schur(A,flag)
③[U,T] = schur(A,…)
The command line ①③ returns the orthogonal matrix U and Schur Matrix T, satisfying a = uTU '. If A has a complex feature root, the flag is 'compute'; otherwise, the flag is 'real '.
[Example 3.31] Schur Decomposition
In the command window, enter the following content to create the matrix K.
& Gt; k = magic (3); % generate Level 3 cube array
Perform Schur decomposition on the matrix K and input the following in the Command window:
& Gt; [U, T] = Schur (k) % Schur decomposition of matrix K
### 3.2.7 transformation of the diagonal matrix of the plural feature value and the real block feature value
Even a real array may have a complex number in its feature values. In actual use, we usually need to convert this pair of complex values to a real number (2x2. Function call format:
① [VC, DC] = rsf2csf (VR, Dr) % convert the Schuler form into the Schuler form
② [VR, Dr] = cdf2rdf (VC, DC) % convert the shul form into the shol form
[Example 3.32] transformation between the diagonal matrix of the complex feature value and the diagonal matrix of the real feature value
In the command window, enter the following content to create matrix B.
>> B=[5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9;4 5 6 7 8];
First, perform Schur decomposition on matrix B. In the command window, enter:
& Gt; [U, T] = Schur (B) % Schur decomposition of matrix B
Then convert the shol form into the shul form. In the command window, enter:
& Gt; [U, T] = rsf2csf (u, T) % The Schuler form is converted into the Schuler form
### 3.2.8 Generalized Singular Value Decomposition
MATLAB provides the gsvd function to perform Generalized Singular Value Decomposition on the matrix. The specific call format is:
①[U,V,X,C,S] = gsvd(A,B)
②[U,V,X,C,S] = gsvd(A,B,0)
③sigma = gsvd (A,B)
Among them, the function call format ① returns the matrix U and V, a common square matrix X, nonnegative diagonal matrix C and S, meeting a = uCX', B = VSX', C'C + s'S = I (I is the unit matrix ). The columns of A and B must be the same, and the number of rows can be different. Function call format ② and ① are basically the same, and ③ return the Generalized Singular Value sigma value.
[Example 3.33] Generalized Singular Value Decomposition
In the command window, enter the following content to create the matrices AO and D.
>> AO=[1 2 3 4 5 6 7 8;2 3 4 5 6 7 8 9;3 4 5 6 7 8 9 0]‘;
& Gt; D = magic (3); % generate Level 3 cube array
Perform Generalized Singular Value Decomposition on the matrix AO and input the following in the Command window:
& Gt; [U, V, X, C, S] = gsvd (Ao, d) % Generalized Singular Value Decomposition for Matrix AO
### Qz decomposition of feature Value Problems
MATLAB provides the qz function for qz decomposition of matrix feature values. The Calling format of this function is:
①[AA,BB,Q,Z,V] = qz(A,B)
②[AA,BB,Q,Z,V] = qz(A,B,flag)
In function call format ①, A and B are phalanx. The return results AA and BB are upper triangular arrays, Q and Z are orthogonal matrices or their column transformations, and V is feature vector arrays, QAZ = AA and QBZ = BB. Command Line ② generates the decomposition result determined by the flag. The flag value is 'compute', indicating the plural decomposition (default). The value is 'real', indicating the real number decomposition.
[Example 3.34] qz decomposition of feature Value Problems
In the command window, enter the following content to create the matrices A and B.
>> A=[1 2 3 4 5;5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9];
>> B=[5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9;4 5 6 7 8];
Perform qz decomposition on the feature values of matrix A and matrix B. In the command window, enter:
& Gt; [AA, BB, Q, Z, V] = qz (a, B) % of the qz decomposition of the feature values of matrix A and matrix B
### Decomposition in the form of haenberger
If the first subdiagonal line of matrix H is 0, H is the hessenberg matrix. If the Matrix is a symmetric matrix, its henberger form is a diagonal Triangle Matrix. MATLAB can convert the matrix into this form through similarity transformation. The specific call format is:
① H = Hess (a) returns the heenberger form of matrix.
② [P, H] = Hess (a) P is a matrix, satisfying the following conditions: a = php' and P = eye (SIZE ())
[Example 3.35] decomposition in the form of henberger
In the command window, enter the following content to create matrix.
>> A=[1 2 3 4 5;5 3 4 8 5;6 8 7 6 9;2 6 8 2 1;2 7 9 3 9;]
The heenberger form of matrix A can be entered in the Command window:
& Gt; [p, H] = Hess (a) % returns the henberger form of matrix
DT data
Contact information: [email protected]
Matlab programming and application seriesChapter 4 matrix operations (4)