Estimate the integral of one-dimensional function using the trapezoidal rule.
x values, or a single value that is taken as the (constant) difference between x values.
y values, with length (
Flag indicating the desired return value (see “Value”).
type="A" (the default), a single value is returned,
containing the estimate of the integral of
type="dA", a numeric vector of the same length as
x, of which
the first element is zer0, the second element is the integral between
x, etc. If
type="cA", the result is the
cumulative sum (as in
cumsum) of the values that would be
type="dA". See “Examples”.
There is no handling of
1 2 3 4 5 6 7 8 9 10
x <- seq(0, 1, length.out=10) # try larger length.out to see if area approaches 2 y <- 2*x + 3*x^2 A <- integrateTrapezoid(x, y) dA <- integrateTrapezoid(x, y, "dA") cA <- integrateTrapezoid(x, y, "cA") print(A) print(sum(dA)) print(tail(cA, 1)) print(integrateTrapezoid(diff(x[1:2]), y)) print(integrateTrapezoid(y))
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.