# NIntegrate returned complex value for non-complex integrand

**URL:** <https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864>\
**Category:** Questions\
**Tags:** mathematica, calculus, numerical-computation\
**Created:** [August 5, 2014, 5:28pm UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864 "2014-08-05T17:28:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnskzn1](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dnskzn1](https://community.wolfram.com/u/dnskzn1)\
**Post date:** [August 5, 2014, 5:28pm UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864/1 "2014-08-05T17:28:02Z")

</div>

(Note the different MinRecursion values.)

```
NIntegrate[MyD[0.001, Ez, Ep, 10, 2, WLU, WRD, mLUPi, m1i, mRDOWNi], {Ez, -((mRDOWNi/mLUPi)*WRD + 
     e*0.001), -((mRDOWNi/mLUPi)*(WRD + e*0.001))}, {Ep, (-e*0.001 - Ez), (mRDOWNi/(mLUPi - mRDOWNi))*(Ez + WRD + e*0.001)}, MinRecursion -> **4** ]

OUT= 1.08254*10^-13 + 7.38211*10^-35 I

NIntegrate[MyD[0.001, Ez, Ep, 10, 2, WLU, WRD, mLUPi, m1i, mRDOWNi], {Ez, -((mRDOWNi/mLUPi)*WRD + 
     e*0.001), -((mRDOWNi/mLUPi)*(WRD + e*0.001))}, {Ep, (-e*0.001 - Ez), (mRDOWNi/(mLUPi - mRDOWNi))*(Ez + WRD + e*0.001)}, MinRecursion -> **5** ]

OUT= 1.08254*10^-13

```

You can check the attached file

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [August 5, 2014, 8:43pm UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864/2 "2014-08-05T20:43:17Z")

</div>

NIntegrate is a numerical algorithm, so its answer is not exact.

---

<div class="post-metadata">

**Author:** ![dnskzn1](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dnskzn1](https://community.wolfram.com/u/dnskzn1)\
**Post date:** [August 6, 2014, 5:15am UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864/3 "2014-08-06T05:15:45Z")

</div>

In my case the integrand cannot be complex in the limits on integration.

When i’m changing the integrand to Im[integrand]:

NIntegrate[Im[MyD[0.001, Ez, Ep, 10, 2, WLU, WRD, mLUPi, m1i, mRDOWNi]], {Ez, -((mRDOWNi/mLUPi)_WRD + e_0.001), -((mRDOWNi/mLUPi)_(WRD + e_0.001))}, {Ep, (-e_0.001 - Ez), (mRDOWNi/(mLUPi - mRDOWNi))_(Ez + WRD + e\*0.001)}, **MinRecursion → 90, MaxRecursion → 100** ]

the output is:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option. \>\>

1.

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [August 6, 2014, 12:54pm UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864/4 "2014-08-06T12:54:43Z")

</div>

Some of the techniques for numerical integration involve the complex plane, so it’s not surprising that a result from NIntegrate could have a very small imaginary part from an integral that’s real.

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [August 6, 2014, 2:22pm UTC](https://community.wolfram.com/t/nintegrate-returned-complex-value-for-non-complex-integrand/2864/5 "2014-08-06T14:22:13Z")

</div>

Numerical Integration involves evaluating the integrand not only at the limits of integration but at points inbetween them as well. So if there’s anywhere in the domain of the integration where a numerical evaluation could produce a slightly complex value due to floating point inaccuracy, you will see this behavior.

NIntegrate is a complex beast. It is both a numerical algorithm and a symbolic one. Unless you ask it not to, NIntegrate will symbolically analyze your input and find equivalent Integrals to give a quicker or better answer. There’s no guarantee that the new integral won’t introduce a trivial imaginary value.

Normally, you use the Chop function along with the result of NIntegrate to remove such small imaginary values.

Alternatively, you can pick a numerical method for NIntegrate to use with Method option that prevents it from doing anything which might introduce a complex value. This generally isn’t worth the headache. I’d use Chop.
