# NOT RUN {
p <- mp("(x - 1)^2")
(f <- as.function(p))
f(1)
f(seq(0, 2, .1))
p <- mp("x + 3 x y + z^2 x")
(f <- as.function(p))
f(1:3) # -> 16
f(c(1,1,1)) # -> 5
f <- as.function(p, vector = FALSE)
f(1, 2, 3) # -> 16
f(1, 1, 1) # -> 5
f <- as.function(p, varorder = c("z","y","x"), vector = FALSE)
f(3, 2, 1) # -> 16
f(1, 1, 1) # -> 5
# for univariate mpolys, as.function() returns a vectorized function
# that can even apply to arrays
p <- mp("x^2")
f <- as.function(p)
f(1:10)
(mat <- matrix(1:4, 2))
f(mat)
p <- mp("1 2 3 4")
f <- as.function(p)
f(10) # -> 24
bernstein(1, 2)
s <- seq(0, 1, .01)
as.function(bernstein(1, 2))(s)
plot(
s,
as.function(bernstein(1, 2))(s)
)
as.function(mp("x + xx"))
as.function(mp("x + xx"), squeeze = FALSE)
# }
Run the code above in your browser using DataLab