Mathematica: Evaluating integral numerically

In summary, Niles is trying to evaluate an integral numerically, but it is not working. He has attached a notebook with the integral, and NIntegrate is objecting because f is not assigned a value. Niles has normalized the value by Gaussian and tried different values for x, y, and z, but still the function fails. NIntegrate warns about loss of precision and convergence issues, but Niles is not sure what is wrong. He has checked out the book "Real Computing Made Real" and is not optimistic.
  • #1
Niles
1,866
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

  • pf.nb
    5.7 KB · Views: 436
Physics news on Phys.org
  • #2
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:
  • #3
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

  • pf.nb
    7.5 KB · Views: 453
  • #4
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.
 
  • #5
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.
 

FAQ: Mathematica: Evaluating integral numerically

What is Mathematica used for?

Mathematica is a computational software program used by scientists, engineers, and mathematicians for performing complex calculations, visualizing data, and creating interactive simulations.

How do I evaluate an integral numerically in Mathematica?

To evaluate an integral numerically in Mathematica, you can use the NIntegrate function. This function takes in the integrand, the limits of integration, and any other necessary parameters, and returns an approximate numerical value for the integral.

Can I use Mathematica to solve differential equations?

Yes, Mathematica has built-in functions for solving both ordinary and partial differential equations. These functions use numerical methods to find approximate solutions to the equations.

What types of integrals can Mathematica evaluate?

Mathematica can evaluate a wide range of integrals, including definite and indefinite integrals, multiple integrals, improper integrals, and symbolic integrals. It can also handle integrals with complex functions and variables.

How accurate are the numerical evaluations in Mathematica?

The accuracy of the numerical evaluations in Mathematica depends on the precision specified by the user. By default, Mathematica uses machine-precision numbers, but you can specify a higher precision for more accurate results. Additionally, Mathematica uses adaptive algorithms to improve the accuracy of the numerical evaluations.

Similar threads

Replies
13
Views
2K
Replies
1
Views
1K
Replies
2
Views
1K
Replies
4
Views
2K
2
Replies
58
Views
6K
Replies
1
Views
2K
Back
Top