1
$\begingroup$

I'm trying to do a numerical integration. The integration is within a function.

fxn2[k_] := 
 NIntegrate[
   r*BesselJ[0, k*r]*( 
     BesselJ[0, 1] - 
      1 + (BesselJ[1, 1]/
         BesselY[1, 1])*(2/Pi*Log[0.5*Exp[EulerGamma]*Sqrt[0.01/r]] - 
         BesselY[0, 1])), {r, 0, 0.01}] + 
  NIntegrate[
   r*BesselJ[0, k*r]*( 
     BesselJ[0, Sqrt[0.01/r]] - 1 + 
      BesselJ[1, 1]/
        BesselY[1, 1]*(2/Pi*Log[0.5*Exp[EulerGamma]*Sqrt[0.01/r]] - 
         BesselY[0, Sqrt[0.01/r]])), {r, 0.01, Infinity}]

But, whenever I start to plot fxn2, I get

First::normal: Nonatomic expression expected at position 1 in First[0]. >>
First::normal: Nonatomic expression expected at position 1 in First[1]. >>

May I know what's wrong in my code?

$\endgroup$
3
  • $\begingroup$ Might not be the only problem based on the error message, but here you need to use k_?NumericQ in place of k_ to be able to use fxn2 in other functions such as Plot. Make sure you Clear[fxn2] before you re-define it. support.wolfram.com/kb/12502 $\endgroup$
    – Szabolcs
    Nov 18 '14 at 23:51
  • $\begingroup$ Thanks Szabolcs. I tried your suggestion, but the output message is still the same. $\endgroup$
    – Michelle
    Nov 19 '14 at 1:28
  • $\begingroup$ The message itself seems to be generated in th symbolic preprocessing part, you can avoid it iserting Method -> {Automatic, "SymbolicProcessing" -> 0} in the second integral. However the integral itself is diverging as was noted by @Marius Ladegård Meyer $\endgroup$
    – Acus
    Nov 19 '14 at 12:46
2
$\begingroup$

The error occurs because of the integral extending to Infinity. If I simply do

NIntegrate[r*BesselJ[0, 10*r]*
(BesselJ[0, Sqrt[0.01/r]] - 1 + BesselJ[1, 1]/
BesselY[1, 1]*(2/Pi*Log[0.5*Exp[EulerGamma]*Sqrt[0.01/r]] - 
BesselY[0, Sqrt[0.01/r]])), {r, 0.01, 10000}]

I get the error

NIntegrate::ncvb: "NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in r near {r} = {19.5412}. NIntegrate obtained -0.00084999 and 0.001570429957126261` for the integral and error estimates."

For some reason, this error message becomes what OP posted when the upper limit is raised to Infinity.

A workaround is to choose a large upper limit that is not Infinity (you are using NIntegrate anyway) and possibly increasing the number of allowed recursive refinements using the option MaxRecursion -> number. Using MaxRecursion -> 20 and an upper limit of 10 000 on the integral gives me ListPlot

forListPlot[Table[{k, fxn2[k]}, {k, 0.1, 10, 0.5}]]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.