Example: bachelor of science

Use R to Compute Numerical Integrals

Stat401: Introduction to ProbabilityHandout-08, November 2, 2011 Use R to Compute Numerical IntegralsIn short, you may use R to nd out a Numerical answer to ann-fold integrate a one-dimensional integral over a nite or in nite interval, use R functionintegrate. For example, nd out 101(x+ 1)pxdx>## define the integrated function>integrand <- function(x) {1/((x+1)*sqrt(x))}>## integrate the function from 0 to infinity>integrate(integrand, lower = 0, upper = Inf) with absolute error < Numerical answer is 3:141593 up to a small error 2:7 10 example is to nd out 1:96 1:961p2 e x22dx>f <- function(x) {1/sqrt(2*pi)*exp(-x^2/2)}>integrate(f, lower = , upper = ) with absolute error < more information about the functionintegrate, typehelp(integrate)in integrate a scalar function over a multidimensional rectangle, use R useadaptIntegrate, you need to install the R packagecubature rst:(1)Download the package le \ " (2)Install the packagecubaturein R.

Stat401: Introduction to Probability Handout-08, November 2, 2011 Use R to Compute Numerical Integrals In short, you may use R to nd out a numerical answer to an n-fold integral. I.

Tags:

  Relating

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Use R to Compute Numerical Integrals

1 Stat401: Introduction to ProbabilityHandout-08, November 2, 2011 Use R to Compute Numerical IntegralsIn short, you may use R to nd out a Numerical answer to ann-fold integrate a one-dimensional integral over a nite or in nite interval, use R functionintegrate. For example, nd out 101(x+ 1)pxdx>## define the integrated function>integrand <- function(x) {1/((x+1)*sqrt(x))}>## integrate the function from 0 to infinity>integrate(integrand, lower = 0, upper = Inf) with absolute error < Numerical answer is 3:141593 up to a small error 2:7 10 example is to nd out 1:96 1:961p2 e x22dx>f <- function(x) {1/sqrt(2*pi)*exp(-x^2/2)}>integrate(f, lower = , upper = ) with absolute error < more information about the functionintegrate, typehelp(integrate)in integrate a scalar function over a multidimensional rectangle, use R useadaptIntegrate, you need to install the R packagecubature rst:(1)Download the package le \ " (2)Install the packagecubaturein R.

2 (i)Click R menu \packages".(ii)Click the subitem \Install package(s) from local zip " .(iii)Open the downloaded package le \ " .1 For more R packages, please you can use the R functionadaptIntegrateto computen-fold Integrals . Forexample, nd out the integral 120 120 12023(x1+x2+x3)dx1dx2dx3> library(cubature)# load the package "cubature"> f <- function(x) { 2/3 * (x[1] + x[2] + x[3]) } # "x" is vector> adaptIntegrate(f, lowerLimit = c(0, 0, 0), upperLimit = c( , , ))$integral[1] $error[1] the Numerical answer for the 3-dimensional integral is 0:0625 with estimated relativeerror 1:666961 10 more information about the functionadaptIntegrate, typehelp(adaptIntegrate)after loading the packagecubaturein


Related search queries