Skip to contents

Mirrors the C# OrderedPairedData.TrapezoidalAreaUnderY/TrapezoidalAreaUnderX: the trapezoidal-rule area between the curve and the x-axis (under = "y") or the y-axis (under = "x"). Requires x (for under = "y") or y (for under = "x") to be sorted ascending or descending – order_x/order_y = "none" raises the same error the C# method does.

Usage

curve_area(
  x,
  y,
  under = "y",
  order_x = "ascending",
  order_y = "ascending",
  strict_x = TRUE,
  strict_y = TRUE
)

Arguments

x, y

numeric vectors of equal length (at least two), the curve's ordinates.

under

one of "y" (default, area under the curve against the x-axis) or "x" (area against the y-axis).

order_x, order_y

one of "ascending" (default), "descending", or "none".

strict_x, strict_y

require x/y to strictly increase/decrease (per order_x/order_y) between consecutive ordinates. Default TRUE.

Value

a single number.

Examples

curve_area(c(1, 2, 3, 4), c(1, 4, 9, 16))
#> [1] 21.5