I have big difficulties solving the following integral: $$ \int_{-\infty}^{\infty}x\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}^{2}\left(a\left(x-d\right)\right)\,\mathrm{d}x $$

I tried to use integration by parts, and also tried to apply the technique called “differentiation under the integration sign” but with no results.

I’m not very good at calculus so my question is if anyone could give me any hint of how to approach this integral. I would be ultimately thankful.

If it could help at all, I know that $$ \int_{-\infty}^{\infty}x\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}\left(a\left(x-d\right)\right)\,\mathrm{d}x=\frac{a}{b^{2}\sqrt{a^{2}+b^{2}}}\exp\left(-\frac{a^{2}b^{2}\left(c-d\right)^{2}}{a^{2}+b^{2}}\right)+\frac{\sqrt{\pi}c}{b}\mathrm{erf}\left(\frac{ab\left(c-d\right)}{\sqrt{a^{2}+b^{2}}}\right), $$

for $b>0$.

  • $\begingroup$ Do you mean erf((a(x-d))^2), or [erf(a(x-d))]^2 (in the top expression)? $\endgroup$ – Adam Rubinson Apr 27 '12 at 12:06
  • $\begingroup$ @AdamRubinson I meant $[erf(a(x-d))]^2$. I edited the original post to avoid confusion. $\endgroup$ – petru Apr 27 '12 at 13:25
  • $\begingroup$ In that case, I am guessing that they gave you the integral at the bottom of your post as a hint. Note that, assuming your hint at the bottom is correct, that integral is just a constant (even though it looks incredibly messy). You can use IBP where one of your functions is the integrand of the integral at the bottom of your post, and the other function is erf(a(x-d)). The "hint" at the bottom of your post tells you how to integrate the longer one, and all you need to do now is to differentiate erf(a(x-d)) (which you can do) $\endgroup$ – Adam Rubinson Apr 27 '12 at 16:39
  • $\begingroup$ @AdamRubinson Well, after the initial excitement I realized that it’s not that simple. I cannot use the bottom integral because what I need is the antiderivative of $x\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}\left(a\left(x-d\right)\right)$, and not the value of the integral. $\endgroup$ – petru Apr 27 '12 at 17:33
  • $\begingroup$ yes you are correct. My method fails. This is not an easy problem, and I don't know the answer. $\endgroup$ – Adam Rubinson Apr 27 '12 at 18:09

A suggestion instead of a complete answer: taking $c=0$ for ease of typing and integrating by parts $$\begin{align*} \int_{-\infty}^\infty xe^{-b^2x^2}\text{erf}^2(a(x-d))\ \mathrm dx &= -\text{erf}^2(a(x-d))\left.\frac{e^{-b^2x^2}}{2b^2}\right|_{-\infty}^\infty\\ &\qquad\qquad +\int_{-\infty}^\infty2\text{erf}(a(x-d))\frac{2}{\sqrt{\pi}} e^{-a^2(x-d)^2}\frac{e^{-b^2x^2}}{2b^2}\ \mathrm dx\\ &=\frac{2}{b^2\sqrt{\pi}}\int_{-\infty}^\infty\text{erf}(a(x-d)) e^{-a^2(x-d)^2-b^2x^2}\ \mathrm dx\\ &=\frac{2}{b^2\sqrt{\pi}}\int_{-\infty}^\infty\text{erf}(a(x-d)) e^{-(a^2+b^2)x^2 + 2a^2dx-a^2x^2}\ \mathrm dx \end{align*}$$ to which, after completing the square in the exponent, we can apply the OP's given integral formula $$\int_{-\infty}^{\infty}\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}\left(a\left(x-d\right)\right)\,\mathrm{d}x= {\frac{\sqrt\pi}{b}}\mathrm{erf}\left(\frac{ab\left(c-d\right)}{\sqrt{a^{2}+b^{2}}}\right)\,.$$

  • $\begingroup$ Thanks Dilip. I did calculations you suggested but unfortunately I can’t see how this result is supposed to help me. With $c\neq 0$ I still have integrand $\exp\left(-a^2 (-d + x)^2\right) \mathrm{erf}\left(b (x-c)\right) \mathrm{erf}\left(a (x-d)\right)$ and I don’t know how to proceed with it. $\endgroup$ – petru May 3 '12 at 22:05

What I managed to achieve now is a better approximation of that complicated integral, but even though I tried from various angles, I can’t find the closed form.

So basically I’m stuck with integral $$ \int_{-\infty}^{\infty}\exp\left(-a^{2}\left(x-d\right)^{2}\right)\mathrm{erf}\left(b\left(x-c\right)\right)\mathrm{erf}\left(a\left(x-d\right)\right)\,\mathrm{d}x, \tag{1} $$

