The R Project SVN R

Rev

Rev 85981 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 85981 Rev 85990
Line 59... Line 59...
59
m <- 17
59
m <- 17
60
k <- length(wts <- c(76, 99, 60, 20, 1))
60
k <- length(wts <- c(76, 99, 60, 20, 1))
61
n <- m-k+1
61
n <- m-k+1
62
## Convolution
62
## Convolution
63
W <- toeplitz2(c(rep(0, m-k), wts, rep(0, m-k)), ncol=n)
63
W <- toeplitz2(c(rep(0, m-k), wts, rep(0, m-k)), ncol=n)
64
\dontshow{hadM <- isNamespaceLoaded("Matrix")
64
\dontdiff{\dontshow{hadM <- isNamespaceLoaded("Matrix")}
65
## IGNORE_RDIFF_BEGIN}
-
 
66
## "display" nicely :
65
## "display" nicely :
67
if(requireNamespace("Matrix"))
66
if(requireNamespace("Matrix"))
68
   print(Matrix::Matrix(W))    else {
67
   print(Matrix::Matrix(W))    else {
69
   colnames(W) <- paste0(",", if(n <= 9) 1:n else c(1:9, letters[seq_len(n-9)]))
68
   colnames(W) <- paste0(",", if(n <= 9) 1:n else c(1:9, letters[seq_len(n-9)]))
70
   print(W)
69
   print(W)
71
}
70
}
72
\dontshow{if(!hadM) unloadNamespace("Matrix")% revert state
71
\dontshow{if(!hadM) unloadNamespace("Matrix")}}% revert state
73
## IGNORE_RDIFF_END}
-
 
74
## scale W to have column sums 1:
72
## scale W to have column sums 1:
75
W. <- W / sum(wts)
73
W. <- W / sum(wts)
76
all.equal(rep(1, ncol(W.)), colSums(W.), check.attributes = FALSE)
74
all.equal(rep(1, ncol(W.)), colSums(W.), check.attributes = FALSE)
77
## Visualize "mass-preserving" convolution
75
## Visualize "mass-preserving" convolution
78
x <- 1:n; f <- function(x) exp(-((x - .4*n)/3)^2)
76
x <- 1:n; f <- function(x) exp(-((x - .4*n)/3)^2)