DOTTIMES Element-wise Multiplication Operator
Section: Mathematical Operators
Usage
Multiplies two numerical arrays (elementwise). There are two forms for its use, both with the same general syntax:y = a .* b
where a
and b
are n
-dimensional arrays of numerical type. In the
first case, the two arguments are the same size, in which case, the
output y
is the same size as the inputs, and is the element-wise
product of a
and b
. In the second case, either a
or b
is a scalar,
in which case y
is the same size as the larger argument,
and is the product of the scalar with each element of the other argument.
The rules for manipulating types has changed in FreeMat 4.0. See typerules
for more details.
Function Internals
There are three formulae for the dot-times operator, depending on the sizes of the three arguments. In the most general case, in which the two arguments are the same size, the output is computed via:
If a
is a scalar, then the output is computed via
On the other hand, if b
is a scalar, then the output is computed via
Examples
Here are some examples of using the dottimes operator. First, a straight-forward usage of the.*
operator. The first example
is straightforward:
--> 3 .* 8 ans = 24
Next, we multiply a scalar by a vector of values:
--> 3.1 .* [2,4,5,6,7] ans = 6.2000 12.4000 15.5000 18.6000 21.7000
With complex values
--> a = 3 + 4*i a = 3.0000 + 4.0000i --> b = a .* 2 b = 6.0000 + 8.0000i
Finally, the element-wise version:
--> a = [1,2;3,4] a = 1 2 3 4 --> b = [2,3;6,7] b = 2 3 6 7 --> c = a .* b c = 2 6 18 28