Fixing Complex Results in NIntegrate: Tips and Tricks | Anna

  • Thread starter Thread starter Anna Kaladze
  • Start date Start date
AI Thread Summary
Numerical integration using the "Table" command in Mathematica is yielding complex results for certain parameter values, prompting a need for "normal" real values. The discussion suggests that the imaginary parts are minimal and can be eliminated using the Chop function or by converting approximate numbers to rationals. Potential reasons for the emergence of these imaginary components include issues with branch selection during exponentiation or symbolic processing errors. Users recommend contacting Wolfram Support for further investigation into possible bugs. Ensuring accurate real outputs from NIntegrate is essential for reliable computational 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
Views
2K
Replies
4
Views
9K
Replies
3
Views
4K
Replies
0
Views
5K
Replies
2
Views
3K
Replies
21
Views
2K
Replies
2
Views
4K
Back
Top