The integrand I want to integrate from u=183/985 to u=5 is:
integrand[u]=(1/u)*Sqrt[u^2-33489/970225]*BesselJ[1, 125*Sqrt[u^2-33489/970225]]*FAu[u^2])
where FAu is an interpolated function of a table of data (more info below). Here is a plot of the integrand from 183/985 to 5: If I integrate this function directly using NIntegrate
NIntegrate[integrand[u],{u,183/985, 5}, WorkingPrecision->10, AccuracyGoal->10]//AbsoluteTiming
I get:
NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in u near {u} = {0.533503182102844852657037466919066363800523835958162522877040}. NIntegrate obtained -1.98098626595186890458305013843987581889411200403876177007049*10^-9 and 4.40473710561241740892192176221042197437404611846026487150173`60.*^-8 for the integral and error estimates.
{5.87632, -1.980986266*10^-9}
as my answer.
But, if I split the integral in 5: [183/985,1], [1,2], ..., [4,5] and add up the results like this:
Total[NIntegrate[I[u], {u, ##}, WorkingPrecision->10, AccuracyGoal->10]&@@@Partition[Flatten[{183/985,Range[1,5]}],2,1]]//AbsoluteTiming
- it takes 100x more time to evaluate the integral (565.563s),
- it gives no error,
- it gives a different answer (-1.538*10^-11).
Context
To obtain the function FAu[u] I create a table from the integral
TAu[q_]:=(1/104.25919385918256`20)NIntegrate[If[q == 0 || r == 0, r^2/(1 + E^((r - 6.642`20.)/0.549`20.)), (Sin[q*r]/(q*r))*(r^2/(1 + E^((r - 6.642`20.)/0.549`20.)))], {r, 0, 100}, MinRecursion -> 3, MaxRecursion -> 100, WorkingPrecision -> 15,PrecisionGoal -> 7, AccuracyGoal -> Infinity]
and then interpolate it
FAu=Interpolation[TAu];
Questions
As I have been using Mathematica for numerical calculations for not very long I have a few questions:
- How can I be sure of the result NIntegrate returns? Since FAu[u] is evaluated using NIntegrate, it itself may contain errors. I've tried several NIntegrate methods and all of them return different results (except GaussKronrodRule, which I think NIntegrate automatically uses it for this case).
- Why splitting the integral takes much longer to evaluate and why it returns a different answer?
- I'm still confused with PrecisionGoal and AccuracyGoal options. If I want a result with at least 3 - 4 decimal digits after the period, this means I should be using AccuracyGoal->4 instead of PrecisionGoal?
Thanks
q
,TAu
.) Please, fix those. Also, you are usingWorkingPrecision
in a wrong way -- you probably wantPrecisionGoal
. $\endgroup$Method -> "InterpolationPointsSubdivision"
in the doc center. $\endgroup$