In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "MATLAB how to achieve matrix operations", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "MATLAB how to achieve matrix operations" this article.
# 3.1.5 Matrix function
MATLAB provides a wealth of functions to implement a variety of matrix operations, which will be described step by step below. Due to the lack of space, there will be no mathematical explanation. Table 3.1 shows the common matrix operation functions and the corresponding functional descriptions of the functions.
Table 3.1 Common matrix operation functions
Function name function det (X) calculates the determinant of the square matrix
Rank (X) calculates the rank of the matrix and obtains the maximum side length of the square matrix in which the determinant is not zero.
The trace b of trace (X) matrix A, that is, the sum of diagonal elements of A.
Expm (A) uses the Pade approximation algorithm to calculate eA, which is an internal function, and An is a square matrix.
Expm1 (A) calculates e ^ A using the same algorithm as the M file and the internal function.
Expm2 (A) uses Taylor series to calculate e ^ A
Expm3 (A) calculates e ^ A using eigenvalues and Eigenvectors.
Logm (X) calculates the logarithm of matrix X, which is the inverse function of expm (X).
The function fun specified by funm (X, fun) calculates the function matrix of square matrix X.
Sqrtm (X) calculates the square root of the matrix A, A1, which is equivalent to X*X=A, and calculates X.
Polyvalm (P, X) calculates the value of the polynomial according to the matrix operation rules. Where P is the polynomial coefficient vector, the square matrix X is the polynomial variable, and the return value is the polynomial value.
Inv (X) calculates the inverse matrix of the matrix. When the det (X) of the square matrix X is not equal to zero, the inverse matrix Xmuri 1 exists. X is multiplied by Xmur1 as the unit matrix.
Pinv (X) solves the pseudo-inverse B of matrix X
Norm (X, ref) solves the different norms of a matrix or vector, and ref specifies the type of solving norm.
Cond (X, p) returns the condition number of the p-norm of a matrix X. If pairing 2 corresponds to 2 norm
[vPerry d] = eig (X) calculates the eigenvalues and Eigenvectors of the matrix. If the equation Xv=vd has a nonzero solution, then v is the eigenvector and d is the eigenvalue.
Diag (X) produces diagonal matrices of X matrices
Lu (X) square matrix is decomposed into the product of a quasi-lower triangular square matrix and an upper triangular square matrix. L is a lower triangular matrix, two rows must be exchanged in order to become a real lower triangular matrix.
The matrix X of order qr (X) m × n is decomposed into the product of an orthogonal matrix Q and an upper triangular matrix r of the same order as X. The side length of the square matrix Q is the smaller of the n and m of the matrix X, and the value of its determinant is 1.
The matrix X of order X = svd (X) m × n is decomposed into the product of three matrices, where uther v is an orthogonal matrix of order n × n and order m × m, s is a diagonal matrix of order m × n, and the elements on the diagonal line are the singular values of matrix X, whose length is the smaller of n and m.
Note: 1. When the matrix is rectangular, the equations AX=I and XA=I have at least one non-solution, then the pseudo inverse of A can represent the inverse of the matrix to some extent. If An is a nonsingular matrix, then pinv (A) = inv (A).
In the above table, although 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 calculating inv (a). It is expressed by the condition number (the function of finding the condition number is cond). The larger the condition number, the lower the accuracy of the solution. MATLAB will warn: "the condition number is too large, the result may not be accurate."
# 3.1.6 Matrix transpose
The operator of matrix transpose is "'" and "A'" denotes the transpose of matrix A. if the element of matrix An is real, it is the same as the transpose of matrix in linear algebra. If An is a complex matrix, then the element transposed by An is composed of the conjugate complex number of the corresponding element A.
"A.'" Represents the transpose of array A, if the array An is a complex array, it only represents the transpose of the complex matrix array, without the conjugate operation of the matrix or array.
[example 3.17] Matrix and array transpose operation.
Enter the following in the command window to generate matrix AA and matrix A1:
> > AA=magic (3);% generate a third-order magic square matrix
> > A1=eye (3);% generate unit diagonal matrices of order 3
The complex matrix is composed of An and A1, and enter in the command window:
> > x3=AA+A1*i% consists of complex matrix of AA and A1
Generate the following complex matrix x3:
X3 = 8.0000 + 1.0000i 1.0000 6.00003.0000 5.0000 + 1.0000i 7.00004.0000 9.0000 2.0000 + 1.0000i
① if the matrix AA is transposed, you can enter:
> > AA'% transpose real matrix
The matrix AA is transposed as follows:
Ans = 8 3 41 5 96 7 2
If ② transposes the complex matrix x3, you can enter:
> x3'% transpose complex matrix
The transposed complex matrix is as follows:
Ans = 8.0000-1.0000i 3.0000 4.00001.0000 5.0000-1.0000i 9.00006.0000 7.0000 2.0000-1.0000i
If ③ performs array transpose operation on complex matrix x3, you can enter:
> x3.'% perform array transpose operation on complex matrix
After the transposition operation is performed, it is as follows:
Ans = 8.0000 + 1.0000i 3.0000 4.00001.0000 5.0000 + 1.0000i 9.00006.0000 7.0000 2.0000 + 1.0000i
# 3.1.7 Mathematical functions of matrices and arrays
In the MATLAB basic mathematical function library, there are many basic mathematical function operations that can calculate the matrix or array. The call format and function description of each function is shown in Table 3.2.
Table 3.2 basic functions
Function name meaning function name meaning abs absolute value or complex modulus Rat rational approximate sqrt square root Mod module except cosine real real part Round4 rounding to integer imag imaginary part Fix to nearest 0 rounding conj complex conjugate Floor to nearest-∞ rounding sin sine Ceil to nearest + ∞ rounding cos cosine symbolic function tan tangent Rem residue asin arc sine Exp natural index acos inverse cosine Log natural logarithm atan inverse tangent Log10 logarithmic atan2 fourth quadrant inverse tangent pow22 power sinh hyperbolic sine Bessel Bessel function cosh hyperbolic cosine Gamma gamma function tanh hyperbolic tangent
[example 3.18] the use of array arithmetic functions.
First create the following array B in the MATLAB workspace:
B = [5 3 4 8 5 x 6 8 7 6 9 x 2 6 8 2 1 x 2 7 9 3 9 4 5 6 7 8]
Readers can enter the following command in the MATLAB command line window, the operation results of different array arithmetic functions:
Y1=sin (B)% to find the sine of the array
Finding the square root of an array with y2=sqrt (y1)%
Finding the imaginary part of an array by y3=imag (y2)%
[example 3.19] take the example above, round the array Y1.
Enter the following command in the MATLAB command line window to round up the sinusoidal function of array B differently:
B1=floor (y1)% is rounded to the nearest-∞
B2=ceil (y1)% rounded to the nearest + ∞
B3=round (y1) 4 rounding 5 to an integer
B4=fix (y1)% rounded to the nearest 0
These are all the contents of the article "how to implement Matrix Operation in MATLAB". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.