Integrals of tf-objects are computed by simple quadrature (trapezoid rule).
By default the scalar definite integral
\(\int^{upper}_{lower}f(s)ds\) is returned (option definite = TRUE),
alternatively for definite = FALSE the anti-derivative on
[lower, upper], e.g. a tfd or tfb object representing \(F(t) \approx
\int^{t}_{lower}f(s)ds\), for \(t \in\)[lower, upper], is returned.
Usage
tf_integrate(f, arg, lower, upper, ...)
# Default S3 method
tf_integrate(f, arg, lower, upper, ...)
# S3 method for class 'tfd'
tf_integrate(
f,
arg = tf_arg(f),
lower = tf_domain(f)[1],
upper = tf_domain(f)[2],
definite = TRUE,
...
)
# S3 method for class 'tfb'
tf_integrate(
f,
arg = tf_arg(f),
lower = tf_domain(f)[1],
upper = tf_domain(f)[2],
definite = TRUE,
...
)Arguments
- f
a
tf-object- arg
(optional) grid to use for the quadrature.
- lower
lower limits of the integration range. For
definite = TRUE, this can be a vector of the same length asf.- upper
upper limits of the integration range (but see
definitearg / description). Fordefinite = TRUE, this can be a vector of the same length asf.- ...
not used
- definite
should the definite integral be returned (default) or the antiderivative. See description.
Value
For definite = TRUE, the definite integrals of the functions in
f. For definite = FALSE and tf-inputs, a tf object containing their
anti-derivatives
Details
When f is irregular and lower / upper are not supplied explicitly,
they default to each curve's own observed arg range (i.e., the range of its
tf_arg() values) rather than the (shared) domain endpoints; for regular tfd
the defaults remain the domain endpoints.
Without this per-curve default, curves that do not span the full domain
would silently NA-poison the trapezoidal sum, because the default linear
evaluator does not extrapolate. Pass explicit lower / upper to integrate
over a fixed sub-interval, or switch to an extrapolating evaluator
(e.g. tf_approx_fill_extend()) to integrate over the full domain.
See also
Other tidyfun calculus functions:
tf_derive()