as.function.spray | R Documentation |
Coerce a spray object to a function
## S3 method for class 'spray'
as.function(x,...)
x |
spray object, interpreted as a multivariate polynomial |
... |
Further arguments, currently ignored |
Returns a function; this function returns a numeric vector.
Coercion is possible even if some indices are zero or negative. The function is not vectorized in the arity of its argument.
Robin K. S. Hankin
(S <- spray(matrix(1:6,3,2),1:3))
(f <- as.function(S))
f(2:3) == 3*2^3*3^6 + 2*2^2*3^5 + 1*2^1*3^4 # should be TRUE
S1 <- spray(matrix(sample(-2:2,replace=TRUE,21),ncol=3),rnorm(7),addrepeats=TRUE)
S2 <- spray(matrix(sample(-2:2,replace=TRUE,15),ncol=3),rnorm(5),addrepeats=TRUE)
f1 <- as.function(S1)
f2 <- as.function(S2)
f3 <- as.function(S1*S2)
x <- 4:6
f1(x)*f2(x)-f3(x) # should be zero
# coercion is vectorized:
f1(matrix(1:33,ncol=3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.