# Integral funkiness

**URL:** <https://community.wolfram.com/t/integral-funkiness/273>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [July 26, 2013, 5:22pm UTC](https://community.wolfram.com/t/integral-funkiness/273 "2013-07-26T17:22:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvand125](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jvand125](https://community.wolfram.com/u/jvand125)\
**Post date:** [July 26, 2013, 5:22pm UTC](https://community.wolfram.com/t/integral-funkiness/273/1 "2013-07-26T17:22:40Z")

</div>

I have a rather curious problem. I’m trying to solve this integral:

```auto
step1 = Integrate[
  Cos[q + ((k2 - k2 Cos[\[Theta]]) \[Rho] Cos[\[Phi]] - 
       k2 Sin[\[Theta]] \[Rho] Sin[\[Phi]])] \[Rho], {\[Phi], 0, 
   2 \[Pi]}, 
  Assumptions -> {k2 > 0 && \[Theta] \[Element] Reals && \[Rho] > 0}]

```

The answer it gives me for that is

```auto
2 \[Pi] \[Rho] Cos[q]

```

This seems to be independent of Theta. However, if I plug in a value for Theta before doing the integral. For example Theta = Pi / 2 gives:

```auto
2 \[Pi] \[Rho] BesselJ[0, Sqrt[2] k2 \[Rho]] Cos[q]

```

And Theta = Pi gives

```auto
2 \[Pi] \[Rho] BesselJ[0, 2 k2 \[Rho]] Cos[q]

```

Obviously, the result does depend on Theta then, even though the initial answer has no theta dependence. Is this a bug I stumbled upon in Mathematica 8.0.1.0 for Linux or am I missing something fundamental here?

---

<div class="post-metadata">

**Author:** ![kisensee](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kisensee/32/16793_2.png) [@kisensee](https://community.wolfram.com/u/kisensee)\
**Post date:** [July 26, 2013, 6:20pm UTC](https://community.wolfram.com/t/integral-funkiness/273/2 "2013-07-26T18:20:27Z")

</div>

This may be an issue with your version of Mathematica - I was able to reproduce your first result in Mathematica 8.0.1, but was not able to reproduce the result in 8.0.4 or 9.0.1. Those later versions returned the input unevaluated after a lengthy calculation.

---

<div class="post-metadata">

**Author:** ![jvand125](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jvand125](https://community.wolfram.com/u/jvand125)\
**Post date:** [July 29, 2013, 3:35pm UTC](https://community.wolfram.com/t/integral-funkiness/273/3 "2013-07-29T15:35:42Z")

</div>

Ah, thanks. Good to see that I’m not going crazy. 🙂

---

<div class="post-metadata">

**Author:** ![sukrause](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sukrause/32/41348_2.png) [@sukrause](https://community.wolfram.com/u/sukrause)\
**Post date:** [July 31, 2013, 7:40pm UTC](https://community.wolfram.com/t/integral-funkiness/273/4 "2013-07-31T19:40:56Z")

</div>

Hi there,

this you can possibly solve: First of all, one sets

```auto
q = 0, k2 Cos[?]= x, k2 Sin[?] = y

```

because the q is a strong obstacle and the ?-terms are unimportant for the integral. The simplified integral

```auto
(* q = 0, k2 Cos[\[Theta]] \[Rule] x, k2 Sin[\[Theta]]\[Rule] y *)
Integrate[
 Cos[((k2 - x) \[Rho] Cos[\[Phi]] - y \[Rho] Sin[\[Phi]])] \[Rho], {\[Phi], 0, 2 \[Pi]}, 
 Assumptions -> {k2 > 0 && \[Theta] \[Element] Reals && \[Rho] > 0}]

ConditionalExpression[
 2 \[Pi] \[Rho] BesselJ[0, Sqrt[(k2 - x)^2 + y^2] \[Rho]], 
 Sqrt[(k2 - x)^2 + y^2] \[Element] Reals]

```

The conditional means

```auto
In[8]:= Reduce[(k2 - k2 Cos[\[Theta]])^2 + (k2 Sin[\[Theta]])^2 >= 0, \[Theta], Reals]

Out[8]= (C[1] \[Element] 
    Integers && \[Theta] == \[Pi] + 
     2 \[Pi] C[1]) || (-\[Pi] + \[Theta])/(2 \[Pi]) \[NotElement] Integers

```

and one finds

```auto
In[7]:= S
Integrate[Sin[((k2 - x) \[Rho] Cos[\[Phi]] - y \[Rho] Sin[\[Phi]])] \[Rho], {\[Phi], 0, 2 \[Pi]}, 
 Assumptions -> {k2 > 0 && \[Theta] \[Element] Reals && \[Rho] > 0}]

Out[7]= 0

```

Why this is interesting? If you develop the orginal integral into a seris in q and integrate

```auto
Integrate[Series[
  Cos[q + ((k2 - k2 Cos[\[Theta]]) \[Rho] Cos[\[Phi]] - 
       k2 Sin[\[Theta]] \[Rho] Sin[\[Phi]])] \[Rho], {q, 0, 
   12}], {\[Phi], 0, 2 \[Pi]}]

```

you are left with only the both integrals shown above, one is zero, so the result is

```auto
(Cosh[q]- 1) ConditionalExpression[
 2 \[Pi] \[Rho] BesselJ[0, Sqrt[(k2 - x)^2 + y^2] \[Rho]], 
 Sqrt[(k2 - x)^2 + y^2] \[Element] Reals]

```

x and y do depend on \ because of

```auto
In[13]:= Sum[q^(2 o)/(2 o)!, {o, 1, Infinity}]

Out[13]= -1 + Cosh[q]

```

Best regards  
Udo.

---

<div class="post-metadata">

**Author:** ![jvand125](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jvand125](https://community.wolfram.com/u/jvand125)\
**Post date:** [July 31, 2013, 8:15pm UTC](https://community.wolfram.com/t/integral-funkiness/273/5 "2013-07-31T20:15:50Z")

</div>

Thanks! That’s a very neat approach. I think you made a minor mistake at the end though. I’ve gone through the steps you mentioned, but the series one gets is

```auto
In[13]:= Sum[(-1)^o q^(2 o)/(2 o)!, {o, 0, \[Infinity]}]

Out[13]= Cos[q]

```

There is an extra factor of (-1)^o there and the series starts from o=0 instead of o=1. With those modifications it works. So in the end one instead gets

```auto
Cos[q] ConditionalExpression[
 2 ? ? BesselJ[0, Sqrt[(k2 - x)^2 + y^2] ?], 
 Sqrt[(k2 - x)^2 + y^2] ? Reals]

```

, which is definitely the answer I was looking for.

I had obtained that answer through a different approach, which I feel is simply a workaround for the bug, but to wit:  
The original formula was

```auto
Cos[q + ((k2 - k2 Cos[?]) ? Cos[?] - k2 Sin[?] ? Sin[?])] ?

```

, which I had rewritten in the form

```auto
Cos[q + \[Gamma]1 Cos[\[Phi]] - \[Gamma]2 Sin[\[Phi]] \[Rho]
= Cos[q + \Sqrt[\[Gamma]1^2 + \[Gamma]2^2] Cos[\[Phi] + \[Beta]]]

```

, where the new angle ? is defined as

```auto
Cos[\[Beta]] = \[Gamma]1/Sqrt[\[Gamma]1^2 + \[Gamma]2^2]
Sin[\[Beta]] = \[Gamma]2/Sqrt[\[Gamma]1^2 + \[Gamma]2^2]

```

Doing so allowed Mathematica to solve the integral, giving the same answer as your method produced.

---

<div class="post-metadata">

**Author:** ![sukrause](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sukrause/32/41348_2.png) [@sukrause](https://community.wolfram.com/u/sukrause)\
**Post date:** [August 3, 2013, 3:16pm UTC](https://community.wolfram.com/t/integral-funkiness/273/6 "2013-08-03T15:16:37Z")

</div>

Okay, you figured it out; last night I found it strange to generate Cosh during integration of Cos. Just for the logs

```auto
In[40]:= Clear[fN, fA]
fN[q_, k2_, \[Theta]_, \[Rho]_] := 
 NIntegrate[
  Cos[q + ((k2 - k2 Cos[\[Theta]]) \[Rho] Cos[\[Phi]] - 
       k2 Sin[\[Theta]] \[Rho] Sin[\[Phi]])] \[Rho], {\[Phi], 0, 
   2 \[Pi]}]
fA[q_, k2_, \[Theta]_, \[Rho]_] := 
 2 \[Pi] \[Rho] Cos[q] BesselJ[0, 
    Sqrt[(k2 - 
        k2 Cos[\[Theta]])^2 + (k2 Sin[\[Theta]])^2] \[Rho]] /; \
(-\[Pi] + \[Theta])/(2 \[Pi]) \[NotElement] Integers

In[55]:= Clear[ted]
ted = Transpose[
   RotateLeft[
    Join[RandomReal[{-1, 5}, {3, 
       30}], {RandomReal[{-\[Pi] + 1/1000, \[Pi] - 1/1000}, 30]}]]];

In[67]:= Chop[(fA @@@ ted) - (fN @@@ ted)]

Out[67]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

```
