Integrate function fails without warning

3 views (last 30 days)
George Swadling
George Swadling on 21 Jan 2016
Edited: John D'Errico on 21 Jan 2016
I came across a problem while trying to run a physics calculation for a project. The integrate function fails without warning, giving a result substantially lower than the true value. In the attached script I have included both versions of the calculation. These are mathematically identical but give very different results. The failure of the integration may be related to the large exponents of some of the input parameters, however the function gives no error message to suggest it has run into a problem. This is worrying to me as I use MATLAB for these type of calculations regularly and I am now worried that I cant trust my results. Can anyone see if I have made a glaring mistake?
Many thanks,
George

Answers (1)

John D'Errico
John D'Errico on 21 Jan 2016
Edited: John D'Errico on 21 Jan 2016
Your mistake on these things is in understanding numerical integration and probably of floating point arithmetic.
Numerical integration tools are not prescient. They evaluate the function that you supply. If the function is essentially a delta function, i.e., zero everywhere that they look (to within the supplied tolerance) then they will tell you the integral is zero, or some equivalently small number. The integration tool cannot do more than that, nor should you expect it to do so.
Anyway, how could you expect the tool to return a warning? Suppose I chose a function that was essentially identically zero everywhere, except at some point that I won't tell you about, where there is the equivalent of a delta function. How could an integration tool know where to look for the spike in the integrand, if it sees only zero? Now suppose I chose to give you the same function, but without that spike?

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!