Saturday 3 November 2012

1.3 ARRAY OPERATIONS

1.3 ARRAY OPERATIONS


Array operations refer to element-by-element arithmetic operations. Preceding
the linear algebraic matrix operations, * / \ ‘ , by a period (.) indicates an array
or element-by-element operation. Thus, the operators .* , .\ , ./, .^ , represent
element-by-element multiplication, left division, right division, and raising to
the power, respectively. For addition and subtraction, the array and matrix operations
are the same. Thus, + and .+ can be regarded as an array or matrix
addition.
If A1 and B1 are matrices of the same dimensions, then A1.*B1 denotes an array
whose elements are products of the corresponding elements of A1 and B1.
Thus, if
A1 = [2 7 6
8 9 10];
B1 = [6 4 3
2 3 4];
then
C1 = A1.*B1
results in
C1 =
12 28 18
16 27 40
An array operation for left and right division also involves element-by-element
operation. The expressions A1./B1 and A1.\B1 give the quotient of elementby-
element division of matrices A1 and B1. The statementD1 = A1./B1
gives the result
D1 =
0.3333 1.7500 2.0000
4.0000 3.0000 2.5000
and the statement
E1 = A1.\B1
gives
E1 =
3.0000 0.5714 0.5000
0.2500 0.3333 0.4000
The array operation of raising to the power is denoted by .^. The general
statement will be of the form:
q = r1.^s1
If r1 and s1 are matrices of the same dimensions, then the result q is also a matrix
of the same dimensions. For example, if
r1 = [ 7 3 5];
s1 = [ 2 4 3];
then
q1 = r1.^s1
gives the result
q1 =
49 81 125
© 1999
One of the operands can be scalar. For example,
q2 = r1.^2
q3 = (2).^s1
will give
q2 =
49 9 25
and
q3 =
4 16 8
Note that when one of the operands is scalar, the resulting matrix will have the
same dimensions as the matrix operand.

No comments:

Post a Comment