https://github.com/cran/pracma
Tip revision: 708a2ad382a163d1eef5af0665e3ae2aad200ced authored by HwB on 21 March 2013, 00:00:00 UTC
version 1.4.5
version 1.4.5
Tip revision: 708a2ad
deconv.R
##
## d e c o n v . R Deconvolution
##
deconv <- function(b, a) {
if (length(b) == 0)
return(list(q = 0, r = c()))
if ( (!is.numeric(b) && ! is.complex(b)) ||
(!is.numeric(a) && ! is.complex(a)) )
stop("Arguments 'b' and 'a' must be numeric or complex.")
if ( a[1] == 0)
stop("First element of argument 'a' must be nonzero.")
nb <- length(b)
na <- length(a)
if (nb < na)
return(list(q = 0, r = b))
q <- c()
while (nb >= na) {
d <- b[1] / a[1]
b <- b - conv(a, c(d, rep(0, nb-na)))
q <- c(q, d)
b <- b[2:nb]
nb <- nb -1
}
return(list(q = q, r = b))
}