I am calculating the following integral $$I=\int_0^1 e^{-c_1x^2+c_2x}\mathrm{erf}(c_3x+c_4)dx,$$ with Integrate and NIntegrate respectively.

There is no analytical solution for this integral and I got two different numerical results, with quite large difference: $-0.117035 + 0.5i$.

My question is, which one is more accurate in this case.

Here is my code:

c1 = Pi;
c2 = SetPrecision[10.1 + 10.1 I, 30];
c3 = Sqrt[Pi];
c4 = SetPrecision[1.1 + 6.1 I, 30];
I1 = NIntegrate[Exp[-c1 x^2 + c2 x] Erf[c3 x + c4], {x, 0, 1}, 
   PrecisionGoal -> 20, WorkingPrecision -> 30];
I2 = Integrate[Exp[-c1 x^2 + c2 x] Erf[c3 x + c4], {x, 0, 1}];
error = N[I1 - I2]
(*error=-0.117035 + 0.5i*)

Thanks in advance!!


Better define the parameters with infinite precision. Then you can use ultrahigh WorkingPrecision.

c1 = Pi;
c2 = (101 + 101 I)/10;
c3 = Sqrt[Pi];
c4 = (11 + 61 I)/10;

I3 = NIntegrate[Exp[-c1 x^2 + c2 x] Erf[c3 x + c4], {x, 0, 1}, 
         WorkingPrecision -> 100]

(*   5.98422153733426875937314115532253471792710605523929063484400170963328\
        0746439954199937370126209185221*10^10 - 
        02374014674651258602665889195814*10^13 I   *)
|improve this answer|||||
  • $\begingroup$ @Akkr14: thanks for the answer^_^! After Rationalize the parameters, I recalculated $I_1$, $I_2$ and $I_3$. It turned out that $I_1$ and $I_3$ via NIntegrate are almost the same, but $I_2$ is still much different than them. Does that mean the result obtained by Integrate is not trustable in this case? $\endgroup$ – Ligang Sun Feb 28 at 9:52
  • 1
    $\begingroup$ Remove the semicolon after Integrate... to see, that it gives back the input. It does not find an analytical solution, most likely the is no one. But when you apply N[I2] the integral is automaticlly calculated numericaly with NIntegrate, but with standard machine precision, which is 16. This is of course less accurate than with WorkingPrecission->30 . $\endgroup$ – Akku14 Feb 28 at 14:33
  • $\begingroup$ @Akkr14: thanks a lot! it is very clear now. $\endgroup$ – Ligang Sun Feb 29 at 17:11

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.