I want to use the tensorFunction in package RcppSimpleTensor (https://github.com/tlamadon/RcppSimpleTensor) to compute a 3 dimensional function like this one:
DGP <- function( x,y,z ) {
return((x + y - 5)^2 + (z-5)^2)
}
I create 3 vectors of values for x,y and z:
xdata <- seq(0,10,length=10)
ydata <- seq(0,10,length=10)
zdata <- seq(0,5,length=15)
I define the tensorFunction:
library(RcppSimpleTensor)
RcppVals <- tensorFunction( R[i,j,k] ~ (X[i] + Y[j] - 5)^2 + (Z[k] - 5)^2 )
RcppArray <- RcppVals(xdata,ydata,zdata)
But running this function gives an error “Error in tmpfun(X, Y, Z, k, j, i) : expecting a single value”
What am I doing wrong here?
This is now fixed in the main branch of the code,
best,
t.