View source: R/discretizeMap.R
1 | discretizeMap(N, map, xlim)
|
N |
|
map |
|
xlim |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (N, map, xlim)
{
x_lower = xlim[1]
x_upper = xlim[2]
dx = (x_upper - x_lower)/(N - 1)
domain = seq(from = x_lower, to = x_upper, by = dx)
codomain = sapply(X = domain, FUN = function(x) map(x))
helperMatrix = matrix(codomain, ncol = 1) %*% rep(1, N)
indices = apply(X = helperMatrix, MARGIN = 1, FUN = function(x) {
dist = abs(x - domain)
index = which(dist == min(dist))
return(index)
})
A = matrix(rep(0, N * N), ncol = N, nrow = N)
for (i in 1:N) {
A[indices[i], i] = 1
}
return(A)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.