Integrate vs. NIntegrate in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter nnnrocks
  • Start date Start date
  • Tags Tags
    Integrate Mathematica
Click For Summary
SUMMARY

The discussion focuses on the discrepancies between the results of the Integrate and NIntegrate functions in Mathematica when evaluating the integral of Exp[-I*t*x - t^2/2] from -infinity to infinity. It is established that NIntegrate requires high precision settings to yield accurate results, particularly as the variable x increases. For instance, using WorkingPrecision of 40 and PrecisionGoal of 6 provides accurate results for x = 10, while a lower precision fails to converge. Users must adjust the WorkingPrecision based on the magnitude of x to ensure reliable outputs.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of numerical integration techniques
  • Knowledge of complex functions and oscillatory behavior
  • Experience with precision settings in numerical computations
NEXT STEPS
  • Explore advanced settings in NIntegrate for handling oscillatory integrals
  • Learn about the implications of WorkingPrecision and PrecisionGoal in Mathematica
  • Investigate the differences between Integrate and NIntegrate in Mathematica
  • Study techniques for improving convergence in numerical integration
USEFUL FOR

Mathematica users, mathematicians, physicists, and engineers who require accurate numerical integration for complex functions, especially those dealing with oscillatory behavior.

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
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 34 ·
2
Replies
34
Views
5K
  • · 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
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K