| simpsonCoefs | R Documentation |
Return a vector of Simpson's Composite numerical integration coefficients.
simpsonCoefs(n)
n |
Number of coefficients, which is the number of points
at which the function of interest is evaluated. The number of
intervals is |
Let x be an vector of equally spaced points in the domain
of a function f (equally spaced is critical).
Let y = f(x). The numeric integral of f from min(x)
to max(x) is
sum(simpsonCoefs(length(y)) * y) * (x[2] - x[1]) / 3.
A vector of Simpson Composite rule coefficients suitable for numeric integration. The return is a vector of integers alternating between 4 and 2, with 1's on each end.
x <- seq(0, 9, length=13)
y <- x^2
scoefs <- simpsonCoefs(length(x))
# exact integral is 9^3/3 = 243
sum( scoefs*y ) * (x[2] - x[1]) / 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.