Message Boards Message Boards

0
|
2190 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

NIntegrate error: Integral and error estimates are 0 on all subregions

Posted 1 year ago

Hello, can someone answer my question? I need to integrate a function defined as follow:
enter image description here
In principle, I need the results for n up 100 and the parameter up should be equal to infinity. The integrand is a strongly oscillating function, therefore this is not a simple task. But I get an error message when I ask Mathematica to do a very simple task for me.
Here is the result for n=78 and up=0.4:
enter image description here

The result looks reasonable. And here is what I get when I try to increase n by one (n=79 and up=0.4):
enter image description here
What happens? Plotted are the integrands in both cases; they are quite regular functions. But in the second case Mathematica tells that it cannot integrate such a trivial function and produces the result integral = 0. If I try to increase up, I get the same problem at smaller values of n. Is this a bug in Mathematica? Does someone know, what to do in this case? Many thanks in advance.

5 Replies

Use ?Numeric somewhere before LaguerreL[] is called. A numerically stable algorithm is used to compute its value when its arguments are numerics. Otherwise it expands symbolically (to a numerically unstable polynomial, as the OP noted).

For instance replace the definition of f1 with this:

ClearAll[f1]; (* remove previous definition! *)
f1[n_, Q_?NumericQ] := Exp[-Q^2/4]*LaguerreL[n - 1, 1, Q^2/4];

Then the integral is computed quickly and accurately.

POSTED BY: Michael Rogers

Many thanks for the reply! Well, giving the working precision in this specific case (up=0.4) did help, but when I increased n or took integration intervals with larger 'up', the problem came back again. Finally I realized that the problem is that the integrand is a product of very small (Exp[...]) and very large (LaguerreL[...]) functions, and precision is lost when calculating the product. So, at large values n and 'up' (what I needed) this is probably an unsolvable problem.

I have found another solution to this problem. Thanks everyone for the replies and reading.

Try giving a WorkingPrecision:

NIntegrate[integrand[79, Q], {Q, 0, .4}, WorkingPrecision -> 20]
POSTED BY: Gianluca Gorni

Hello, thanks for the reply! Sorry, my 1st time here. I repeat my question:

Can someone answer my question? I need to integrate a function defined as follow:

bes[x_] := If[x == 0, 1, 2*BesselJ[1, x]/x];
f1[n_, Q_] := Exp[-Q^2/4]*LaguerreL[n - 1, 1, Q^2/4];
f2[n_, Q_] := n*bes[Q*Sqrt[n]];
integrand[n_, Q_] := (f1[n, Q] - f2[n, Q])^2;
result[n_, up_] := NIntegrate[integrand[n, Q], {Q, 0, up}];

In principle, I need the results for n up 100 and the parameter up should be equal to infinity. The integrand is a strongly oscillating function, therefore this is not a simple task. But I get an error message when I ask Mathematica to do a very simple task for me. Here is the result for n=78 and up=0.4:

n = 78;
up = 0.4;
Plot[integrand[n, Q], {Q, 0, up}, PlotRange -> Full]
result[n, up]

The integrand for n=78 and the result of integration

The result 0.01745... looks reasonable. And here is what I get when I try to increase n by one (n=79 and up=0.4):

n = 79;
up = 0.4;
Plot[integrand[n, Q], {Q, 0, up}, PlotRange -> Full]
result[n, up]

The integrand for n=79, the

What happens? Plotted are the integrands in both cases; they are quite regular functions. But in the second case Mathematica tells that it cannot integrate such a trivial function and produces the result integral = 0. If I try to increase up, I get the same problem at smaller values of n. Is this a bug in Mathematica? Does someone know, what to do in this case? Many thanks in advance.

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

The rules explain how to format your code properly. Posting code Images doesn't help other members to copy your code. Please EDIT your post and make sure code blocks start on a new paragraph and look framed and colored like this.

int = Integrate[1/(x^3 - 1), x];
Map[Framed, int, Infinity]

You can also embed notebook or attach notebook.

enter image description here

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract