Times {lazy.symbolic} | R Documentation |
Elementwise Multiplication of Two or More Symbolic Vectors/Matrices
Times(..., simplify = 1, debug = 0)
... |
Symbolic matrices or vectors to be multiplied elementwise. |
simplify |
= 0 not to use Simplify nor remove_paren |
debug |
= 1 to print intermediate result |
Let v be a vector of length lv, and M, a matrix of the size nr x nc.
If lv <= nr*nc, v*M and M*v exist.
When (nr*nc %% lv) == 0, there will be no warning but
otherwise, you will be warnded.
If lv > nr*nc, v*M nor M*v do not exits. It causes error.
When exits, v*M = M*v = matrix( c(M)*v, nrow(M), ncol(M) ).
v%*%M and M%*%v exist if v can be promoted to either a row or column
vector to make the two arguments conformable.
vec1*vec2 always exists and
length(vec1*vec2)=max(length(v1),length(v2)) .
If the arguments are super matrices with SMdim attributes, the final result will have an appropriate SMdim attribute.
A character matrix
Times("a",2)
Times("a+b",2)
Times("c","a+b")
M32 <- demomat(3,2, root="a")
v2 <- 1:2; v3 <- 1:3; v4 <- 1:4; v9 <- 1:9
vm2 <- matrix(v2,2)
vm3 <- matrix(v3,3)
# matrix times vector with conformable length
# This seems to be what we want.
Times(v3,M32)
Times(M32,v3)
# matrix times vector with conformable length
# This may not be what we want.
Times(v2,M32)
Times(M32,v2)
# %*% operator promotes vectors to matrices.
Print(v3%*%demomat(3,2), demomat(3,2)%*%v2)
# When langth(vec) < length(c(mat)),
# with warning
Times(v4,M32)
Times(M32,v4)
# When langth(vec) > length(c(mat)),
# ERROR
# Times(v9,M32)
# Times(M32,v9)