Updated March 14, 2023
Definition of Matlab Dot
MATLAB DOT function is used for getting the dot product of specific inputs. Input data can be scalar, vector, matrices, or multidimensional arrays. If the input arguments are scalar in nature then the dot function give the scalar dot product. Let A and B be vectors and to get dot product using dot function then they must have the same length. And if input arguments are matrices or multidimensional arrays, then they must have the same size. This function is used for the dot product of real vectors as well as dot product of real vectors.
Syntax:
C = dot(A,B)
C = dot(A,B,dim)
How does Matlab Dot do?
This function is used for calculating dot product of input arguments. The input arguments can be scalar, vector, real or complex values. And it can be in any format like matrices or multidimensional arrays. There are simple steps to calculating dot product and the steps are as follows.
Step 1: – Load the data into a variable or into an array
Step 2: – Use dot function with proper syntax calculating dot product of
Input data.
Step 3: – Execute the code to run the program.
Examples
Let us see the example related to the dot function.
Example #1
In this example, we calculate the dot product of the multidimensional arrays by using the dot function. so first we load the input data that is multidimensional arrays ‘R’ and ‘P’ respectively. ‘R = cat(3,[1 1;1 1],[12 13;14 15],[6 7;8 9]) ;’ this line load the multidimensional arrays ‘R’ and ‘P = cat(3,[2 2;2 2],[0 1;2 3],[14 5; 6 17]) ;’ this line load the multidimensional arrays ‘P’. If R and P are matrices or multidimensional arrays, then they must have the same size. After that, we used the dot function to calculate the dot product of the multidimensional arrays. ‘Q = dot(R,P,3)’ this syntax of the dot function is used to calculate the dot product of the multidimensional arrays. Here 3 indicates the third dimension (dim = 3) to calculate the dot product of R and P along the dimension. The result is stored in variable Q. Then we execute the code to get output.
Code:
clc;
0 1;2 3],[14 5; 6 17]);
clear all;
close all;
R = cat(3,[1 1;1 1],[12 13;14 15],[6 7;8 9]);
P = cat(3,[2 2;2 2],[
Q = dot(R,P,3)
Output:
Example #2
Let us see another example related to the dot function. In this example, we calculate the dot product of the complex number by using the dot function. So first we load the input data that are complex numbers into variables ‘P’ and ‘Q’ respectively. “P = [3+i 4-i 5+i -2-i];” this line load the complex number in to variables P and ‘Q = [4-i 4-2i 3+2i 4+3i]; this line load the complex number in to variables Q. After that, we used the dot function to calculate the dot product of the complex number. ‘R = dot(P,Q)’ this syntax of the dot function is used to calculate the dot product of the complex number. The result is stored in variable R. Then we execute the code to get output.
Code:
clc;
clear all;
close all;
P = [3+i 4-i 5+i -2-i];
Q = [4-i 4-2i 3+2i 4+3i];
R = dot(P,Q)
Output:
Example #3
Let us see one more example related to the dot function. In this example, we calculate the dot product of the matrix by using the dot function. So first we load the input data that is number into matrix ‘P’ and ‘Q’ respectively. “P = [9 8 7;6 5 4;2 3 1];” this line load the number in to matrix P and ‘Q = [3 8 5;1 1 1;3 2 1] ;’ this line load the number in to matrix Q. After that, we used the dot function to calculate the dot product of the matrix. ‘R = dot(P,Q)’ this syntax of the Matlab dot function is used to calculate the dot product of the matrix. The result is stored in matrix R. Then we execute the code to get output.
Code:
clc;
clear all;
close all;
P = [9 8 7;6 5 4;2 3 1];
Q = [3 8 5;1 1 1;3 2 1];
R = dot(P,Q)
Output:
Conclusion
In this article, we saw the concept of the Matlab dot function. Basically, this function is used for calculating dot product of input arguments. Then saw syntax related to the Matlab dot function and how it is used in Matlab code. Also, we saw some examples related to the Matlab dot function.
Recommended Articles
This is a guide to Matlab Dot. Here we discuss the Definition of Matlab Dot, How to do Matlab Dot with different examples with code. You may also have a look at the following articles to learn more –