R/trapint.R

trapint = function(v, x){
  #Check vectors for possible errors and return appropriate messages
  #V is depth/time value, x is item of interest
  #v and x should be in vector form
  if (length(x) != length(v)){
    stop('Your variables are of different lengths.')
  }
  if (!is.numeric(v)){
    stop('The variable of integration "v" is not numeric.')
  }
  if (!is.numeric(x)){
    stop('The integrand "x" is not numeric.')
  }

  n = length(x)
  integral = sum(0.5 * (x[2:n] + x[1:(n-1)]) * ((v[2:n] - v[1:(n-1)])))
  return(integral)
}
kevans27/aqeco documentation built on May 16, 2019, 4:08 a.m.