Mathematica Mathematica: Evaluating integral numerically

Click For Summary
The user is experiencing issues with numerical integration in Mathematica, specifically with the NIntegrate function, which fails due to unassigned variable values and loss of precision. After attempting to normalize a Gaussian function, the user still encounters problems, particularly with convergence warnings when integrating over large domains. Suggestions include integrating over smaller ranges for better accuracy and reformulating the integral to improve convergence. The discussion highlights the importance of proper variable assignment and the potential pitfalls of working with very small values in numerical calculations. Overall, the user is seeking effective strategies to resolve these integration challenges.
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 13 ·
Replies
13
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 58 ·
2
Replies
58
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
4K