Mathematica Integrate vs. NIntegrate in Mathematica

Click For Summary
NIntegrate in Mathematica provides accurate results for the integral of Exp[-I*t*x - t^2/2] when x is small, but its accuracy diminishes as x increases. To achieve high precision with NIntegrate, users must adjust the WorkingPrecision and PrecisionGoal settings, particularly for larger values of x. For example, a WorkingPrecision of 40 is necessary for x = 10 to obtain a result close to the exact value. As x increases, such as to 50, a WorkingPrecision greater than 87 is required for accurate results. Properly configuring these parameters is essential for handling oscillatory behavior in complex functions.
nnnrocks
Messages
1
Reaction score
0
I'm trying to integrate the function Exp[-I*t*x - t^2/2] from -infinity to infinity using NIntegrate in Mathematica; the value that I get is accurate when x is small, but as x gets larger, the output from NIntegrate does not match the value I get when I use Integrate -- it gets less and less accurate.
Does anyone know why this happens and what I can do to make sure NIntegrate is giving me accurate answers? (I'm ultimately going to apply NIntegrate to a much more complicated function and I'm using this test function to figure out how to deal with the oscillatory behavior)
 
Physics news on Phys.org
The exact result is $$ e^{-\frac{x^2}{2}} \left(\sqrt{2 \pi }\right) $$

Which for ##x == 10# is 4.83466*10^-22

So you need HIGH precision to recreate that with NIntegrate. You can do that, and set a precision goal by : (In the following the first example is NOT ENOUGH PRECISION, the second is enough )

Code:
With[{x = 10}, 
 NIntegrate[Exp[-I*t*x - t^2/2], {t, -\[Infinity], \[Infinity]}, 
  WorkingPrecision -> 20, PrecisionGoal -> 6]]

This is not enough, and gives
Code:
NIntegrate::ncvb: "\!\(\*
StyleBox[\"\\\"NIntegrate failed to converge to prescribed accuracy after \\\"\", \"MT\"]\)\!\(\* StyleBox[\"9\", \"MT\"]\)\!\(\* StyleBox[\"\\\" recursive bisections in \\\"\", \"MT\"]\)\!\(\* StyleBox[\"t\", \"MT\"]\)\!\(\* StyleBox[\"\\\" near \\\"\", \"MT\"]\)\!\(\* StyleBox[ RowBox[{\"{\", \"t\", \"}\"}], \"MT\"]\)\!\(\* StyleBox[\"\\\" = \\\"\", \"MT\"]\)\!\(\* StyleBox[ RowBox[{\"{\", \"1.255585675845388`\", \"}\"}], \"MT\"]\)\!\(\* StyleBox[\"\\\". NIntegrate obtained \\\"\", \"MT\"]\)\!\(\* StyleBox[ RowBox[{ RowBox[{\"-\", \"1.0581813203458523`*^-16\"1.0581813203458523`*}], \"+\",  RowBox[{\"3.469446951953614`*^-17\"3.469446951953614`*, \" \", \"I\"}]}], \"MT\"]\)\!\(\* StyleBox[\"\\\" and \\\"\", \"MT\"]\)\!\(\* StyleBox[\"6.409147557108418`*^-16\"6.409147557108418`*, \"MT\"]\)\!\(\* StyleBox[\"\"\", \"MT\"]\) for the integral and error estimates.

Code:
With[{x = 10}, 
 NIntegrate[Exp[-I*t*x - t^2/2], {t, -\[Infinity], \[Infinity]}, 
  WorkingPrecision -> 40, PrecisionGoal -> 6]]

This gives
Code:
 4.834658903596599769813455011618390931572*10^{-22} + 
 1.783512275559820938759410037056409076459*10^{-51} i


So youll have to increase your working precision depending on how high "x" is.

For x = 50, you'll have to have the working precision greater than 87 (90 works).
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 58 ·
2
Replies
58
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K