Matrix and Array Operators

advertisement
Matrix and Array Operators1
For the following, assume we have two square matrices A and B (dimensions are
2 rows by 2 columns) and a scalar, S (dimension is 1 row by 1 column):
a11 a12 
b11 b12 
A  
 B  
 S  s11
a
a
b
b
 21 22
 21 22
Matrices
Matrix operators follow the rules of linear algebra

Addition and Subtraction
For matrices of equal dimensions: A + B or A - B
Multiplication
Two matrices can be multiplied together only if the number of columns in the
first matrix equals the number of rows in the second matrix
i.e. X is a 15x15 and Y is a 15x7; X*Y is valid, but not Y*X
Any matrix can be multiplied by a scalar: S * A = A * S
For square matrices, A*B and B*A are valid, but yield different results:
a b  a b
a b  a b 
A * B   11 11 12 21 11 12 12 22 
a21b11  a22b21 a21b12  a22b22
b a  b a
b a  b a 
B * A   11 11 12 21 11 12 12 22 
b21a11  b22a21 b21a12  b22a22
Division

For the same sized matrices:
A / B = A * B-1
Division by a scalar is only defined if the scalar is in the denominator:
A / S is valid, S / A is not valid
1
Adapted from: Jordan, M. 2007: MR2020 MATLAB Course Notes and Pratap, R. 2006: Getting
Started with MATLAB 7: A Quick Introduction for Scientists and Engineers
Arrays
Array operators perform term-by-term calculations.
Addition and Subtraction
No difference between array and matrix addition and subtraction. The matrices
or vectors must be of equal dimension (same size).
Multiplication
You can multiply the elements of two same-sized matrices using the array
operator .*
A .* B
When multiplying by a scalar, it is always term by term, so there is no difference
in * or .* operators.
A .* S = A * S
Division
You can divide the elements of two same-sized matrices using the array
operator ./
A ./ B
Array division with a scalar is defined when the scalar is either in the numerator
or denominator.
Scalar in the denominator:
There is no difference in the / or ./ operators.
A ./ S = A / S
Scalar in the numerator:
This IS a difference in operators; the ./ MUST be used to compute term by
term division.
S ./ A
Download