0
$\begingroup$

Let us consider the definite integral $$\int\limits_0^1\frac{1}{-\sin \left(\frac{355 x}{113}\right)-\sin (\pi x)+2}\,dx.$$

The integrand has the sharp maximum at approximately x==1/2 as

Plot[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1},  PlotRange -> {0, 1000}]

enter image description here

and

1/(2 - Sin[Pi*x] - Sin[355/113*x]) /. x -> 0.5

1.1259*10^14

show. Let us calculate its numerical value by

NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1}, WorkingPrecision -> 500]

1.2362169441996136851883195633922114040481857268750706513973706856485258255036921164094489402293477582881130975970830174783445922472199291683034580223409700064733593412912404064803381979555313504509727777905495203840976429627566636757997635903087515772977188679568523976731890867113508843031431576691732124347894884567712227795096153264965184100880948635131023672835134263978050533965702731340161896810515594850298388648619221758337473963896532597731360204009495075235122659383639365026092262109738888*10^7

and

NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1}, WorkingPrecision -> 1000]

1.001238555284578042264617144192400882420859884217313673973393029717575862379157756534310218994101070236160802301957339871913913756328227472506781430533481037902156433981036539993869651405529876630723938976081293563905374365419140155264038994215106030388424098155233913474224499823849830641075764497571015128909503298524419408682320418929661264138488676605033434972671072242011026479745573132128871944031984928168529268107459810009286814370366477980818868498042156604771607758181001778158976146808678042800024409528816766163438147284276803597703017272639164188183298370503946710095132978382457347421323244213392134426628339851044899564836060073374226540743034549243746615692589205033957730838390841727891835162993345859514680681840739765635659862420614154264942957376804156215178774043250223996004039988875402248125243337150092116281087960046032952525230784220279493253698303801199053339187333072097391177874201614455353679697657089606621124448308475019101617295155680442626137130223538965822513429241*10^7

As we see, the results differ. Up to Maple, this value equals 1.499451605234141071490295*10^7.

The question arises: what is the true value of this integral?

$\endgroup$
6
  • $\begingroup$ I much dislike the above results are performed without any warnings. $\endgroup$
    – user64494
    Commented Feb 17 at 21:15
  • 2
    $\begingroup$ Well, more or less your integral manifests the first pathology described in NIntegrate's advanced documentation. (See the sub-section "Tricking the error estimator" in the section "Examples of Pathological Behavior".) $\endgroup$ Commented Feb 17 at 22:16
  • $\begingroup$ @AntonAntonovv: No, this is not it: the receipt there is NIntegrate[f[x], {x, 0, 1}, Method -> "GlobalAdaptive", MaxRecursion -> 20, PrecisionGoal -> 12]. $\endgroup$
    – user64494
    Commented Feb 18 at 5:27
  • $\begingroup$ "No, this is not it: the receipt there is [..]" -- Yes, it is. It is the same pathology, with more or less the same fix. $\endgroup$ Commented Feb 18 at 14:20
  • 1
    $\begingroup$ Hmm... What is emotional about my argument? Do you understand my statement? Can you see the similarity between the two integrals? Can you see the similarity between the options given to NIntegrate? $\endgroup$ Commented Feb 18 at 20:19

2 Answers 2

4
$\begingroup$

You can get a result close to Maple's using the method "LocalAdaptive":

NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1}, 
  MinRecursion -> 3, MaxRecursion -> 100, Method -> "LocalAdaptive", 
  PrecisionGoal -> 10] // InputForm

(* 1.4994515633482287*^7 *)

I have not looked into Maple's numerical integration algorithms for more than 15 years, but I remember that at the time their default (and only) integration strategy was similar to "LocalAdaptive".


Using "GlobalAdaptive" with larger recursion start- and end values:

NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1}, 
 MinRecursion -> 6, MaxRecursion -> 100, 
 Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 10^8}, 
 PrecisionGoal -> 10, WorkingPrecision -> 30]

(* 1.49945160523414228214390320871*10^7 *)

NIntegrate allows custom breakdown of the integration ranges.

For example, let us try to "isolate" the max point:

Reduce[{-((-(355/113) Cos[(355 x)/
       113] - \[Pi] Cos[\[Pi] x])/(2 - Sin[(355 x)/113] - 
      Sin[\[Pi] x])^2) == 0, 0 <= x <= 1}, x]

(* x == Root[{
  355 Cos[Rational[355, 113] #] + 113 Pi Cos[Pi #]& , 
   0.49999997877158033540739364320327348112`20.331736988545668}] *)

N[ToRules[%], 100]

(* {x -> 0.4999999787715803354073608859722141098496639023446210807132737788751325902685677891429692202993799552} *)
Block[{c = 10^(-7)},
 Plot[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 1/2 - c, 1/2 + c}, 
  PlotRange -> All, MaxRecursion -> 15]
 ]

enter image description here

Then we can integrate like this:

Block[{c = 10^(-7)},
 NIntegrate[
  1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1/2 - c, 1/2 + c, 1}, 
  MaxRecursion -> 100, WorkingPrecision -> 30, PrecisionGoal -> 10]
 ]

(* 1.49945160523414228208295107976*10^7 *)
$\endgroup$
3
$\begingroup$

You may help MMA a bit by splitting the integration range into 3 pieces. The first one the easy piece from 0 up to near the peak, the second over the peak, where you also specify "Method->"LocalAdaptive"". And the third from after the peak up to 1

NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 0, 1/2 - 0.001}] + 
 NIntegrate[
  1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 1/2 - 0.001, 1/2 + 0.001}, 
  Method -> "LocalAdaptive"] +
 NIntegrate[1/(2 - Sin[Pi*x] - Sin[355/113*x]), {x, 1/2 + 0.001, 1}]

1.49888*10^7
$\endgroup$
2
  • $\begingroup$ +1 though I prefer the Anton Antonov's answer. $\endgroup$
    – user64494
    Commented Feb 17 at 20:55
  • $\begingroup$ I much dislike too small precision without any warning. $\endgroup$
    – user64494
    Commented Feb 17 at 21:59

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.