simpsons: Simpson's Rule Empirical Area Under a Curve

View source: R/simpsons.R

simpsonsR Documentation

Simpson's Rule Empirical Area Under a Curve

Description

Calculates the area below a curve from points a to b. This function is provided for general use.

Usage

simpsons(f, a, b, n = 100)

Arguments

f

A function.

a

Numeric. The left x boundary.

b

Numeric. The right x boundary.

n

Numeric. The number of subdivisions along the function line.

Details

Note that if y-values are negative, this returns the area above the function line.

Value

A numeric value representing the area under the curve with x bounds a and b.

Examples

# import raster image
data(normforest)
normforest <- terra::unwrap(normforest)

# basic values
z <- terra::values(normforest)

# calculate cumulative probability density function of surface 'height' (= ndvi)
mod <- ecdf((1 - z))

# calculate integral
int_area <- simpsons(f = mod, b = 1, a = 0.8, n = 500)

geodiv documentation built on Oct. 6, 2023, 1:07 a.m.