https://github.com/cran/pracma
Raw File
Tip revision: 708a2ad382a163d1eef5af0665e3ae2aad200ced authored by HwB on 21 March 2013, 00:00:00 UTC
version 1.4.5
Tip revision: 708a2ad
moler.R
##
##  m o l e r . R
##


moler <- function(n) {
	if (length(n) != 1 || n != round(n))
		stop("Argument 'n' must be an integer.")
	if (n <= 0) return(c())

	A <- matrix(0, nrow = n, ncol = n)
	for (i in 1:n) {
		A[i, 1:i] <- (1:i) - 2
	}
	A <- A + t(A)
	diag(A) <- 1:n
	A
}
back to top