swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: 579123307d89d9c83ce74568d6dfb56864019c93 authored by Hans W. Borchers on 05 February 2014, 00:00:00 UTC
version 1.6.4
version 1.6.4
Tip revision: 5791233
polymul.R
##
## p ol y m u l .R Polynomial Multiplication
##
polymul <- function(p, q){
if ( (!is.vector(p, mode="numeric") && !is.vector(p, mode="complex")) ||
(!is.vector(q, mode="numeric") && !is.vector(q, mode="complex")) )
stop("Arguments 'p' and 'q' must be real or complex vectors.")
n <- length(p); m <- length(q)
if (n <= 1 || m <= 1) return(p*q)
r <- rep(0, n+m-1)
for (i in seq(along=q)) {
r <- r + c(rep(0, i-1), p * q[i], rep(0, m-i))
}
while (r[1] == 0 && length(r) > 1)
r <- r[2:length(r)]
return(r)
}