# Inconsistent results between NIntegrate and Integrate

I get these inconsistent results

What is going wrong? Fast oscillating terms? Small exponential factors? But then, why the result seems to toggle between values 1 and 2, rather than being a real number?

EDIT:

Module[{\[Beta] = 1.0, \[Epsilon] = 0.99},
NIntegrate[2/(\[Pi] (1 + E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r - \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + 2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2)) E^(-2 \[Beta]^2 (1 - \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]), {\[Alpha]r, -50, 50}, {\[Alpha]i, -50, 50}]]

Module[{\[Beta] = 4.0, \[Epsilon] = 0.99},
NIntegrate[2/(\[Pi] (1 + E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r - \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + 2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2)) E^(-2 \[Beta]^2 (1 - \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]), {\[Alpha]r, -50, 50}, {\[Alpha]i, -50, 50}]]

• Please upload your equations as copy-paste-able Mathematica code so that potential respondents can copy it to their notebooks and experiment with it. Thanks.
– Syed
May 6 at 9:04
• c'mon @m135, you have been around before, you should know by now that we considered it helpful and polite to show your own efforts and share your data and code attempts in a well formatted form, so we can copy, paste and quickly see the problem you are facing. May 6 at 9:22

If you look at the result of

\[Alpha]=4;\[Epsilon]=99/100;Plot3D[2/(\[Pi] (1 +  E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r -
\[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2)) E^(-2 \[Beta]^2 (1 - \[Epsilon]^2))
Cos[4 \[Alpha]i \[Beta] \[Epsilon]]), {\[Alpha]r, -10, 10}, {\[Alpha]i, -2, 2},
PlotRange -> All, PlotPoints -> 50, WorkingPrecision->20]


you will see a weird plot. Outside of this rectangle the integrand takes very small values, e.g. N[2/(\[Pi] (1 + E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r - \[Beta] \ \[Epsilon])^2 + \[Alpha]i^2)) + E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + 2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2)) E^(-2 \[Beta]^2 (1 - \ \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]) /. {\[Alpha]r -> 10, \[Alpha]i -> 10}] results in 1.80913*10^-119. Because of the big ranges of the integration {\[Alpha]r, -50, 50} and {\[Alpha]i, -50, 50} NIntegrate produces an incorrect result

\[Beta] = 4; \[Epsilon] = 99/100; NIntegrate[2/(\[Pi] (1 +
E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r - \[Beta] \[Epsilon])^2 + \[Alpha]i^2))
+ E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2))
E^(-2 \[Beta]^2 (1 - \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]),
{\[Alpha]r, -50,  50}, {\[Alpha]i, -50, 50}, WorkingPrecision -> 15]


1.00000000055400

without any warning and error communication. This definitely is a bug.

A narrowing of the ranges of the integration is a workaround. Indeed,

Integrate[ 2/(\[Pi] (1 +  E^(-2 (\[Beta]^2))))
(E^(-2 ((\[Alpha]r - \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2))
E^(-2 \[Beta]^2 (1 - \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]), {\[Alpha]r, -50,  50},
{\[Alpha]i, -50, 50}] // N


2. + 0. I

The same result is obtained when integrating over {\[Alpha]r, -10, 10}, {\[Alpha]i, -3, 3}. This is in accordance with

NIntegrate[ 2/(\[Pi] (1 + E^(-2 (\[Beta]^2))))
(E^(-2 ((\[Alpha]r - \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) +
2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2))
E^(-2 \[Beta]^2 (1 - \[Epsilon]^2)) Cos[4 \[Alpha]i \[Beta] \[Epsilon]]),
{\[Alpha]r, -10,  10}, {\[Alpha]i, -3, 3}, WorkingPrecision -> 15]


1.99999980395600

• We also may widen the ranges: NIntegrate[ 2/(\[Pi] (1 + E^(-2 (\[Beta]^2)))) (E^(-2 ((\[Alpha]r - \[Beta] \ \[Epsilon])^2 + \[Alpha]i^2)) + E^(-2 ((\[Alpha]r + \[Beta] \[Epsilon])^2 + \[Alpha]i^2)) + 2 E^(-2 (\[Alpha]r^2 + \[Alpha]i^2)) E^(-2 \[Beta]^2 (1 - \ \[Epsilon]^2)) Cos[ 4 \[Alpha]i \[Beta] \[Epsilon]]), {\[Alpha]r, -Infinity, Infinity}, {\[Alpha]i, -Infinity, Infinity}, WorkingPrecision -> 15] results in 1.99998076288872. May 6 at 15:39