Home >Common Problem >What is the difference between .* and * in matlab
When performing operations between matrices, the meanings of ".*" and "*" are different: "*" is matrix multiplication, and the two matrices must satisfy that the number of columns of the left matrix is equal to that of the right matrix The number of rows; ".*" is the dot multiplication operation, which refers to the multiplication operation of corresponding elements in the two matrices.
The operating environment of this article: windows7 system, Dell G3 computer, matlab R2020a version. The difference between
.*” and “*”:
is performing operations between numbers There is no difference between ".*
" and "*
", both represent ordinary multiplication operations. Example: m = 2, n = 3, m.*n = 6 , m*n = 6.
The meaning of ".*
" and "*
" when performing operations between matrices is It's different. Suppose a and b represent two matrices, a*b represents matrix multiplication of matrix a and matrix b, a.*b represents the multiplication of elements in matrix a and elements in matrix b in sequence, The result obtained will be used as the elements at the same position in the new matrix.
*
is matrix multiplication. If A is an m*n-dimensional matrix, B is n*p dimensional matrix, then A*B is an m*p dimensional matrix
.*
is a dot multiplication operation, which refers to the multiplication of corresponding elements in the two matrices. It is required that the dimensions of the two matrices are the same
MATLAB uses a special symbol to distinguish matrix operations and array operations. When you need to distinguish between the two, put the dot before the symbol to indicate that this is an array operation (for example, .*). The lines give some common array and matrix operations.
Array addition: A B, array addition and matrix addition Same.
Array subtraction: A-B, array subtraction and matrix subtraction are the same.
Array multiplication: A.*B, A and The elements of B are multiplied one by one. The two arrays must have the same shape, or one of them is a scalar.
Matrix multiplication: A*B, matrix multiplication of A and B, The number of columns of A must be the same as the number of rows of B.
Right division of array: A./B, the elements of A and B are divided one by one: A(i,j)/ B(i,j) The two arrays must have the same shape, or one of them is a scalar.
Array left division: A.\B, the elements of A and B correspond one by one Division: B(i,j)/A(i,j) The two arrays must have the same shape, or one of them is a scalar.
Matrix right division: A/ B matrix division, equivalent to A*inv(B), inv(B) is the inverse matrix of B.
Matrix left division: A\B matrix division, equivalent to inv (B)*A, inv(A) is the inverse matrix of A.
Array exponential operation: A.^B, the elements in AB perform the following operations one by one: A(i, j)^B(i,j), A(i,j)/B(i,j) must have the same shape, or one of them must be a scalar.
If you want to read more related articles, please visit PHP中文网! !
The above is the detailed content of What is the difference between .* and * in matlab. For more information, please follow other related articles on the PHP Chinese website!