https://github.com/cran/pracma
Raw File
Tip revision: 3fdb68cc842f2ab3b59608f8e04d495763584f78 authored by Hans W. Borchers on 27 November 2015, 12:07:10 UTC
version 1.8.8
Tip revision: 3fdb68c
polyval.R
###
### POLYVAL.R  Polynom
###

polyval <- function(p, x) {
    if (length(x) == 0) return(c())
    if (length(p) == 0) return(0 * x)
    if (!is.vector(p, mode="numeric") && !is.vector(p, mode="complex"))
        stop("Argument 'p' must be a real or complex vector.")
    if (!is.vector(x) && !is.matrix(x))
        stop("Argument 'x' must be a real or complex matrix.")

    n <- length(p)
    y <- outer(x[1:length(x)], (n-1):0, "^") %*% p
    dim(y) <- dim(x)
    return(y)
}
back to top