Description Usage Arguments Details Value Author(s) References See Also Examples
Estimates the integral of a real-valued function using Simpson's or the Trapezoid approximation
1 2 |
y |
Vector of f(x) values |
x |
Numeric vector of sorted x values, each element of |
a |
The lower limit of integration, only required for the Simpson method. |
b |
The upper limit of integration, only required for the Simpson method. |
method |
The method of integration (can use just the first letter).
Defaults to |
For the Simpson method, y
is a numeric vector of f(x), evaluated at
an odd number of evenly spaced x's in the interval [a,b].
For the trapezoid method, the elements of x
and y
should
correspond to one another, and x
must be sorted in ascending order.
The lengths or x
and y
should be the same, and they may be
odd or even. The elements of x
may be irregularly spaced.
A single numeric estimate of the integral of f(x) over [a, b]
(Simpson) or over the range of x
(trapezoid).
Landon Sego
Ellis R, Gulick D. "Calculus: One and Several Variables," Harcourt Brace Jovanovich, Publishers: New York, 1991; 479-482.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # The Beta density from 0 to 0.7
integ(dbeta(seq(0, 0.7, length = 401), 2, 5), a = 0, b = 0.7)
# Checking result with the cdf
pbeta(0.7, 2, 5)
# f(x) = x^2 from 0 to 3
integ(seq(0, 3, length = 21)^2, a = 0, b = 3)
# A quadratic function with both methods
x <- seq(0, 3, length = 51)
integ(x^2, x = x, method = "t")
integ(x^2, a = 0, b = 3, method = "s")
# Now a linear function
x <- seq(0, 2, length = 3)
y <- 2 * x + 3
integ(y, x = x, method = "t")
integ(y, a = 0, b = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.