# NOT RUN {
ktensor(rspray(4,powers=1:4))
as.ktensor(cbind(1:4,2:5,3:6),1:4)
## Test multilinearity:
k <- 4
n <- 5
u <- 3
## Define a randomish k-tensor:
S <- ktensor(spray(matrix(1+sample(u*k)%%n,u,k),seq_len(u)))
## And a random point in V^k:
E <- matrix(rnorm(n*k),n,k)
E1 <- E2 <- E3 <- E
x1 <- rnorm(n)
x2 <- rnorm(n)
r1 <- rnorm(1)
r2 <- rnorm(1)
# change one column:
E1[,2] <- x1
E2[,2] <- x2
E3[,2] <- r1*x1 + r2*x2
f <- as.function(S)
r1*f(E1) + r2*f(E2) -f(E3) # should be small
## Note that multilinearity is different from linearity:
r1*f(E1) + r2*f(E2) - f(r1*E1 + r2*E2) # not small!
# }
Run the code above in your browser using DataLab