# A numerical integration high precision calculation problem

**URL:** <https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605>\
**Category:** Questions\
**Tags:** calculus, numerical-computation\
**Created:** [February 17, 2024, 10:24am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605 "2024-02-17T10:24:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 17, 2024, 10:24am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/1 "2024-02-17T10:24:23Z")

</div>

I tried many times but couldn’t get a high precision calculation

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/52379494-e40a-4048-8035-ecaa7a9d8a5c)

 ![一个操蛋的数值积分.png](https://global.discourse-cdn.com/wolfram/original/3X/c/4/c4dfc96bbbe6001acbd7ddb5036e23a6b2833448.png)

[未命名-1.nb](https://community.wolfram.com/uploads/short-url/pGdINfexzekhYKkqeEFDpS5DHr5.nb) (3.82 KB)

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [February 17, 2024, 4:09pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/2 "2024-02-17T16:09:01Z")

</div>

I used the following combination of methods for rapidly oscillating functions:

```
Method -> {"ExtrapolatingOscillatory", Method -> "Trapezoidal"} 

```

And the next result is silently within a second:

```
In: NIntegrate[Abs[Sin[x^4]]/(Sqrt[x] + x^2), {x, 0, \[Infinity]}, 
 Method -> {"ExtrapolatingOscillatory", Method -> "Trapezoidal"}, 
 MaxRecursion -> 100, WorkingPrecision -> 10] 
Out: 0.5988992624

```

But when I try to increase `WorkingPrecision` to `11` everything hangs ((

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [February 17, 2024, 4:55pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/3 "2024-02-17T16:55:56Z")

</div>

I tried a change of variables:

```
IntegrateChangeVariables[
 Inactive[Integrate][Abs[Sin[x^4]]/(Sqrt[x] + x^2),
  {x, 0, \[Infinity]}],
 t, t == x^4]

```

The decay at infinity is `1/t^(5/4)`, rather slow. Integrating by part will make the decay faster, but the `Abs` forces to divide into intervals.

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [February 17, 2024, 5:11pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/4 "2024-02-17T17:11:31Z")

</div>

I strongly suspect your are confusing [`WorkingPrecision`](https://reference.wolfram.com/language/ref/WorkingPrecision.html) with [`PrecisionGoal`](https://reference.wolfram.com/language/ref/PrecisionGoal.html).

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [February 17, 2024, 9:51pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/5 "2024-02-17T21:51:17Z")

</div>

After a change of variables, maybe integrate several cycles and then replace sine by its average. The change of variables may not be important, but I did it early in searching for a solution to make it easier (for my brain) to locate the singularities.

```
integrand = 
 Abs[Sin[x^4]]/(Sqrt[x] + x^2) Dt[x, u] /. x -> (Pi*u)^(1/4) // 
  Simplify[#, u > 0] &
avgSine = Integrate[Sin[\[Pi] u], {u, 0, 1}];

(* (\[Pi]^(1/8) Abs[Sin[\[Pi] u]])/((4 + 4 \[Pi]^(3/8) u^(3/8)) u^(7/8)) *)

Block[{n = 10000},
 NIntegrate[integrand, Evaluate@Flatten@{u, Range[0, n]}] + 
  avgSine*Integrate[(\[Pi]^(1/8))/((4 + 4 \[Pi]^(3/8) u^(3/8)) u^(7/8)), {u, n, Infinity}]
 ]

(* 0.6182229377606695` *)

```

The solution with `n = 100000`, which differs from the above in around the 11th digit:

```
(* 0.618222937758045` *)

```

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 18, 2024, 4:48am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/6 "2024-02-18T04:48:28Z")

</div>

In fact, I’ve already tried…

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 18, 2024, 4:58am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/7 "2024-02-18T04:58:02Z")

</div>

I tried to copy the learning document method, but it didn’t work, so I would like to ask you to try. (I also tried Maple, but the results were disappointing)

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 18, 2024, 5:04am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/8 "2024-02-18T05:04:04Z")

</div>

Thank you for your reply. I really feel helpless about the problem

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 18, 2024, 5:22am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/9 "2024-02-18T05:22:51Z")

</div>

Yes, I tried for a long time, but the problem is still there. I don’t have enough knowledge to solve it

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [February 18, 2024, 9:56am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/10 "2024-02-18T09:56:21Z")

</div>

**Maple** solution see [here](https://www.mapleprimes.com/questions/237834-Compute-Integral-In-Maple-Numerically-)

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 18, 2024, 2:05pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/11 "2024-02-18T14:05:07Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![nbbienia](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nbbienia](https://community.wolfram.com/u/nbbienia)\
**Post date:** [February 18, 2024, 4:53pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/12 "2024-02-18T16:53:52Z")

</div>

This sort of integrals can probably be evaluated correctly by using double exponential quadratures, see, for example, Ooura and Mori, “The double exponential formula for oscillatory functions over the half infinite interval”, J. Comput. Appl. Math. 38(1991)353-360.  
However, my attempts to use double exponential quadratures in MATHEMATICA were not successful.  
L.B.

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [February 18, 2024, 8:32pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/13 "2024-02-18T20:32:43Z")

</div>

> However, my attempts to use double exponential quadratures in MATHEMATICA were not successful.

In your attempts, did you use the methods [“DoubleExponential”](https://reference.wolfram.com/language/tutorial/NIntegrateIntegrationStrategies.html#526196975) or [“DoubleExponentialOscillatory”](https://reference.wolfram.com/language/tutorial/NIntegrateIntegrationStrategies.html#48895312)? Over this integral or (also) others?

---

<div class="post-metadata">

**Author:** ![nbbienia](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nbbienia](https://community.wolfram.com/u/nbbienia)\
**Post date:** [February 18, 2024, 11:08pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/14 "2024-02-18T23:08:02Z")

</div>

I don’t remember now. It was a few years ago. But I wanted to integrate a non-oscillatory integrand with a hard singularity at x=0, and I finally succeeded by not using double exponential formulae.  
L.B.

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [February 18, 2024, 11:49pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/15 "2024-02-18T23:49:07Z")

</div>

Using the method [“DoubleExponentialOscillatory”](https://reference.wolfram.com/language/tutorial/NIntegrateIntegrationStrategies.html#48895312) works, at least to a point, but it is slow:

```mathematica
AbsoluteTiming@
 NIntegrate[Abs[Sin[x^4]]/(Sqrt\[x\] + x^2), {x, 0, \[Infinity]}, 
  Method -> {"DoubleExponentialOscillatory", 
    Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 10^6}, 
    "SymbolicProcessing" -> 0}, PrecisionGoal -> 4, 
  MaxRecursion -> 40]

```

```auto
NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 1000000 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 0.6184623212443172` and 0.0007604000503125842` for the integral and error estimates.

{117.819, 0.618462}

```

```mathematica
In[1]:= AbsoluteTiming@
 NIntegrate[Abs[Sin[x^4]]/(Sqrt\[x\] + x^2), {x, 0, \[Infinity]}, 
  Method -> {"DoubleExponentialOscillatory", 
    Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 10^6}, 
    "SymbolicProcessing" -> 0}, PrecisionGoal -> 4, 
  MaxRecursion -> 40, WorkingPrecision -> 30]

```

```auto
DynamicNIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.Dynamic

DynamicNIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 1000000 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 0.618315690550426459312705456807`30. and 0.00046796568836866222451442302407`30. for the integral and error estimates.Dynamic

{6215.76, 0.618315690550426459312705456807}

```

From the messages it seems that we can trust the first three significant digits, `0.618`, and those results agree with the earlier posted results.

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [February 19, 2024, 6:33pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/16 "2024-02-19T18:33:47Z")

</div>

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/0d94b999-105b-47a0-8781-259f71d40242)

---

<div class="post-metadata">

**Author:** ![2921276963](https://avatars.discourse-cdn.com/v4/letter/2/bbce88/32.png) [@2921276963](https://community.wolfram.com/u/2921276963)\
**Post date:** [February 20, 2024, 4:12am UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/17 "2024-02-20T04:12:20Z")

</div>

Your answer gave me a lot of help, thank you very much!

---

<div class="post-metadata">

**Author:** ![antononcube](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/antononcube/32/7348_2.png) [@antononcube](https://community.wolfram.com/u/antononcube)\
**Post date:** [February 20, 2024, 2:48pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/18 "2024-02-20T14:48:04Z")

</div>

Very nice! This should be a separate Community post.

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [February 20, 2024, 4:54pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/19 "2024-02-20T16:54:04Z")

</div>

Using a [Evaluating integrals over the positive real axis](https://en.wikipedia.org/wiki/Laplace_transform#Evaluating_integrals_over_the_positive_real_axis):

```
S = IntegrateChangeVariables[Inactive[Integrate][Abs[Sin[x^4]]/(Sqrt[x] + x^2), {x, 0, Infinity}], t, t == x^4];

int = LaplaceTransform[Numerator[S[[1]]], t, x]*InverseLaplaceTransform[1/Denominator[S[[1]]], t, x]

(* (x^(1/4) Coth[(\[Pi] x)/2] MittagLefflerE[3/8, 5/4, -x^(3/8)])/(4 (1 + x^2)) *)

NIntegrate[int, {x, 0, Infinity}, Method -> "GlobalAdaptive", WorkingPrecision -> 50, PrecisionGoal -> 25, MaxRecursion -> 25]

(* 0.61822293775804867431044812335205529689707962742130 *)

```

Regards M.I.

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [February 20, 2024, 5:10pm UTC](https://community.wolfram.com/t/a-numerical-integration-high-precision-calculation-problem/23605/20 "2024-02-20T17:10:21Z")

</div>

Nice!
