Learn R Programming

Bolstad (version 0.1-8)

sintegral: Numerical integration using Simpson's Rule

Description

Takes a vector of x values and a corresponding set of postive y values and evaluates the area under the curve.

Usage

sintegral(x, fx, n.pts = 256, ret = FALSE)

Arguments

x
a sequence of x values.
fx
the value of the function to be integrated at x.
n.pts
the number of points to be used in the integration.
ret
if true returns the partial sums of the integration.

Examples

Run this code
## integrate the normal density from -3 to 3
x<-seq(-3,3,length=100)
fx<-dnorm(x)
estimate<-sintegral(x,fx)
true.val<-diff(pnorm(c(-3,3)))
cat(paste("Absolute error :",round(abs(estimate-true.val),7),""))
cat(paste("Relative percentage error :", 100*round((abs(estimate-true.val)/true.val),6),"%
"))

Run the code above in your browser using DataLab