# Thread: computin multiple integral with ugly - but positive - function (mathematica/matlab)

1. ## computin multiple integral with ugly - but positive - function (mathematica/matlab)

hello everyone,

I'm trying to compute a triple integral in mathematica (with NIntegrate), but it's not giving me a good answer. In fact it sometimes gives me a number close to 22, sometimes (if I increase working presicion) close to 90, etc (I'm actually expecting this integral to be less than 1). And everytime it also says that integral converges too slowly. However the function is positive, so I don't understand why is it so hard to compute. Are there tricks I could use to evaluate the integral precisely, in these cases?

I tried Monte Carlo method, and it gives me even more random answers...

Btw, the function does have blow-ups on the edges, but they are of the form $1/\sqrt{x}$, which is integrable.

Just in case someone interested, here's my function:

NIntegrate[ 2*1/(3!*\[Pi]^2) * r*(2 r*Sin[t]*(r^2 + z1^2 - 2*r*z1*Cos[t]))/((1 + r^2 z1^2 - 2 r z1 Cos[t])*Sqrt[((1 + r^2*Sin[t]^2 - r^2*Cos[t]^2)^2 + 4*r^4*Sin[t]^2*Cos[t]^2)]*Sqrt[1 - z1^2]*(1 - r^2)), {z1, -1, 1}, {r, 0, 1}, {t, 0, \[Pi]}, MaxRecursion -> 50, WorkingPrecision -> 200, PrecisionGoal -> 8]

2. ## Re: computin multiple integral with ugly - but positive - function (mathematica/matla

Different regions of your integrand present different challenges to the integrator.

As a first simple experiment I subdivided the integrand into the interior, the six "faces" and the eight "corners." Some of those regions appear to integrate relatively nicely while others seem to have substantially more trouble. Actually I'm not certain that there might need to be further subdivisions near t=Pi/2.

Here is what I've been looking at:
In[1]:= d=1/30;
f=Simplify[2*1/(3!*π^2)*r*(2 r*Sin[t]*(r^2+z1^2-2*r*z1*Cos[t]))/((1+r^2 z1^2-2 r z1 Cos[t])*
Sqrt[((1+r^2*Sin[t]^2-r^2*Cos[t]^2)^2+4*r^4*Sin[t]^2*Cos[t]^2)]*Sqrt[1-z1^2]*(1-r^2))]

Interior

In[3]:= NIntegrate[f,{z1,-1+d,1-d},{r,0+d,1-d},{t,d Pi,π-d Pi}]

Faces

In[4]:= NIntegrate[f,{z1,-1,-1+d},{r,d,1-d},{t,d Pi,π-d Pi}]

In[5]:= NIntegrate[f,{z1,1-d,1},{r,d,1-d},{t,d Pi,π-d Pi}]

In[6]:= NIntegrate[f,{z1,-1+d,1-d},{r,0,d},{t,d Pi,π-d Pi}]

In[7]:= NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,d Pi,π-d Pi}]

In[8]:= NIntegrate[f,{z1,-1+d,1-d},{r,d,1-d},{t,0,d Pi}]

In[9]:= NIntegrate[f,{z1,1-d,1},{r,d,1-d},{t,π-d Pi,Pi}]

Corners

In[10]:= NIntegrate[f,{z1,-1,-1+d},{r,0,d},{t,0,d Pi}]

In[11]:= NIntegrate[f,{z1,-1,-1+d},{r,0,d},{t,Pi-d Pi,Pi}]

In[12]:= NIntegrate[f,{z1,-1,-1+d},{r,1-d,1},{t,0,d Pi}]

In[13]:= NIntegrate[f,{z1,-1,-1+d},{r,1-d,1},{t,Pi-d Pi,Pi}]

In[14]:= NIntegrate[f,{z1,1-d,1},{r,0,d},{t,0,d Pi}]

In[15]:= NIntegrate[f,{z1,1-d,1},{r,0,d},{t,Pi-d Pi,Pi}]

In[16]:= NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,0,d Pi}]

In[17]:= NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,Pi-d Pi,Pi}]

Inspect the denominator of the simplified expression carefully and look for regions where the denominator will go to zero. I believe those will tend to pose the greatest challenges to the integrator.

As you increase the PrecisionGoal this will further expose which of these regions have increased problems.

3. ## Re: computin multiple integral with ugly - but positive - function (mathematica/matla

Good idea. I will play with each of the regions as you suggested. After giving it a try it looks like the integrand indeed might have some unintegrable places there...

Thanks.

4. ## Re: computin multiple integral with ugly - but positive - function (mathematica/matla

I apologize for one error that I didn't notice until it was too late to edit and correct this.

When I scraped and pasted between Mathematica some of the \[Pi] turned into n and others remained as Pi.
Hopefully this has corrected all those errors, but check this carefully to make certain that none remain.

d=1/30;
f=Simplify[2*1/(3!*Pi^2)*r*(2 r*Sin[t]*(r^2+z1^2-2*r*z1*Cos[t]))/((1+r^2 z1^2-2 r z1 Cos[t])*
Sqrt[((1+r^2*Sin[t]^2-r^2*Cos[t]^2)^2+4*r^4*Sin[t]^2*Cos[t]^2)]*Sqrt[1-z1^2]*(1-r^2))]

Interior

NIntegrate[f,{z1,-1+d,1-d},{r,d,1-d},{t,d Pi,Pi-d Pi}]

Faces

NIntegrate[f,{z1,-1,-1+d},{r,d,1-d},{t,d Pi,Pi-d Pi}]

NIntegrate[f,{z1,1-d,1},{r,d,1-d},{t,d Pi,Pi-d Pi}]

NIntegrate[f,{z1,-1+d,1-d},{r,0,d},{t,d Pi,Pi-d Pi}]

NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,d Pi,Pi-d Pi}]

NIntegrate[f,{z1,-1+d,1-d},{r,d,1-d},{t,0,d Pi}]

NIntegrate[f,{z1,1-d,1},{r,d,1-d},{t,Pi-d Pi,Pi}]

Corners

NIntegrate[f,{z1,-1,-1+d},{r,0,d},{t,0,d Pi}]

NIntegrate[f,{z1,-1,-1+d},{r,0,d},{t,Pi-d Pi,Pi}]

NIntegrate[f,{z1,-1,-1+d},{r,1-d,1},{t,0,d Pi}]

NIntegrate[f,{z1,-1,-1+d},{r,1-d,1},{t,Pi-d Pi,Pi}]

NIntegrate[f,{z1,1-d,1},{r,0,d},{t,0,d Pi}]

NIntegrate[f,{z1,1-d,1},{r,0,d},{t,Pi-d Pi,Pi}]

NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,0,d Pi}]

NIntegrate[f,{z1,1-d,1},{r,1-d,1},{t,Pi-d Pi,Pi}]

If I haven't made another mistake then you can use Reduce on your denominator==0&&your range limitations on the variables and I believe you will find that the denominator will be zero when r==1 or when z1==1. That might help focus your attention on the regions where integration may be having more problems.

5. ## Re: computin multiple integral with ugly - but positive - function (mathematica/matla

yep, I figured the Pi thing, no worries. thanks again.