Compute the area of a function with values y at the points x within given limits.

trapz_limits(x, y, lower, upper)

Arguments

x

x-coordinates of points on the x-axis.

y

Function values associated with the x-coordinates.

lower

Lower integration boundary.

upper

Upper integration boundary.

Value

Area under the curve defined by the (x, y)-tuples.

Examples

x <- 0:5 y <- c(1, 4, 2, 3, 3, 0) trapz_limits(x, y, -2, 10)
#> [1] 12.5
trapz_limits(x, y, -2, -1)
#> [1] 0
trapz_limits(x, y, -2, .4)
#> [1] 0.64
trapz_limits(x, y, .4, .7)
#> [1] 0.795
trapz_limits(x, y, .4, 3.6)
#> [1] 9.16
trapz_limits(x, y, .4, 7)
#> [1] 11.86
trapz_limits(x, y, 6, 7)
#> [1] 0
if (FALSE) { # throws an error trapz_limits(x, y, 4, 3) }