Computing Triple Integral in 'R'

Click For Summary

Discussion Overview

The discussion centers around computing a triple integral of a function of three variables, specifically within the context of the R programming environment. Participants explore various methods using different R packages, including Cubature, Base, and SimplicialCubature, while attempting to understand the manual computation of the integral value of 0.166666.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on how to compute the triple integral manually, given the function is defined as 1 in the domain where x < y < z and 0 otherwise.
  • Another participant questions the definition of the domain x < y < z, suggesting it may be infinite without additional bounding conditions, and asks for clarification on the limits set in the R code.
  • A participant explains that the lower and upper limits in the R code represent the bounds for the integration, specifically indicating that they are set to 0 and 1 for all three variables.
  • There is a discussion about the implications of changing the number of repetitions for the lower and upper limits in the R code, raising concerns about the consistency with the stated condition x < y < z.
  • One participant notes that the programming command used in the Cubature package may be difficult to understand, particularly in how it relates to the computed integral value.

Areas of Agreement / Disagreement

Participants express differing views on the definition and implications of the integration domain, with some agreeing on the limits set in the R code while others question the adequacy of the domain definition. The discussion remains unresolved regarding the clarity of the integration setup and its implications.

Contextual Notes

There are limitations regarding the clarity of the domain definition and its implications for the integral's finiteness. The relationship between the programming commands and the mathematical conditions is also not fully resolved.

WMDhamnekar
MHB
Messages
381
Reaction score
30
I would like to compute the triple integral of a function of three variables $f(x,y,z)$in R. I am using the package Cubature, Base, SimplicialCubature and the function adaptIntegrate(), Integrate and adaptIntegrateSimplex(). The integrand is equal to 1 only in certain domain(x<y<z, 0 otherwise).
Followings are the different ways to answer this question but i didn't understand how to compute the answer 0.166666 manually. If any member knows the answer, may reply. Using Cubature package,

library(cubature)
lower <- rep(0,3)
upper <- rep(1,3)

fxyz <- function(w) {
x <- w[1]
y <- w[2]
z <- w[3]
as.numeric(x <= y)*as.numeric(y <= z)
}
adaptIntegrate(f=fxyz,lowerLimit=lower,upperLimit= upper,doChecking=TRUE, maxEval=2000000,absError=10e-5,tol=1e-5)
\$integral
[1]0.1664146

\$error
[1]0.0001851699

\$functionEvaluations
[1]2000031

\$returnCode
[1]0

Using base package in 'R'
f.xyz <- function(x, y, z) ifelse(x < y & y < z, 1, 0)
f.yz <- Vectorize(function(y, z) integrate(f.xyz, 0, 1, y=y, z=z)\$value,
vectorize.args="y")

f.z <- Vectorize(function(z) integrate(f.yz, 0, 1, z=z)\$ value,
vectorize.args="z")
integrate(f.z, 0, 1)
>0.1666632 with absolute error < 9.7e-05

Using SimpicialCubature package in 'R'
library(SimplicialCubature)
f <- function(x) 1
S <- CanonicalSimplex(3)
> adaptIntegrateSimplex(function(x) 1, S)
\$integral
[1] 0.1666667

\$estAbsError
[1] 1.666667e-13

\$functionEvaluations
[1] 55

$returnCode
[1] 0

\$message
[1] "OK"
Note that integrating the constant function f(x)=1 over the simplex simply gives the volume of the simplex, which is 1/6. The integration is useless for this example

SimplexVolume(S)
[1] 0.1666667

Can any member explain me what is this actual question and how we can solve this question manually?
 
Physics news on Phys.org
I don't know "Cubature" but I will reply anyway!

First, your domain, x< y< z, is not well defined. The simple "x< y< z" is infinite and the integral of "1" on that domain is not finite. Is there not some other condition bounding the domain? In your program you have "lower<- rep(0,3)" and "upper<- rep(1,3)". Could that possibly mean that x lies between 0,3 and 1,3 (I would have said 0.3< z< 1.3)?
 
HallsofIvy said:
I don't know "Cubature" but I will reply anyway!

First, your domain, x< y< z, is not well defined. The simple "x< y< z" is infinite and the integral of "1" on that domain is not finite. Is there not some other condition bounding the domain? In your program you have "lower<- rep(0,3)" and "upper<- rep(1,3)". Could that possibly mean that x lies between 0,3 and 1,3 (I would have said 0.3< z< 1.3)?

Hello,
lower<-rep(0,3) means in adaptIntegrate function lower limit 0,repeats 3 times and upper<-(1,3) means upper limit 1, repeats 3 times.
e.g.$\displaystyle\int_0^1\displaystyle\int_0^1\displaystyle\int_0^1$
 
Dhamnekar Winod said:
Hello,
lower<-rep(0,3) means in adaptIntegrate function lower limit 0,repeats 3 times and upper<-(1,3) means upper limit 1, repeats 3 times.
e.g.$\displaystyle\int_0^1\displaystyle\int_0^1\displaystyle\int_0^1$
That's strange. What would happen if you entered different number of repetitions for the the lower limits and upper limits? Also \int_0^1\int_0^1\int_0^1 doesn't match your "x< y< z".
 
HallsofIvy said:
That's strange. What would happen if you entered different number of repetitions for the the lower limits and upper limits? Also \int_0^1\int_0^1\int_0^1 doesn't match your "x< y< z".

Hello,
Because of the following programming command while using 'Cubature' package in 'R', adaptIntegrate function gives answer 0.1664146.
fxyz <- function(w) {
x <- w[1]
y <- w[2]
z <- w[3]
as.numeric(x <= y)*as.numeric(y <= z)
}

This programming command seems to be difficult to understand.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K