num_integrate: Returns the 2D reimann integration of a curve within...

View source: R/num_integrate.R

num_integrateR Documentation

Returns the 2D reimann integration of a curve within specified limits

Description

The function returns a single numeric scalar as a result for the integration between upper and lower bounds

Usage

num_integrate(X,Y, xmin=2, xmax=5)
num_integrate(X,Y,xmin=2, xmax=5, type='avg')
num_integrate(X,Y, xmin=2, xmax=5, type='left')
num_integrate(X,Y, xmin=2, xmax=5, type='right')

Arguments

X

A numeric vector containing the X values of the curve you want to integrate

Y

A numeric vector containing the Y values of the curve you want to integrate

xmin

The lower bound of the integral.
Caution: xmin >= min(X), otherwise an error will be thrown.

xmax

The upper bound of the integral
Caution: xmax <= max(X), otherwise an error will be thrown.

type

The type defines the kind of reimann integral and is ordinaarily set to "avg".
The other possible options are "left" and "right". Defines the placement of the reimann rectangles w.r.t. the vertical y-axis height being considered.
The "avg" input averages between the left and right reimann integrals.

Details

The X vector should include the bounds of xmax and xmin or else an error will be thrown. Look at the arguments section above.
The funcion is by default set to type='avg'. Hence, if needed, this factor can be changed to 'left' or 'right'.
The no. of points within the bounds of xmax and xmin should at least be 4.
The sampling density in the dataset should allow on an average for at least 4 points within the xmax and xmin window length.

Value

The function always returns a numeric scalar

Author(s)

Chitran Ghosal

References

https://en.wikipedia.org/wiki/Riemann_integralReimann Integration

Examples

X <- seq(0,10, by=0.001)
Y <-2*X
num_integrate(X, Y, xmin=2, xmax=8)
num_integrate(X, Y, xmin=2, xmax=8, type='avg')
num_integrate(X, Y, xmin=2, xmax=8, type='left')
num_integrate(X, Y, xmin=2, xmax=8, type='right')
num_integrate(X,Y, xmin=2, xmax=2)
num_integrate(X,Y, xmin=6, xmax=6)

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.