This series of tutorials comes from the publication of the "Matlab-based 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].
### 3.1.5 Matrix Functions MATLAB provides a wide range of functions to implement various operations on the matrix. The following section describes them step by step. Due to the length of the article, we will not explain it in mathematics. Table 3.1 describes commonly used matrix calculation functions and functions. Table 3.1 Common matrix calculation functions
|
Function Name |
Function |
det(X) |
Calculate the matrix Index |
rank(X) |
Calculate the rank of the matrix, and obtain the edge length of the maximum square matrix with a non-zero determinant. |
trace(X) |
Trace B of matrix A, that is, the sum of diagonal elements of |
expm(A) |
Use the pade approximation algorithm to calculate the EA. This is an internal function. A is a square matrix. |
expm1(A) |
Calculate e ^ A using an algorithm with the same M file and internal functions |
expm2(A) |
Calculate e ^ A using the Taylor series |
expm3(A) |
Using feature values and feature vectors to calculate e ^ |
logm(X) |
Calculates the logarithm of matrix X, which is an inverse function of expm (X ). |
funm(X, fun) |
The specified function fun calculates the Function Matrix of matrix X. |
sqrtm(X) |
Calculates the square root of matrix A A1/2, which is equivalent to x * x =. |
polyvalm(P, X) |
Calculate the polynomial value according to matrix calculation rules. P is a polynomial coefficient vector, X is a polynomial variable, and the return value is a polynomial value. |
inv(X) |
Calculate the inverse matrix, when the det (x) of the matrix X is not equal to zero, the inverse matrix X-1 exists. X is multiplied by the X-1 as a matrix of units. |
pinv(X) |
Returns the pseudo-inverse B of matrix X. |
norm(X , ref) |
The ref specifies the type of the matrix or vector to be solved. |
cond(X, p) |
Returns the condition number of the P-norm of matrix X. If P = 2 corresponds to 2 norm |
[v,d]=eig(X) |
Calculate the matrix feature value and feature vector. If the equation XV = VD has a non-zero solution, V is the feature vector and D is the feature value. |
diag(X) |
Generate a diagonal array of X Matrix |
[l,u]=lu(X) |
The square matrix is decomposed into the product of a quasi-bottom Triangle Matrix and an upper triangle matrix. L quasi-bottom triangle array. Two lines must be exchanged to become the real bottom triangle array. |
[q,r]=qr(X) |
M × n order matrix X is decomposed into an orthogonal matrix Q and the product of an upper triangle matrix R of the same order as X. The side length of the square matrix Q is smaller than N and M of matrix X, and the value of the determinant is 1. |
[u,s,v]=svd(X) |
M×n order matrix X is decomposed into the product of the three matrices, where U and V are n×n and m×m order orthogonal phalanx, S is a diagonal matrix of order m × n. The elements on the diagonal line are the Singular Values of matrix X. The length of S is smaller than N and M. |
Note: 1. when the Matrix is a long square matrix, the equation AX = I and XA = I have at least one unsolvable solution. In this case, the pseudo-inverse of a can represent the inverse of the Matrix to some extent. If a is a non-singular matrix, then pinv (A) = inv ().
- In the preceding table, if det (A) = 0 or det (a) is not equal to zero but the value is very small and close to zero, the accuracy of the solution is relatively low when inv (a) is calculated, it is expressed by the number of conditions (the function for determining the number of conditions is Cond). The higher the number of conditions, the lower the solution accuracy. MATLAB will warn: "The number of conditions is too large, and the result may be inaccurate ".
### 3.1.6 matrix transpose
The matrix transpose operator is "'", and "A'" indicates the transpose of matrix A. If the element of matrix A is a real number, it is the same as the transpose of the matrix in linear algebra. If a is a complex matrix, the elements after a transpose are composed of the complex numbers of the elements corresponding to.
"A. '" indicates the transpose of array A. If array A is a plural array, it only indicates the transpose of the plural matrix array, and does not perform the matrix or array concatenation operation.
[Example 3.17] matrix and array transpose operations.
In the command window, enter the following content to generate the matrix AA and matrix A1:
& Gt; AA = magic (3); % generate Level 3 cube array
& Gt; a1 = eye (3); % generates a 3-level unit diagonal Array
A complex matrix composed of a and A1. In the command window, enter:
& Gt; X3 = AA + A1 * I % a complex matrix consisting of AA and A1
Generate the following complex matrix X3:
x3 =<br/>8.0000 + 1.0000i 1.0000 6.0000<br/>3.0000 5.0000 + 1.0000i 7.0000<br/>4.0000 9.0000 2.0000 + 1.0000i
① If matrix AA is transposed, enter the following in the Command window:
& Gt; AA' % transpose operation on the Real Matrix
After matrix AA is transposed as follows:
ans =<br/>8 3 4<br/>1 5 9<br/>6 7 2
② If you perform transpose operation on the complex matrix X3, enter the following in the Command window:
& Gt; X3 '% transpose operation on the Complex Matrix
The transpose complex matrix is as follows:
ans =<br/>8.0000 - 1.0000i 3.0000 4.0000<br/>1.0000 5.0000 - 1.0000i 9.0000<br/>6.0000 7.0000 2.0000 - 1.0000i
③ If you perform array transpose operation on the complex matrix X3, enter the following in the Command window:
& Gt; x3.' % returns an array transpose operation to the complex matrix.
The transpose operation is as follows:
ans =<br/>8.0000 + 1.0000i 3.0000 4.0000<br/>1.0000 5.0000 + 1.0000i 9.0000<br/>6.0000 7.0000 2.0000 + 1.0000i
### 3.1.7 mathematical functions of Matrices and Arrays
There are also many basic mathematical function operations in the MATLAB basic mathematical function library that can calculate matrices or arrays. For the call formats and function descriptions of each function, see Table 3.2.
Table 3.2 Basic functions
Function Name |
Description |
Function Name |
Description |
abs |
Absolute value or plural Modulus |
Rat |
Rational Number Approximation |
sqrt |
Square Root |
Mod |
Modulo division Remainder |
real |
Real-time |
Round |
4 rounded to an integer |
imag |
Virtual part |
Fix |
Rounded to 0 |
conj |
Combination of multiple numbers |
Floor |
Rounded to nearest-∞ |
sin |
Sine |
Ceil |
Rounded to nearest + ∞ |
cos |
Cosine |
Sign |
Symbol Functions |
tan |
Tangent |
Rem |
Returns the remainder of the remainder. |
asin |
Arcsin |
Exp |
Natural Index |
acos |
Arccosine |
Log |
Natural logarithm |
atan |
Arc tangent |
log10 |
Base-10 logarithm |
atan2 |
Quadrant arc tangent |
pow2 |
Power of 2 |
sinh |
Hyperbolic sine |
Bessel |
Besell Function |
cosh |
Hyperbolic cosine |
Gamma |
Gamma functions |
tanh |
Hyperbolic tangent |
|
|
[Example 3.18] use of array arithmetic functions.
First, create the following array B in the MATLAB Workspace:
>> 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]
You can enter the following command in the MATLAB command line window to calculate different array arithmetic functions:
& Gt; Y1 = sin (B) % returns the sine of the array
& Gt; y2 = SQRT (Y1) % to obtain the struct of the array
& Gt; Y3 = imag (Y2) % to obtain the virtual part of the array
[Example 3.19] connect to the instance and round the array Y1.
In the MATLAB command line window, enter the following command to perform different round operations on the calculation results of the sine function of array B:
& Gt; b1 = floor (Y1) % rounded to nearest-∞
& Gt; b2 = Ceil (Y1) % rounded to nearest + ∞
& Gt; B3 = round (Y1) % 4 homes 5 to Integers
& Gt; B4 = fix (Y1) % rounded up to 0
DT data
Contact information: [email protected]
Matlab programming and application series-Chapter 1 matrix operations (2)