Mathematica: Evaluating integral numerically

  • Context: Mathematica 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Integral Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the challenges faced by a user attempting to evaluate an integral numerically in Mathematica. The focus is on troubleshooting issues related to the NIntegrate function, including variable assignments, precision loss, and convergence problems. Participants explore potential corrections and adjustments to the integral setup.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant notes that NIntegrate requires all variables to have numeric values assigned, indicating that the absence of a value for 'f' is causing issues.
  • Another participant mentions that assigning a value to 'f' leads to warnings about loss of precision, suggesting that accumulated uncertainty may be affecting the results.
  • Concerns are raised about Underflow results when evaluating the product of functions over a large range, indicating that the output may be too small to be represented accurately.
  • A participant suggests that integrating a Gaussian function over its entire range should yield a result of 1, questioning the scaling factor applied by the user.
  • There is a suggestion to reformulate the integral to achieve faster convergence and avoid warnings, with a reference to a book that may provide guidance on problem posing for accurate results.
  • The user expresses uncertainty about the reformulation of the integral and the reasons behind the difficulties encountered with NIntegrate.

Areas of Agreement / Disagreement

Participants express varying opinions on the causes of the issues with NIntegrate, with no consensus on a definitive solution. There are multiple competing views regarding the appropriate approach to resolving the numerical evaluation problems.

Contextual Notes

Participants discuss the implications of variable assignments, scaling factors, and integration limits, but there are unresolved mathematical steps and assumptions regarding the behavior of the functions involved.

Niles
Messages
1,834
Reaction score
0
Hi

I am trying to evaluate an integral in Mathematica numerically as I have done many times before, but it simply won't work. To make things easy on everybody, I have attached a notebook with the integral.

I simply can't see what is wrong here. I'd be happy to receive some help.


Niles.
 

Attachments

Physics news on Phys.org
NIntegrate requires that every variable involved have been assigned a numeric value. In your notebook f is not assigned any value. That is why NIntegrate is objecting.

Now if I assign f=1 or f=10^3 or ... and then try the notebook I get a different warning. It claims that it is stopping because of loss of precision. This usually means that during all the calculation enough uncertainty has accumulated that there will be zero or only a few bits of precision left.

If I try evaluating lorentzian[f, Sqrt[x^2+ y^2+ 4*z^2]]*gaussian[x, y, z] for x,y,z in the range of -100...100 I find lots of Underflow[] results. That usually means the result is so small that there isn't a negative exponent big enough to describe it.

Does any of this help? Can you, for example write down what result would be when x,y,z are all -100 or 100 and f is whatever it is supposed to be?

Hint: How small is gaussian[100,100,100]==Exp[-3*(10^2)^2*(10^3)^2]?
 
Last edited:
Hi

Thanks for replying so quickly. It does help -- I think I normalized by Gaussian wrongly. I have corrected it now, and even multiplied by a constant (just to see if it works.. I can always divide it out later).

However NIntegrate still fails. I have uploaded my new attempt. What can I do now?Niles.

EDIT: Actually the upper/lower limits don't really matter. I just randomly chose 100 because I thought the function was practically zero there. 10 might even have done it.
 

Attachments

If you integrate a gaussian from -Infinity to Infinity you get exactly 1, assuming you don't scale this by 10^6 which I do not understand why you are doing. Your first integral is almost exactly that. Integrating over a smaller domain, where you know what the answer should be, is always a good idea so you can check your calculations for correctness.

I'm not certain what your lorentzian integral should give you, but it seems very close to 1.

Your third integral takes forever and gives warnings about convergence, which was what I saw. Integrating between -j and j for j up to 3 rapidly gives a result with no warning. j beyond 3 (far less than your 100) results in warnings that it just isn't finding an answer.

Can you perhaps reformulate your formula to converge much more rapidly to an accurate answer? See if you can find a copy of "Real Computing Made Real" in a library somewhere and read that. That is an excellent book trying to teach people how to pose problems so they get accurate correct answers.
 
The reason for multiplying by 10^6 was because I thought Mathematica was having a difficult time with all the small values.. but I see it doesn't make a difference.

Honestly I'm not sure what is wrong here. Basically we're just adding numbers here, I don't see why NIntegrate finds that so difficult. I'm not sure how to reformulate the ingral.. I mean, it is what it is, but I see why you suggest it.

I'll check out the book, but I'm not optimistic.

Thanks so far.Niles.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 58 ·
2
Replies
58
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
4K