[DPRG] Matlab .* operator
Subject: [DPRG] Matlab .* operator
From: Paul Bouchier
paul.bouchier at gmail.com
Date: Mon Aug 11 05:26:23 CDT 2014
Ron, please pass this information to Will, as he asked the question.
At the Matlab talk on Saturday, Will asked why my sample code contained
something like: timeSecs = timeSecs .* (1.0e3), yet the slides showed an
example like 3 * A, where A could be a matrix. By experiment, we found that
the two constructs (* and .*) produced the same result.
The answer is found in the Matlab documentation. The .* operator expands a
scalar to the same size as the matrix and then multiplies each element by
the scalar. If one element of A * B is scalar, it is defined to work the
same as A .* B, doing elementwise multiplication after scalar expansion.
At a deeper level, the .* and ./ operators do elementbyelement
multiplication/division, whereas the * and / operators do matrix
multiplication/division.
Thanks to those hardy folks who braved the heat to try & wrap their heads
around Matlab/Octave. I'll get the slides and sample code up on the DPRG
tutorials page shortly, but email me if you want the slides meantime.
Paul
*References*
From
http://www.mathworks.com/help/matlab/matlab_prog/arrayvsmatrixoperations.html
Introduction
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.
Array OperationsArray operations work on corresponding elements of arrays
with equal dimensions. For vectors, matrices, and multidimensional arrays,
both operands must be the same size. Each element in the first input gets
matched up with a similarly located element from the second input.
If one operand is a scalar and the other is not, then MATLAB applies the
scalar to every element of the other operand. This property is known as *scalar
expansion* because the scalar expands into an array of the same size as the
other input, then the operation executes as it normally does with two
arrays.
If at least one input is scalar, then A*B is equivalent to A.*B and is
commutative. (ref http://www.mathworks.com/help/matlab/ref/mtimes.html)
 next part 
An HTML attachment was scrubbed...
URL: http://list.dprg.org/pipermail/dprglist/attachments/20140811/f1c2ad52/attachment.html
More information about the DPRG mailing list
