Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does operator "dot" (.) mean?

Given the code :

 A = [1 2 3; 3 2 1]  B = A.^2 

The output :

B =       1     4     9      9     4     1 

But if I do this : B = A^2

The output is :

Error using  ^  Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead. 

What does the operator . do exactly ?

like image 361
JAN Avatar asked Jun 02 '12 05:06

JAN


People also ask

What does dot mean in programming?

In general, dot notation tells Python to look inside the space that is before the dot for code to execute. You can use dot notation to access the specific version of a certain function that is defined in a different class or a different module.

What does the dot operator do in C?

operator in C/C++ The dot (.) operator is used for direct member selection via object name. In other words, it is used to access the child object.

What does the dot in Matlab mean?

dot(A,B,1) treats the columns of A and B as vectors and returns the dot products of corresponding columns. dot(A,B,2) treats the rows of A and B as vectors and returns the dot products of corresponding rows.

What is the use of 2 A dot operator?

It is also known as separator or period or member operator. It is used to separate a variable and method from a reference variable.


2 Answers

The dot itself is not an operator, .^ is.

The .^ is a pointwise¹ (i.e. element-wise) power, as .* is the pointwise product.

.^ Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. The sizes of A and B must be the same or be compatible.

C.f.

  • "Array vs. Matrix Operations": https://mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
  • "Pointwise": http://en.wikipedia.org/wiki/Pointwise
  • "Element-Wise Operations": http://www.glue.umd.edu/afs/glue.umd.edu/system/info/olh/Numerical/Matlab_Matrix_Manipulation_Software/Matrix_Vector_Operations/elementwise

¹) Hence the dot.

like image 180
kay Avatar answered Sep 27 '22 00:09

kay


There is a whole page in the MATLAB documentation dedicated to this topic: Array vs. Matrix Operations. The gist of it is below:

MATLAB® has two different types of arithmetic operations: array operations and matrix operations. You can use these arithmetic operations to perform numeric computations, for example, adding two numbers, raising the elements of an array to a given power, or multiplying two matrices.

Matrix operations follow the rules of linear algebra. By contrast, array operations execute element by element operations and support multidimensional arrays. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are unnecessary.

like image 44
Dev-iL Avatar answered Sep 26 '22 00:09

Dev-iL