Evaluate the integral $ \int_0^{+\infty} \frac{\sin(x^2)}{x^4+1} dx $ using the residue method I have a problem in evaluating the integral above.
So far I've proceeded in this way.
We have an even function, so:
$$ \int_0^{+\infty} \frac{\sin(x^2)}{x^4+1} dx = \frac{1}{2} \int_{-\infty}^{+\infty} \frac{\sin(x^2)}{x^4+1} dx $$
Then we choose the complex function:
$$ f(z) = \frac{e^{iz^2}}{z^4+1} \qquad \forall z \in \mathbb{C} /\{ e^{i\frac{\pi + 2k\pi}{4}} \} \qquad k= 0,1,2,3 $$
Then we choose the integration path $\gamma$ consisting of the real axis from $-R$ to $+R$ and the upper semicircle $\Gamma$ of radius $R$.
So we will have:
$$ 2 \pi i \left(\text{Res}(f, e^{i\pi \over 4}) +\text{Res}(f, e^{i3\pi \over 4}) \right) = \oint_{+\gamma} f(z)dz =\\= \int_{-R}^{+R} f(z)dz + \int_{+\Gamma}f(z)dz $$
Taking the limit $R \to +\infty$ we can prove that the integral over $\Gamma$ is $0$. After some calculation and taking the imaginary part of the integral I obtain:
$$\int_0^{+\infty} \frac{\sin(x^2)}{x^4+1} dx = \frac{\pi}{4\sqrt{2}}\left( e - \frac{1}{e} \right) \simeq 1.31 $$
But, if I compute this integral on a computer, it gives me $0.37$. What is wrong with my reasoning ?
 A: If
