3
$\begingroup$

I get these inconsistent results enter image description here

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}]]
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Syed
    May 6 at 9:04
  • 3
    $\begingroup$ 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. $\endgroup$
    – rhermans
    May 6 at 9:22

1 Answer 1

4
$\begingroup$

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]

enter image description here

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – user64494
    May 6 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.