TransWikia.com

Problem with NIntegrate over a piecewise function

Mathematica Asked by S. DENG on January 26, 2021

The following code seems to generate wrong results

q2 = 1/y^0.9;
G2 = 1.1 x^0.045;
b2bar = x /. Solve[G2 == 1, x][[1]]
ff = FullSimplify[PiecewiseExpand[D[Min[G2, 1], x]*x*q2]]
NIntegrate[ff, {y, 0, 1}, {x, y, b2bar}]
NIntegrate[ff, {y, 0, 1}, {x, y, 1}]

Since ff=0 for x>=b2bar, one would expect NIntegrate[ff, {y, 0, 1}, {x, y, b2bar}] and NIntegrate[ff, {y, 0, 1}, {x, y, 1}] to generate the same results. But NIntegrate[ff, {y, 0, 1}, {x, y, b2bar}] gives 0.038246 and NIntegrate[ff, {y, 0, 1}, {x, y, 1}] gives 0.022375.

Is there an error with NIntegrate when integrating piecewise functions? How can I avoid this?

2 Answers

As I mentioned in a comment, NIntegrate does solve the condition 1.1 x^0.045 < 1 for the singularity at x == b2bar and this causes a problem with the integration, which is itself an issue. But that issue can be avoided by reducing the condition to something NIntegrate can handle. If we throw in the domain restriction 0 <= x <= 1 && 0 <= y <= 1 from the integral, or just the x component 0 <= x <= 1, then Reduce will solve the condition.

ff = PiecewiseExpand[D[Min[G2, 1], x]*x*q2,
  Method -> {"ConditionSimplifier" -> (Quiet[
        Reduce[# && 0 <= x <= 1, x, Reals], Reduce::ratnz] &)}]
NIntegrate[ff, {y, 0, 1}, {x, y, 1}]

Mathematica graphics

Correct answer by Michael E2 on January 26, 2021

If your second numerical integration uses appropriate options nearly the same results are obtained.

(Those options can be figured out from the messages NIntegrate issues while evaluating your second integral.)

One such way is:

NIntegrate[ff, {y, 0, 1}, {x, y, 1}, 
 Method -> {"GlobalAdaptive", "MaxErrorIncreases" -> 10^6}, 
 MaxRecursion -> 1000]

Here is another:

NIntegrate[ff, {y, 0, 1}, {x, y, 1}, MinRecursion -> 3]

(See res3 and res4 in the attached screenshot.)

enter image description here

Answered by Anton Antonov on January 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP