Loading [MathJax]/jax/output/HTML-CSS/jax.js

Functionality for k-tensors

ktensor(S)
as.ktensor(M,coeffs)
is.ktensor(x)
# S3 method for class 'ktensor'
as.function(x,...)

Arguments

M,coeffs

Matrix of indices and coefficients, as in spray(M,coeffs)

S

Object of class spray

x

Object of class ktensor

...

Further arguments, currently ignored

Details

A k-tensor object S is a map from Vk to the reals R, where V is a vector space (here Rn) that satisfies multilinearity:

S(v1,,avi,,vk)=aS(v1,,vi,,vk)

and

S(v1,,vi+vi,,vk)=S(v1,,vi,,xv)+S(v1,,vi,,vk).

Note that this is not equivalent to linearity over Vnk (see examples).

In the stokes package, k-tensors are represented as sparse arrays (spray objects), but with a class of c("ktensor", "spray"). This is a natural and efficient representation for tensors that takes advantage of sparsity using spray package features.

Function as.ktensor() will coerce a k-form to a k-tensor via kform_to_ktensor().

Value

All functions documented here return a ktensor object except as.function.ktensor(), which returns a function.

References

Spivak 1961

Author

Robin K. S. Hankin

Examples


as.ktensor(cbind(1:4,2:5,3:6),1:4)
#> A linear map from V^3 to R with V=R^6:
#>            val
#>  4 5 6  =    4
#>  3 4 5  =    3
#>  2 3 4  =    2
#>  1 2 3  =    1


## 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
#> [1] 2.220446e-16

## Note that multilinearity is different from linearity:
r1*f(E1) + r2*f(E2) - f(r1*E1 + r2*E2)  # not small!
#> [1] -0.4413777