Numerical integral does not agree with analytic integral

I am trying to evaluate a function, that I've now reduced to its minimum (not) working example. Unless I am doing something very wrong, it appears that NIntegrate is not agreeing with the result from Integrate.

The integral I am trying to evaluate is the following:

$$\int_0^{2\pi} t e^{-a \cos(b + t) } \sin(b+t)\ dt$$

To do so, I am using the code:

Integrate[
t Exp[-a Cos[b + t]] Sin[t + b],
{t, 0, 2 \[Pi]}
]


The result found by Mathematica is the following

$$\fbox{-\frac{2 \pi (\sinh (a)-\cosh (a)+I_0(a))}{a}\text{ if }\Re(a)>0}$$

The condition is fulfilled for my purposes. However, this solution does not agree with the numerical evaluation of the integral. For instance, the line:

NIntegrate[
t Exp[-a Cos[b + t ]] Sin[  t + b] /. a -> 0.5 /. b -> 0.5,
{t, 0, 2 \[Pi]}
]


yields -5.26114, whereas

Integrate[
t Exp[-a Cos[b + t ]] Sin[  t + b],
{t, 0, 2 \[Pi]}
]/. a -> 0.5 /. b -> 0.5


yields -5.74224. These two values are considerably different. Another strange outcome is that replacing the values analytically inside the integral makes the integral uncomputable, even though the values chosen satisfy the required condition Re[a]>0:

Integrate[
t Exp[-a Cos[b + t ]] Sin[  t + b] /. a -> 0.5 /. b -> 0.5,
{t, 0, 2 \[Pi]}
]


the return of this line is simply the inputted form of the integral.

What is going on here? Am I doing anything incorrectly? Is there a problematic discrepancy between the symbolic and numerical solvers?

Thanks in advance for the help!

Any recommendations for better practices regarding writing up these commands is very welcome too :)

• Seems like a bug in Integrate. The output is totally independent of b which obviously should not. Commented Feb 13 at 22:19
• Another strange outcome is that replacing the values analytically inside the integral makes the integral uncomputable No. It works for me on V 14. Here is screen shot !Mathematica graphics You should avoid machine numbers with exact function like Integrate Commented Feb 13 at 22:50
• Please report this to WRI at [email protected] Commented Feb 13 at 22:58
• With some substitutions, for example setting $f(t)=t e^{-a \cos (b+t)}$ , you can get a analytic result $\frac{2 \pi}{a} \left(e^{-a \cos (b)}-I_0(a)\right)$.
– chuy
Commented Feb 14 at 19:10

Not a Mathematica answer per se, but just in case its useful, I'll expand on my comment under the question.

Let's write the original integral as

$$\int_0^{2 \pi } u(t) \, \mathrm{d}t$$ where $$u(t)=t \sin (b+t) e^{-a \cos (b+t)}$$

If I define $$f(t)=t e^{-a \cos (b+t)}$$,

then

$$u(t)=\frac{1}{a}\left(\frac{\mathrm{d}f}{\mathrm{d}t}-e^{a \cos (x)}\right)$$ if $$a\neq0$$. If $$a=0$$, then the integral is simply $$-2 \pi \cos (b)$$.

From here, the integral becomes:

\begin{aligned} \int_0^{2 \pi } u(t) \, \mathrm{d}t &= \frac{1}{a}\left(\int _0^{2 \pi }\frac{\mathrm{d}f}{\mathrm{d}t}\mathrm{d}t-\int _0^{2 \pi }e^{-a \cos (b+t)}\mathrm{d}t\right) \\ &= \frac{1}{a}\left(\int _0^{2 \pi }\mathrm{d}f-\int _0^{2 \pi }e^{-a \cos (b+t)}\mathrm{d}t\right) \\ &= \frac{1}{a}\left(2 \pi e^{-a \cos (b)}-2 \pi I_0(a)\right)\\ &= \frac{2 \pi}{a}\left(e^{-a \cos (b)}-I_0(a)\right) \end{aligned}

Note:

$$\underset{a\to 0}{\lim }\,\frac{2 \pi}{a}\left(e^{-a \cos (b)}-I_0(a)\right) = -2 \pi \cos (b)$$

There is a chance that my extreme lack of rigor here has led to a result that is much more limited in terms of what conditions must be placed on $$a$$ and $$b$$.

There is a workaround. Let us put

J[t_] := Integrate[Exp[-a*Cos[b + x]]*Sin[b + x], {x, 0, t},
Assumptions -> t >= 0 && t <= 2*Pi]


Then

J[0]


0

and

J[2*Pi]


0

The integral under consideration is nothing but $$j:=\int_0^{2\pi}tJ'(t)\,dt$$. Integrating by parts, we obtain

j = -Integrate[J[t], {t, 0, 2*Pi}]


-((2 \[Pi] (-E^(-a Cos[b]) + BesselI[0, a]))/a)

Let us verify it by

j /. {a -> 0.5, b -> 0.5}


-5.26114