What does operator “dot” (.) mean?

Question:

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 ?

Answer:

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. A and B must have the same size, unless one of them is a scalar.

C.f.

¹) Hence the dot.


原文地址:https://www.cnblogs.com/vigorz/p/10499121.html