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

Arguments

x

numeric or character matrix.

y

numeric or character matrix.

Value

matrix.

Functions

  • %mx%: binary operator.

References

Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086

See also

Other matrix algebra: mxdet(), mxinv(), mxtr()

Examples

### 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)"