sintegral | R Documentation |
Takes a vector of x values and a corresponding set of postive f(x)=y values and evaluates the area under the curve:
\int{f(x)dx}
.
sintegral(x, fx, n.pts = 256)
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. |
returns a list with the following elements
x |
the x-values at which the integral has been evaluated |
y |
the cummulative integral |
int |
the value of the integral over the whole range |
## integrate the normal density from -3 to 3 x=seq(-3,3,length=100) fx=dnorm(x) estimate=sintegral(x,fx)$int true.val=diff(pnorm(c(-3,3))) cat(paste('Absolute error :',round(abs(estimate-true.val),7),'\n')) cat(paste('Relative percentage error :', 100*round((abs(estimate-true.val)/true.val),6),'%\n'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.