#' Discretize function over space-time grid
#'
#' @param f function to evaluate on grid
#' @param x space variable
#' @param t time variable, can be null to discretize a function over just space.
#'
#' @description {Discretizes a function of space-time over a grid.}
#' @details {Simple double for-loop for space-time functions and one for-loop for functions of a single-variable}
#' @return matrix
#' @export grid_function
grid_function <- function(f, x, t = NULL)
{
# If both x and t variable are present
if(!is.null(t))
{
N <- length(t)
M <- length(x)
m <- matrix(data = 0, nrow = N, ncol = M)
for(i in 1:N)
{
for(j in 1:M)
{
m[i, j] <- f(x[j], t[i])
}
}
} else if(is.null(t)){
n <- length(x)
m <- matrix(data = 0, nrow = n)
for(j in 1:n)
{
m[j] <- f(x[j])
}
}
return(m)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.