Skip to content
Prev 247152 / 398503 Next

Integrate and subdivisions limit

There's obviously a more numerically stable approach. If g(x) is a polynomial
you do know its polynomial antiderivative. Take that and sum up all intervals
where the step function is constant.

Example:  g(x) = 1 constant, integrate x^2 over 0..1 in 10000 subdivisions.
          The antiderivative is 1/3 * x^3, thus

    g <- function(x) 1
    x <- seq(0, 1, len=10001)
    sum((x[2:10001]^3 - x[1:10000]^3)*g(2:10001))/3  #=> 0.3333333

The antiderivative of a polynomial a_1 x^n + ... + a_{n+1} given as vector
c(a1,...) can also be determined automatically, no manual work is necessary.

Hans Werner