Computing Triple Integral in 'R'

In summary: Can you please explain it in simpler way?In summary,using Cubature package,lower limit is 0,repeats 3 times, upper limit is 1, repeats 3 timesusing base package in 'R',f.xyz <- function(x) 1 S <- CanonicalSimplex(3)integrate(f.xyz, 0, 1, y=y, z=z) gives 0.1666667integrate(f.xyz, 0, 1) gives 0using SimplicialCubature package in 'R',library(SimplicialCubature) f <- function(x) 1 S <- Canon
  • #1
WMDhamnekar
MHB
381
28
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
  • #2
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)?
 
  • #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$
 
  • #4
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 [tex]\int_0^1\int_0^1\int_0^1[/tex] doesn't match your "x< y< z".
 
  • #5
HallsofIvy said:
That's strange. What would happen if you entered different number of repetitions for the the lower limits and upper limits? Also [tex]\int_0^1\int_0^1\int_0^1[/tex] 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.
 

FAQ: Computing Triple Integral in 'R'

What is a triple integral in 'R'?

A triple integral in 'R' is a mathematical concept used to calculate the volume of a three-dimensional region in a Cartesian coordinate system. It involves integrating a function over a three-dimensional space, with each integral representing a different dimension. The result of a triple integral is a scalar value that represents the volume of the region.

What is the purpose of computing a triple integral in 'R'?

The purpose of computing a triple integral in 'R' is to find the volume of a three-dimensional region or object. It is commonly used in physics and engineering to calculate the mass, center of mass, and moments of inertia of three-dimensional objects. It is also used in calculus and other advanced mathematical concepts.

What are the steps involved in computing a triple integral in 'R'?

The steps involved in computing a triple integral in 'R' are as follows:

  • Step 1: Determine the limits of integration for each dimension.
  • Step 2: Write the triple integral in the correct order, either dx dy dz or dz dy dx.
  • Step 3: Evaluate the innermost integral first, using the limits of integration determined in Step 1.
  • Step 4: Evaluate the remaining integrals in the same way, using the previous integral as the lower limit and the limits of integration for the current dimension as the upper limit.
  • Step 5: Once all integrals have been evaluated, multiply the results together to get the final answer.

What are some common mistakes to avoid when computing a triple integral in 'R'?

Some common mistakes to avoid when computing a triple integral in 'R' include:

  • Forgetting to reverse the order of integration when switching from dx dy dz to dz dy dx or vice versa.
  • Using incorrect limits of integration for each dimension.
  • Forgetting to evaluate all three integrals.
  • Not using the correct integrand (function to be integrated) for each integral.
  • Using the wrong type of integral (e.g. using a double integral instead of a triple integral).

Can a triple integral in 'R' be used to calculate other properties besides volume?

Yes, a triple integral in 'R' can be used to calculate other properties besides volume. It can also be used to calculate the mass, center of mass, and moments of inertia of three-dimensional objects. In addition, it can be used in physics to calculate quantities such as electric charge density and fluid flow rate. It is a versatile mathematical tool that has many applications in various fields.

Similar threads

Back
Top