Solving Mathematica Error: NIntegrate::ncvb

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting an error encountered in Mathematica while using the NIntegrate function. Participants explore the causes of the NIntegrate::ncvb error, which indicates a failure to converge to the desired accuracy. The focus includes the mathematical formulation of the integral, the behavior of the loop in the code, and comparisons with Monte-Carlo simulations.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports an error from NIntegrate indicating failure to converge, specifically near a value of x.
  • Another suggests testing individual iterations of the loop to identify which values of yQdB cause the error.
  • Some participants discuss the implications of precision settings and recursion limits, with suggestions to either increase iterations or reduce precision goals.
  • There is mention of discrepancies between numerical results from Mathematica and those from Monte-Carlo simulations, raising questions about the accuracy of the numerical evaluation.
  • Participants express uncertainty about whether the issue lies with Mathematica or the mathematical formulation itself, with one seeking confirmation from calculus forums.
  • Several participants emphasize the importance of clearly defining the integral and using proper notation to avoid mistakes in the code.
  • There is a discussion about the representation of constants in the mathematical integral versus the Mathematica code, with some suggesting that the variable A may not be treated as a constant in the code.
  • One participant notes that the error occurs at almost all values of yQdB when the lower limit of the integral is set to zero.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the error or the best approach to resolve it. Multiple competing views remain regarding the handling of precision, the formulation of the integral, and the interpretation of constants in the code.

Contextual Notes

Limitations include potential undefined cases in the expressions, the dependence on the choice of limits for the integral, and the unresolved nature of the mathematical formulation versus the code implementation.

  • #31
OK, thanks. I'm trying to do the mathematical derivations all over again. But I suspect it's just a technical issue with Mathematica.
 
Physics news on Phys.org
  • #32
Code:
For[yQdB = -10, yQdB <= 15, yQdB++;
 yQ = 10^(yQdB/10);
 INTEGRAND = 
  Simplify[1/x^2*Exp[(GSS*(x + GSS*yQ))/(x*yp) - x]*
    Exp[-(GSS*(x + GSS*yQ))/(x*yp) T]/T];
 A1 = 0.5*((GSS^2)*yQ)/yp*
   NIntegrate[INTEGRAND, {T, 1, \[Infinity]}, {x, Cons, Infinity}, 
    PrecisionGoal -> 5, MaxRecursion -> 12, WorkingPrecision -> 20];
 Print["A1 = ", 0.5*((GSS^2)*yQ)/yp, 
  "\[Times] NIntegrate[  1/x^2\[Times]Exp[ ( ", GSS, "\[Times](x +", 
  GSS*yQ, "))/(x\[Times]", yp, ") - x]\[Times] ExpIntegralE[1, (", 
  GSS, "\[Times](x + ", GSS*yQ, "))/(x\[Times]", yp, ")]"]]

Try that.
Basically its evaluating E1 and the Exponential separately, and one is hitting $MaxNumber and the other $MinNumber.

To fix this I just took the definition of the E1 function (its in its help file under "more information") and then let it combine the two exponentials before integration.

Now of course you have a 2-dimensional numerical integration, which takes a bit longer, but it seems to get the results. It complains about precision, but the results seem ok. You can increase working precision to try to get that error to go away, but it makes it slower and slower.

Does that help?
 
  • #33
Thanks. But I get results in term of x. How to get numerical values? (I'm no expert in Mathematica)
 
  • #34
Code:
yp = 10^(5/10);
GSS = 100;
Cons = 10^-7;
results = {};
For[yQdB = -10, yQdB <= 15, yQdB++;
 yQ = 10^(yQdB/10);
 INTEGRAND = 
  Simplify[1/x^2*Exp[(GSS*(x + GSS*yQ))/(x*yp) - x]*
    Exp[-(GSS*(x + GSS*yQ))/(x*yp) T]/T];
 A1 = 0.5*((GSS^2)*yQ)/yp*
   NIntegrate[INTEGRAND, {T, 1, \[Infinity]}, {x, Cons, Infinity}, 
    PrecisionGoal -> 5, MaxRecursion -> 12, WorkingPrecision -> 20];
 results = Join[results, {yQdB, A1}];
 Print[{yQdB, A1}];]

Sorry, I left in your old code showing the equation.

This should print you real results, and at the end of the run you can just look at "results".

Though I'm not certain if this is giving the correct result to be honest, as once yQdB passes 5 it changes to something low. Maybe that's how it should be? I don't know.
 
  • Like
Likes   Reactions: EngWiPy
  • #35
It's difficult to know if it's correct or not, as A1 is just one value from the final result. The final result is in the form of A1+A2-A3, where all values have similar integrad form approximately. I increased the working precision to 40 but I still get the "error" message! When I combined all the results, I got some negative values. This shouldn't happen, as the final value must be between 0 and 0.5.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 13 ·
Replies
13
Views
14K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K