Solving Mathematica Error: NIntegrate::ncvb

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
34 replies · 5K views
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
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?
 
Thanks. But I get results in term of x. How to get numerical values? (I'm no expert in Mathematica)
 
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
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.