trapzc: Trapezoidal rule for numerical integration on an equidistant...

View source: R/Transformations.R

trapzcR Documentation

Trapezoidal rule for numerical integration on an equidistant grid

Description

Approximates the integral of a function from its values on an equidistant grid by the composite trapezoidal rule,

\int_a^b f(t)\,dt \approx h\left(\frac{f_1}{2} + f_2 + \dots + f_{n-1} + \frac{f_n}{2}\right),

where h is the grid spacing. It is the integration routine used by fcenLR, fcenLRp, fcenLRu, fcenLRinv and compositionalSpline.

Usage

trapzc(step, f)

Arguments

step

spacing h of the (equidistant) grid.

f

numeric vector of at least two function values on the grid, e.g. a density or a clr-transformed density.

Value

A single number: the approximate value of the integral.

Author(s)

R. Talska talskarenata@seznam.cz, K. Hron karel.hron@upol.cz

See Also

fcenLR, fcenLRinv

Examples

t <- seq(-4.7, 4.7, length = 1000)
t_step <- diff(t[1:2])
f <- dnorm(t, mean = 0, sd = 1.5)

# integral of the density over the grid (close to 1)
trapzc(t_step, f)

# the clr transform of a density integrates to zero
trapzc(t_step, fcenLR(t, t_step, f))

robCompositions documentation built on Nov. 1, 2026, 1:06 a.m.