Learn R Programming

vectools (version 0.2.0)

00_binary_operators: Binary Operators

Description

MatrixArray multiplication.

That is, multiplication of arrays of matrices.

Usage

# S4 method for MatrixArray,MatrixArray
%*%(x, y)
# S4 method for MatrixArray,matrix
%*%(x, y)
# S4 method for matrix,MatrixArray
%*%(x, y)

#cartesian a %{*}% b

#right padding #(for pre-multiplication) a %*[% b a %*{% b a %*|% b

#left padding #(for post-multiplication) a %]*% b a %}*% b a %|*% b

Arguments

a, b

Comformable matrices or MatrixArray objects. If pad operators are used, then the objects need to be conformable after padding.

x, y

Same as a and b.

Value

Column-wise and row-wise operators return a single matrix.

All other operators return a MatrixArray.

Note that the recycling order, is subject to change.

Details

The operators are designed for matrix array multiplication.

If there are two matrix arrays, each with ten matrices of the same size: And they are multiplied using the %*% operator, then each pair of matrices is multiplied using matrix multiplication, and a new matrix array is returned, of length ten.

It's possible to use a single matrix, in which case, its handled the same as a matrix array of length one. Each pair of matrices needs to be conformable. And if the lengths of the matrix arrays are different, then one matrix array is recycled. (But currently, the length longer one needs to a multiple of the length shorter one).

Often these operators can be used to apply transformation matrices to data. In which case, the transformation matrices will often have one more row or column than the data.

With the right-pad operator %*[%, an extra row of ones is rbinded to the right hand matrices before multiplication, and strips it off the result. Likewise, with the left-pad operator %]*%, an extra column of ones is cbinded to the left hand matrices before multiplication, and then strips it off.

There are a number of variations on this approach.

The operator %{*}% performs cartesian matrix array multiplication, which works out the cartesian product of both matrix arrays, and multiplies all of them. If the matrix arrays have length 10 and 20, then the resulting matrix array will have length 200, not 20.

The %*{% and %}*% operators also perform cartesian matrix array multiplication, but pad the right or left matrix arrays, respectively.

The %*|% and %|*% operators, perform column-wise and row-wise matrix array multiplication, with right or left padding.

The %*|% operator changes the initial padded matrix array on the right, into a second padded matrix array of column vectors. Likewise, the %|*% changes the initial padded matrix array on the left, into a second padded matrix array of row vectors.

Unlike the other operators, these operators will allow the data object to be a vector, and the result that's returned will be a single matrix.

Note that results from the %{*}% operator are dependent on parentheses.

Also, in post-multiplication with two or more transformations and left-padding of the left-most matrix array, we need to put all the transformations in parentheses, otherwise the result after the first multiplication will be non-conformable with the subsequent multiplications.

Column-wise and row-wise multiplication can be used with the eq.arot2 or eq.brot2 functions to define a polygon easily.

See Also

MatrixArray

Pre-Multiplication Transformation Matrices

Post-Multiplication Transformation Matrices

polyplot, cubplot

Examples

Run this code
# NOT RUN {
########################################
#refer to:
#Pre-Multiplication or Post-Multiplication
#for better examples
########################################
polyplot (sqps %]*% brot2 (pi / 8) )
# }

Run the code above in your browser using DataLab