Multiplies two numeric
or character
matrices, if they are conformable. If one argument is a vector, it will be promoted to either a row or column matrix to make the two arguments conformable. If both are vectors of the same length, it will return the inner product (as a matrix
).
mx(x, y)
x %mx% y
numeric
or character
matrix.
numeric
or character
matrix.
matrix
.
x %mx% y
: binary operator.
Guidotti E (2022). "calculus: High-Dimensional Numerical and Symbolic Calculus in R." Journal of Statistical Software, 104(5), 1-37. doi:10.18637/jss.v104.i05
### numeric inner product
x <- 1:4
mx(x, x)
#> [,1]
#> [1,] 30
### symbolic inner product
x <- letters[1:4]
mx(x, x)
#> [,1]
#> [1,] "(a) * (a) + (b) * (b) + (c) * (c) + (d) * (d)"
### numeric matrix product
x <- letters[1:4]
y <- diag(4)
mx(x, y)
#> [,1] [,2] [,3] [,4]
#> [1,] "(a) * 1" "(b) * 1" "(c) * 1" "(d) * 1"
### symbolic matrix product
x <- array(1:12, dim = c(3,4))
y <- letters[1:4]
mx(x, y)
#> [,1]
#> [1,] "1 * (a) + 4 * (b) + 7 * (c) + 10 * (d)"
#> [2,] "2 * (a) + 5 * (b) + 8 * (c) + 11 * (d)"
#> [3,] "3 * (a) + 6 * (b) + 9 * (c) + 12 * (d)"
### binary operator
x <- array(1:12, dim = c(3,4))
y <- letters[1:4]
x %mx% y
#> [,1]
#> [1,] "1 * (a) + 4 * (b) + 7 * (c) + 10 * (d)"
#> [2,] "2 * (a) + 5 * (b) + 8 * (c) + 11 * (d)"
#> [3,] "3 * (a) + 6 * (b) + 9 * (c) + 12 * (d)"