Fixing Complex Results in NIntegrate: Tips and Tricks | Anna

  • Thread starter Anna Kaladze
  • Start date
In summary, using the Table command to numerically integrate a function can result in complex results, but "normal" real values can be obtained by turning the imaginary parts into rationals.
  • #1
Anna Kaladze
35
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
  • #2
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
 
  • #3
@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!
 

1. What is NIntegrate?

NIntegrate is a function in the Wolfram Language that is used for numerical integration, also known as the process of finding the area under a curve.

2. What is a problem with NIntegrate?

One common problem with NIntegrate is that it can be computationally expensive and may take a long time to calculate the integral, especially for more complex functions or larger intervals.

3. How can I improve the performance of NIntegrate?

To improve the performance of NIntegrate, you can try increasing the precision or accuracy settings, using specific integration methods, or breaking the integral into smaller sub-intervals.

4. Can NIntegrate handle singularities or discontinuities in the function?

Yes, NIntegrate has the ability to handle singularities or discontinuities in the function being integrated. However, it may require special treatment or use of specific integration methods to accurately calculate the integral.

5. Are there alternative functions to NIntegrate for numerical integration?

Yes, there are alternative functions such as NDSolve, Integrate, and FindMinimum that can also perform numerical integration in the Wolfram Language. It is recommended to try different functions and compare the results to find the most accurate and efficient solution for your specific problem.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
218
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
8K
  • Calculus and Beyond Homework Help
Replies
1
Views
670
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Precalculus Mathematics Homework Help
Replies
21
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top