swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: 63e8a52ae6668e736720c89691352d6dc3bc9eb1 authored by HwB on 17 January 2012, 00:00:00 UTC
version 0.9.6
version 0.9.6
Tip revision: 63e8a52
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)
}