which after integrating by parts leaves me with $$ \int_{-\infty}^{\infty}\exp\left(-a^{2}(x-d)^{2}\right)\mathrm{erf^{2}}\left(b\left(x-c\right)\right)\,\mathrm{d}x\,. \tag{2} $$

I’m writing this post in hope that somebody knows a trick or technique to deal with integral $(1)$ or $(2)$. Or maybe none of these integrals are “doable”?

Any suggestions will be deeply appreciated.


In the original post I mentioned one helpful integral. Another integral that is useful here is

$$ \int_{-\infty}^{\infty}\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}\left(a\left(x-d\right)\right)\,\mathrm{d}x= {\frac{\sqrt\pi}{b}}\mathrm{erf}\left(\frac{ab\left(c-d\right)}{\sqrt{a^{2}+b^{2}}}\right)\,. $$


Let us denote: \begin{equation} {\mathfrak I}^{(2)}:=\int\limits_{\mathbb R} x \exp\left( -b^2(x-c)^2\right) \cdot [\text{erf}\left( a(x-d)\right)]^2 dx \end{equation}

Then we have: \begin{eqnarray} {\mathfrak I}^{(2)}&=& \int\limits_{\mathbb R} \phi(x) \text{erf}\left(\frac{a b^2 (c-d)}{a^2+b^2}+\frac{a x}{\sqrt{2 a^2+2 b^2}}\right) dx + \frac{c \sqrt{\pi}}{b}\int\limits_{\mathbb R} \phi(x) [\text{erf}\left(\frac{a x}{\sqrt{2} b}+a (c-d)\right)]^2 dx =\\ && \text{sign}(b) \left(\right.\\ % &&\frac{2 a \sqrt{\frac{b^2}{a^2+b^2}} e^{-\frac{a^2 b^2 (c-d)^2}{a^2+b^2}} \text{erf}\left(\frac{a b^2 (c-d)}{\sqrt{a^2+b^2} \sqrt{2 a^2+b^2}}\right)}{b^3}+\\ % &&-\frac{4 \sqrt{\pi } c T\left(\frac{\sqrt{2} a (c-d)}{\sqrt{\frac{a^2}{b^2}+1}},\frac{1}{\sqrt{\frac{2 a^2}{b^2}+1}}\right)}{b}-\frac{4 \sqrt{\pi } c T\left(\frac{a \sqrt{\frac{2 a^2}{b^2}+2} (c-d)}{\sqrt{\frac{\left(a^2+b^2\right)^2}{b^4}}},\frac{1}{\sqrt{\frac{2 a^2}{b^2}+1}}\right)}{b}+\frac{\sqrt{\pi } c \text{erf}\left(\frac{a (c-d)}{\sqrt{\frac{a^2}{b^2}+1}}\right)}{b}+\frac{4 c \arctan\left(\frac{1}{\sqrt{\frac{2 a^2}{b^2}+1}}\right)}{\sqrt{\pi } b}+\frac{2 c \arctan\left(\frac{a^2}{b^2 \sqrt{\frac{2 a^2}{b^2}+1}}\right)}{\sqrt{\pi } b}-\frac{\sqrt{\pi } c \text{erf}\left(\frac{a \sqrt{\frac{a^2}{b^2}+1} (c-d)}{\sqrt{\frac{\left(a^2+b^2\right)^2}{b^4}}}\right)}{b}\\ &&\left.\right) \end{eqnarray} In the first line we substituted for $x-c$ and then split the integral into two integrals one that involves $x$ and the other that does not. Subsequently we integrated by parts the one that involves $x$. Now in the second line we just used A definite integral involving a Gaussian and shifted error functions. .

