Approximates the definite integral by using the rectangle rule.
Usage
integrate_rectangle(x, y, ...)
# S4 method for class 'numeric,numeric'
integrate_rectangle(x, y, right = FALSE)
# S4 method for class 'ANY,missing'
integrate_rectangle(x, right = FALSE)
Arguments
- x, y
A
numeric
vector. Ify
is missing, an attempt is made to interpretx
in a suitable way (seegrDevices::xy.coords()
).- ...
Currently not used.
- right
A
logical
scalar: should the right rule be used instead of the left rule?
Value
Returns a list
with two components x
and y
.
See also
Other integration methods:
integrate_trapezoid()
Examples
## Calculate the area under the sine curve from 0 to pi
# integrate(f = function(x) x^3, lower = 0, upper = 2)
x <- seq(0, 2, len = 101)
y <- x^3
plot(x, y, type = "l")
integrate_rectangle(x, y, right = FALSE) # 3.9204
#> [1] 3.9204
integrate_rectangle(x, y, right = TRUE) # 4.0804
#> [1] 4.0804
integrate_trapezoid(x, y) # 4.0004
#> [1] 4.0004