R/erf.R

Defines functions erf

Documented in erf

#' Error Function
#' 
#' This function returns the error function.  The complementary 
#' error function can be obtained by subtracting the result 
#' from one: (1-erf(t)).  This uses a truncated infinite series.
#' 
#' @param t argument
#' @return error function
#' @export
erf <- function(t) {
      su <- 0
      top <- 0
      bottom <- 0
      for (i in 1:21) {
            k <- i - 1
            top <- ((-1)^k) * t^(2*k+1)
            bottom <- factorial(k) * (2*k+1)
            su <- su + (top / bottom)
      }
      erf <- (2 / (pi^(0.5))) * su
      return(erf)
}
LimpopoLab/hydrostats documentation built on April 14, 2025, 5:25 a.m.