R/fd_central.R

Defines functions fd_central

Documented in fd_central

#' Center difference for numeric vectors
#'
#' @param y numeric vector to differentiate
#' @param h step-size
#'
#' @description {Center difference approximationt to first derivative for a numeric vector representing a function evaluated on a grid.}
#' @details {Details are well known. At each point we take the next and previous, their difference and divided by the step-size.}
#' @return vector
#' @export fd_central
fd_central <- function(y, h)
{
  n <- length(y)
  z <- matrix(0, nrow = n-2)
  for(i in 2:(n-1))
  {
    z[i-1] <- (y[i+1]-y[i-1])/(2*h)
  }
  return(z)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.