1
$\begingroup$

I need to calculate a numerical integral which consists of the following functions:

f7 := 1/
   (Pi^8*(
   (1/8)*(y0 + y1 + y2 + y3 - y4 - y5 - y6 - y7)^2 + 1)
   *
   ((1/8)*(y0 + y1 - y2 - y3 + y4 + y5 - y6 - y7)^2 + 1)
   *
   ((1/8)*(y0 - y1 + y2 - y3 + y4 - y5 + y6 - y7)^2 + 1)
   *
   ((1/8)*(y0 - y1 - y2 + y3 - y4 + y5 + y6 - y7)^2 + 1)
   *
   ((1/8)*(y0 - y1 - y2 + y3 + y4 - y5 - y6 + y7)^2 + 1)
   *
   ((1/8)*(y0 - y1 + y2 - y3 - y4 + y5 - y6 + y7)^2 + 1)
   *
   ((1/8)*(y0 + y1 - y2 - y3 - y4 - y5 + y6 + y7)^2 + 1)
   *
   ((1/8)*(y0 + y1 + y2 + y3 + y4 + y5 + y6 + y7)^2 + 1))

f6 := Integrate[f7, {y7, -Infinity, Infinity}, 
Assumptions -> {Element[{y0, y1, y2,  y3, y4, y5, y6},Reals]}]


h7 = NIntegrate[f7*Log[f7/f6], {y0, -Infinity, Infinity}, {y1, 
 -Infinity, Infinity}, {y2, -Infinity, Infinity}, 
{y3, -Infinity, Infinity}, {y4, -Infinity, Infinity}, 
{y5, -Infinity, Infinity}, {y6, -Infinity, Infinity}, 
{y7, -Infinity, Infinity}]

My question here is, f6 is hard to calculate symbolically. However, I only need h7. Is there any way to calculate h7 using NIntegrate without trying to calculate f6 symbolically?

$\endgroup$
2
  • $\begingroup$ People here generally like users to post code as Mathematica code instead of images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this this meta Q&A helpful $\endgroup$
    – Michael E2
    Commented Oct 1, 2016 at 17:01
  • $\begingroup$ Don't use subscripts. Subscript[y, 1] doesn't create a variable $y_1$, it takes a variable y that is inside a two-argument function Subscript. Compute the following to see what I mean: D[Subscript[y, 1], y]. Use simply y1, y2 etc. $\endgroup$
    – corey979
    Commented Oct 1, 2016 at 18:07

1 Answer 1

1
$\begingroup$

You can do the multiple Integral completeley with NIntegrate. Try this code:

    In[31]:= f7[y0_, y1_, y2_, y3_, y4_, y5_, y6_, y7_] = 
    1/(Pi^8*((1/8)*(y0 + y1 + y2 + y3 - y4 - y5 - y6 - y7)^2 + 
   1)*((1/8)*(y0 + y1 - y2 - y3 + y4 + y5 - y6 - y7)^2 + 
   1)*((1/8)*(y0 - y1 + y2 - y3 + y4 - y5 + y6 - y7)^2 + 
   1)*((1/8)*(y0 - y1 - y2 + y3 - y4 + y5 + y6 - y7)^2 + 
   1)*((1/8)*(y0 - y1 - y2 + y3 + y4 - y5 - y6 + y7)^2 + 
   1)*((1/8)*(y0 - y1 + y2 - y3 - y4 + y5 - y6 + y7)^2 + 
   1)*((1/8)*(y0 + y1 - y2 - y3 - y4 - y5 + y6 + y7)^2 + 
   1)*((1/8)*(y0 + y1 + y2 + y3 + y4 + y5 + y6 + y7)^2 + 1));



In[32]:= f6[y0_?NumericQ, y1_?NumericQ, y2_?NumericQ, y3_?NumericQ, 
 y4_?NumericQ, y5_?NumericQ, y6_?NumericQ] := 
NIntegrate[
f7[y0, y1, y2, y3, y4, y5, y6, y7], {y7, -Infinity, Infinity}, 
MaxRecursion -> 100]

(h7 = NIntegrate[
f7[y0, y1, y2, y3, y4, y5, y6, y7]*
 Log[f7[y0, y1, y2, y3, y4, y5, y6, y7]/
   f6[y0, y1, y2, y3, y4, y5, y6]], {y0, -Infinity, 
 Infinity}, {y1, -Infinity, Infinity}, {y2, -Infinity, 
 Infinity}, {y3, -Infinity, Infinity}, {y4, -Infinity, 
 Infinity}, {y5, -Infinity, Infinity}, {y6, -Infinity, 
 Infinity}, {y7, -Infinity, Infinity}, 
MaxRecursion -> 20]) // Timing

      NIntegrate::eincr: The global error of the strategy     
      GlobalAdaptive has increased more than 2000 times. The global 
 error is expected to decrease monotonically after a number of 
integrand evaluations. Suspect one of the following: the working    precision 
is insufficient for the specified precision goal; the integrand is highly
 oscillatory or it is not a (piecewise) smooth function; or the true value
 of the integral is 0. Increasing the value of the GlobalAdaptive option 
MaxErrorIncreases might lead to a convergent numerical integration. 
NIntegrate obtained -7.47918 and 4.45574566213166` for the integral  and 
error estimates. >>


 {50349.7, -7.47918}

   In[33]:= (h7 = 
   NIntegrate[
f7[y0, y1, y2, y3, y4, y5, y6, y7]*
 Log[f7[y0, y1, y2, y3, y4, y5, y6, y7]/
   f6[y0, y1, y2, y3, y4, y5, y6]], {y0, -Infinity, 
 Infinity}, {y1, -Infinity, Infinity}, {y2, -Infinity, 
 Infinity}, {y3, -Infinity, Infinity}, {y4, -Infinity, 
 Infinity}, {y5, -Infinity, Infinity}, {y6, -Infinity, 
 Infinity}, {y7, -Infinity, Infinity}, MaxRecursion -> 100, 
Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 10000, 
  Method -> "GaussKronrodRule"}]) // Timing

Out[33]= $Aborted

Use ?NumericQ for dhe definition of f6 in order to force it to be evaluated only when it has got numerical values from the h7 - Integration.

I first got a result with a very large error after one day of calculation on a intel i7 4790 Processor. To get a better result, you should try the code wiht higher MaxErrorIncreases. Attention:This may take a few days of calculation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.