simpsons: Simpson's Rule Empirical Area Under a Curve

Description Usage Arguments Details Value Examples

View source: R/simpsons.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(raster)

# import raster image
data(normforest)

# basic values
z <- getValues(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)

Example output

Loading required package: sp

geodiv documentation built on Sept. 5, 2021, 5:26 p.m.