polyn.eval(c(1,-2,1), x = 0:3)# (x - 1)^2
polyn.eval(c(0, 24, -50, 35, -10, 1), x = matrix(0:5, 2,3))# 5 zeros!
(cf <- rbind(diag(3), c(1,-2,1)))
polyn.eval(cf, 0:5)
x <- seq(-3,7, by=1/4)
cf <- 4:1
(px <- polyn.eval(cf, x)) # is exact
if((gmpT <-"package:gmp" %in% search()) || require("gmp")) withAutoprint({
pxq <- polyn.eval(coef = as.bigq(cf, 1), x=x)
pxq
stopifnot(pxq == px)
if(!gmpT) detach("package:gmp")
})
if((RmpfrT <-"package:Rmpfr" %in% search()) || require("Rmpfr")) withAutoprint({
pxM <- polyn.eval(coef = mpfr(cf, 80), x=x) # 80 bits accuracy
pxM
stopifnot(pxM == px)
if(!RmpfrT) detach("package:Rmpfr")
})
stopifnot(identical(polyn.eval(12, x), rep(12, length(x))),
identical(polyn.eval(7, diag(3)), matrix(7, 3,3)))
Run the code above in your browser using DataLab