Fixing Complex Results in NIntegrate: Tips and Tricks | Anna

  • Thread starter Thread starter Anna Kaladze
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on resolving complex results encountered when using the NIntegrate function in Mathematica, specifically when combined with the Table command. User Anna seeks to obtain real numerical outputs instead of complex values from her integration process. Key solutions include applying the Chop function to eliminate small imaginary parts and converting approximate numbers to rational values to ensure real results. Additionally, users suggest contacting Wolfram Support for further investigation into potential computational errors or bugs.

PREREQUISITES
  • Familiarity with Mathematica 12.0 and its NIntegrate function
  • Understanding of numerical integration techniques
  • Knowledge of complex numbers and their manipulation in computational contexts
  • Experience with Mathematica's Simplify and Chop functions
NEXT STEPS
  • Learn how to effectively use the Chop function in Mathematica to handle complex results
  • Explore the implications of using rational numbers in numerical computations
  • Investigate the EvaluationMonitor option in NIntegrate for debugging integration issues
  • Contact Wolfram Support to report and inquire about potential bugs in Mathematica's integration algorithms
USEFUL FOR

Mathematica users, data analysts, and researchers involved in numerical integration who are encountering complex outputs and seeking reliable methods to obtain real numerical results.

Anna Kaladze
Messages
34
Reaction score
0
Hi all,

I need to numerically integrate a function by utilizing “Table” command in the process (please see the code below), but for the parameter values I am interested in, I get complex results. I do not know why this is happening. Also, how do I get "normal" real values instead, while also ensuring that the answer is reasonably correct which one would expect from NIntegrate command.
Thanks a lot.
Anna.

Table[NIntegrate[((1-(u/40)^2.5)*((1/((1+0.06*(u-t)))))/Exp[0.01*u*(1.5-1)])^(1/1.5),{u,t,40}],{t,0,40,1}]
 
Physics news on Phys.org
START HERE:
Input: Simplify[((1 - (1/40)^2.5)*((1/((1 + 0.06*(u - t)))))/
Exp[0.01*u*(1.5 - 1)])^(1/1.5)]
Output:0.999934 (E^(-0.005 u)/(1.\[VeryThinSpace]- 0.06 t + 0.06 u))^0.666667
then take the output and apply the first problem:
SECONDINPUT=Table[NIntegrate[FIRST_OUTPUT,{u,t,40}],{t,0,40,1}]
FinalOutput: = {23.7852, 23.3174, 22.8465, 22.3722, 21.8946, 21.4134, 20.9286, \
20.4398, 19.9471, 19.4501, 18.9487, 18.4426, 17.9318, 17.4159, \
16.8947, 16.3679, 15.8353, 15.2965, 14.7514, 14.1994, 13.6403, \
13.0736, 12.499, 11.916, 11.3241, 10.7228, 10.1115, 9.48957, 8.85635, \
8.21107, 7.55291, 6.88097, 6.19424, 5.4916, 4.7718, 4.03346, 3.27498, \
2.49459, 1.69024, 0.859616, 0.}
I'm no expert, but perhaps Mathematica is getting computational error with what you have given it?
Observe the final answer has only real solutions.
Why did it happen,... don't know... is "Simplify" a "safe" transformation... Yes, usually
 
@brydustin
Using Simplify did not do the trick for me... I don't know why it worked for you but not for me.

@Anna
The imaginary parts are all very small and below machine precision - they can be removed by applying Chop to the result.
Alternatively, if you turn all of the approximate numbers you gave it into rationals, then the result is completely real and identical to that obtained with Chop.

As to how the imaginary parts get there in the first place, I'm not completely sure.
Obviously, raising things to real powers has room for the wrong branch to be chosen somewhere. But using EvaluationMonitor :> Sow to extract the points at which the integrand is evaluated and looking at the integrand at those points shows no problems.

Or maybe if the outside exponent is brought inside incorrectly during the SymbolicProcessing there could be problems. But turning it off using Method -> {Automatic, "SymbolicProcessing" -> 0} yields the same results. As does choosing different explicit integration methods.

Maybe you should send a quick email to Wolfram Support and ask them if they can figure out where the imaginary parts come from... it might even be a small bug in the system and everyone wins when they're fixed!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
5
Views
8K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K