Clear[phi]; phi[x_] := Exp[-1/2 x^2]/Sqrt[2 Pi]; eps = 10^(-9);
For[count = 1, count <= 500, count++,
  {a, b, c, d} = RandomReal[{-3, 3}, 4, WorkingPrecision -> 50];
  x1 = NIntegrate[
    x Exp[-b^2 (x - c)^2] Erf[a (x - d)]^2, {x, -Infinity, Infinity}];
  Sqrt[2 Pi]/(2 b^2) NIntegrate[(x) phi[
       x] Erf[a (c - d) + (a x)/(Sqrt[2] b)]^2, {x, -Infinity, 
      Infinity}] + 
   c Sqrt[2 Pi]/(Sqrt[2] b) NIntegrate[
     phi[x] Erf[a (c - d) + (a x)/(Sqrt[2] b)]^2, {x, -Infinity, 
  (2 a Sqrt[b^2/(a^2 + b^2)] E^(-((a^2 b^2 (c - d)^2)/(a^2 + b^2))))/
    b^3 NIntegrate[
     phi[x] (  
       Erf[ ((a (b^2) )/(a^2 + b^2)) (c - d) + 
         a/Sqrt[2 a^2 + 2 b^2] x]), {x, -Infinity, Infinity}] + (
    c Sqrt[\[Pi]])/
    b NIntegrate[
     phi[x] Erf[a (c - d) + (a x)/(Sqrt[2] b)]^2, {x, -Infinity, 
  (2 a Sqrt[b^2/(a^2 + b^2)] E^(-((a^2 b^2 (c - d)^2)/(a^2 + b^2))))/
    b^3 2 (T[eps, a/Sqrt[ 
       a^2 + b^2], ((Sqrt[2] a (b^2) )/(a^2 + b^2)) (c - d)] + 
      T[eps, -(a/Sqrt[ 
        a^2 + b^2]), ((Sqrt[2] a (b^2) )/(a^2 + b^2)) (c - d)]) + (
    c Sqrt[\[Pi]])/
    b NIntegrate[
     phi[x] Erf[a (c - d) + (a x)/(Sqrt[2] b)]^2, {x, -Infinity, 
  x2 = Sign[
     b] ((2 a Sqrt[b^2/(a^2 + b^2)]
         E^(-((a^2 b^2 (c - d)^2)/(a^2 + b^2))))/
       b^3 Erf[(a b^2 (c - d))/(
        Sqrt[(a^2 + b^2)] Sqrt[2 a^2 + b^2])] + (c Sqrt[\[Pi]])/
       b NIntegrate[
        phi[x] (Erf[a (c - d) + (a x)/(Sqrt[2] b)]^2), {x, -Infinity, 
  x2 = Sign[
     b] ((2 a Sqrt[b^2/(a^2 + b^2)])/
       b^3  E^(-((a^2 b^2 (c - d)^2)/(a^2 + b^2)))
        Erf[(a b^2 (c - d))/(Sqrt[(a^2 + b^2)] Sqrt[2 a^2 + b^2])] + 
      c /(b Sqrt[\[Pi]]) (4 ArcTan[1/Sqrt[1 + (2 a^2)/b^2]] + 
         2 ArcTan[a^2/(Sqrt[1 + (2 a^2)/b^2] b^2)] + \[Pi] Erf[(
           a (c - d))/Sqrt[1 + a^2/b^2]] - \[Pi] Erf[(
           a Sqrt[1 + a^2/b^2] (c - d))/Sqrt[(a^2 + b^2)^2/b^4]] - 
         4 \[Pi] OwenT[(Sqrt[2] a (c - d))/Sqrt[1 + a^2/b^2], 1/Sqrt[
           1 + (2 a^2)/b^2]] - 
         4 \[Pi] OwenT[(a Sqrt[2 + (2 a^2)/b^2] (c - d))/
           Sqrt[(a^2 + b^2)^2/b^4], 1/Sqrt[1 + (2 a^2)/b^2]]));
  If[Abs[x2/x1 - 1] > 10^(-3), 
   Print["results do not match..", {a, b, {x1, x2}}]; Break[]];
  If[Mod[count, 50] == 0, PrintTemporary[count]];
  • $\begingroup$ (+1) --- from Me. $\endgroup$ – Mariusz Iwaniuk Apr 11 at 18:16

thanks for all your comments and suggestions. I still haven’t found the closed form of the integral, or maby it cannot be done…

What I have for this moment is a (very?) good approximation. I haven’t tested it carefully but it seems to be good enough for my purposes.

$$ \int_{-\infty}^{\infty}x\exp\left(-b^{2}\left(x-c\right)^{2}\right)\mathrm{erf}^{2}\left(a\left(x-d\right)\right)\,\mathrm{d}x\approx $$

$$ \frac{c\sqrt{\pi}}{b}+\frac{2a}{b^{2}\sqrt{a^{2}+b^{2}}}\exp\left(-\frac{a^{2}b^{2}(c-d)^{2}}{a^{2}+b^{2}}\right)\mathrm{erf}\left(\frac{ab^{2}(c-d)}{\sqrt{a^{2}+b^{2}}\sqrt{2a^{2}+b^{2}}}\right)-\frac{c}{\sqrt{\frac{b^{2}}{\pi}+\frac{a^{2}\pi}{8}}}\exp\left(-\frac{a^{2}b^{2}(c-d)^{2}\pi^{2}}{8b^{2}+a^{2}\pi^{2}}\right) $$

for $b>0$.


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.