$$I(x)=\int_0^{\infty}\frac{\sin(xt^2)}{t^4+1}dt$$
Then
$$I^{\prime\prime}-I=-\int_0^{\infty}\sin(xt^2)dt==\frac1{\sqrt x}\int_0^{\infty}\sin(t^2)dt=-\frac{\sqrt\pi}{2\sqrt2}x^{-1/2}$$
By the properties of Fresnel integrals.
Then we can use variation of parameters
$$I(x)=u(x)e^x+v(x)e^{-x}$$
$$I^{\prime}(x)=u^{\prime}e^x+v^{\prime}e^{-x}+ue^x-ve^{-x}=ue^x-ve^{-x}$$
Where we have use one degree of freedom to set
$$u^{\prime}e^x+v^{\prime}e^{-x}=0$$
Then
$$I^{\prime\prime}(x)-I(x)=u^{\prime}e^x-v^{\prime}e^{-x}=2u^{\prime}e^x=-2v^{\prime}e^{-x}=-\frac{\sqrt{\pi}}{2\sqrt2}x^{-1/2}$$
Solutions:
$$u=-\frac{\sqrt{\pi}}{4\sqrt2}\int x^{-1/2}e^{-x}dx=\frac{\sqrt{\pi}}{4\sqrt2}\left[c_1-\int_0^xt^{-1/2}e^{-t}dt\right]$$
$$v=\frac{\sqrt{\pi}}{4\sqrt2}\int x^{-1/2}e^xdx=\frac{\sqrt{\pi}}{4\sqrt2}\left[c_2+\int_0^xt^{-1/2}e^tdt\right]$$
So that makes
$$I(x)=\frac{\sqrt{\pi}}{4\sqrt2}\left[c_1e^x+c_2e^{-x}+\int_0^xt^{-1/2}\left(e^{t-x}-e^{x-t}\right)dt\right]$$
Now,
$$I(0)=0=\frac{\sqrt{\pi}}{4\sqrt2}(c_1+c_2)$$
And hopefully we can see that
$$\lim_{x\rightarrow\infty}I(x)=\lim_{x\rightarrow\infty}c_2e^{-x}=\lim_{x\rightarrow\infty}\int_0^xt^{-1/2}e^{t-x}dt=0$$
So that requires
$$c_1=-c_2=\int_0^{\infty}t^{-1/2}e^{-t}dt=\Gamma\left(\frac12\right)=\sqrt{\pi}$$
So now we want
$$I(1)=\frac{\sqrt{\pi}}{4\sqrt2}\left[2\sqrt{\pi}\sinh(1)-2\int_0^1t^{-\frac12}\sinh(1-t)dt\right]$$
Wolfram|Alpha expresses that last integral as
$$\int_0^1t^{-\frac12}\sinh(1-t)dt=\frac{\sqrt{\pi}\left(e^2\text{erf}(1)-\text{erfi}(1)\right)}{2e}\approx1.491998962365937$$
And it does in fact add up to about $0.370348638$, so even with the somewhat shaky exposition above, it may be correct.
A: Introduce a parameter $a$ and differentiate under the integral sign:
\begin{align}
f(a)&=\int_0^\infty\frac{\mathrm e^{-\mathrm iax^2}}{1+x^4}\mathrm dx\;,
\\
f''(a)&=-\int_0^\infty\frac{x^4\mathrm e^{-\mathrm iax^2}}{1+x^4}\mathrm dx\;,
\\
f(a)-f''(a)&=\int_0^\infty\mathrm e^{-\mathrm iax^2}\mathrm dx\\
&=
\sqrt{\frac\pi{4\mathrm ia}}
\;,
\end{align}
valid for $\Im a\lt0$. This differential equation can be solved using variation of constants. A solution of the homogoeneous equation is $f(a)=c\mathrm e^a$, so we use the ansatz $f(a)=c(a)\mathrm e^a$ to obtain
$$
-2c'(a)-c''(a)=\sqrt{\frac\pi{4\mathrm ia}}\mathrm e^{-a}\;.
$$
With $g(a)=c'(a)$, a solution of the homogeneous equation is $g(a)=d\mathrm e^{-2a}$, so we use the ansatz $g(a)=d(a)\mathrm e^{-2a}$ to obtain
$$
-d'(a)=\sqrt{\frac\pi{4a}}\mathrm e^a\;.
$$
Thus a particular solution is given by
\begin{align}
d(a)&=-\int_0^a\sqrt{\frac\pi{4\mathrm ix}}\mathrm e^{x}\mathrm dx
\\
&=-\int_0^\sqrt{a}\sqrt{\frac\pi{\mathrm i}}\mathrm e^{u^2}\mathrm du\\
&=-\frac\pi{2\sqrt{\mathrm i}}\operatorname{erfi}\left(\sqrt a\right)\;.
\end{align}
Thus
\begin{align}
c'(a)&=g(a)\\
&=d(a)\mathrm e^{-2a}\\
&=-\frac\pi{2\sqrt{\mathrm i}}\operatorname{erfi}\left(\sqrt a\right)\mathrm e^{-2a}\;,
\end{align}
and a particular solution can be obtained by integration by parts:
\begin{align}
c(a)&=-\frac\pi{2\sqrt{\mathrm i}}\int_0^a\operatorname{erfi}\left(\sqrt x\right)\mathrm e^{-2x}\mathrm dx
\\
&=-\frac\pi{2\sqrt{\mathrm i}}\left(\left[-\frac12\operatorname{erfi}\left(\sqrt x\right)\mathrm e^{-2x}\right]_0^a+\int_0^a\frac1{2\sqrt{\pi x}}\mathrm e^{-x}\mathrm dx\right)
\\
&=\frac\pi{4\sqrt{\mathrm i}}\left(\operatorname{erfi}(\sqrt a)\mathrm e^{-2a}-\operatorname{erf}\left(\sqrt a\right)\right)\;.
\end{align}
Thus the general solution for $f$ is
$$
f(a)=\frac\pi{4\sqrt{\mathrm i}}\left(\operatorname{erfi}\left(\sqrt a\right)\mathrm e^{-2a}-\operatorname{erf}\left(\sqrt a\right)\right)\mathrm e^a+c_+\mathrm e^a+c_-\mathrm e^{-a}\;.
$$
The initial conditions are
$$f(0)=\int_0^\infty\frac1{1+x^4}\mathrm dx=\frac\pi{2\sqrt2}$$
and
$$f'(0)=\int_0^\infty\frac{-\mathrm ix^2}{1+x^4}\mathrm dx=-\mathrm i\frac\pi{2\sqrt2}\;,$$
and since the particular solution and its derivative are $0$ at $a=0$, we have 
$$c_++c_-=\frac\pi{2\sqrt2}$$
and
$$
c_+-c_-=-\mathrm i\frac\pi{2\sqrt2}\;,
$$
so
$$c_\pm=\frac\pi{4\sqrt2}(1\mp\mathrm i)$$
and
$$
f(a)=\frac\pi{4\sqrt{\mathrm i}}\left(\operatorname{erfi}\left(\sqrt a\right)\mathrm e^{-a}-\operatorname{erf}\left(\sqrt a\right)\mathrm e^a\right)+\frac\pi{2\sqrt2}(\cosh a-\mathrm i\sinh a)\;.
$$
Now we can take the limit $a\to1$ (for which $f(a)$ was originally not defined) to obtain
\begin{align}
\int_0^\infty\frac{\sin\left(x^2\right)}{1+x^4}\mathrm dx
&=-\Im\lim_{a\to\mathrm 1}\,f(a)
\\
&=
\frac{\pi}{4\sqrt2}\left(2\sinh1+\operatorname{erfi}(1)\mathrm e^{-1}-\operatorname{erf}(1)\mathrm e\right)
\\
&\approx0.370349\;.
\end{align}
A: As has been pointed out in comments, your approach doesn't work because the integral over the semicircle doesn't converge.
Here's another approach that also doesn't quite work. Instead of adding the negative real axis, we can add the positive imaginary axis. Let
$$
I=\int_0^\infty\frac{\mathrm e^{\mathrm ix^2}}{x^4+1}\mathrm dx\;,
$$
so that the desired integral is the imaginary part of $I$. Then
$$
\int_{\mathrm i\infty}^0\frac{\mathrm e^{\mathrm iz^2}}{z^4+1}\mathrm dz=-\mathrm i\overline I\;.
$$
Now we can complete the contour with a quarter circle in the first quadrant, where the integrand decays sufficiently rapidly. This contour encloses the pole at $z=\mathrm e^{\frac\pi4\mathrm i}$, with residue
\begin{align}
\frac{\mathrm e^{-1}}{\prod_{k=1}^3\left(\mathrm e^{\frac\pi4\mathrm i}-\mathrm e^{(2k+1)\frac\pi4\mathrm i}\right)}
&=
\frac{\mathrm e^{-1}}{(\sqrt2)(\sqrt2\mathrm i)(\sqrt2+\sqrt2\mathrm i)}
\\
&=
-\frac{1+\mathrm i}{4\sqrt2\mathrm e}\;.
\end{align}
Thus
\begin{align}
I-\mathrm i\overline I
&=
-2\pi\mathrm i\frac{1+\mathrm i}{4\sqrt2\mathrm e}
\\
&=
\frac{\pi}{2\sqrt2\mathrm e}(1-\mathrm i)\;.
\end{align}
But unfortunately this merely tells us that
$$
\Re I-\Im I=\frac{\pi}{2\sqrt2\mathrm e}
$$
and doesn't yield the imaginary part separately.
