# Integration of a function that oscillates rapidly (apparently)

I would like to know if you could help me solve some doubts about the integration of a function that oscillates rapidly (apparently) that depends on time and two angular variables. The parameters S and Chi are given from the beginning. The integral that I want to make is the following:

((2 S + 1)/(4 Pi)) NIntegrate[
Sin[θ] ((Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])^(
2 S - 1) (1 + Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])), {θ, 0, Pi}, {ϕ, 0 , 2 Pi},
MaxRecursion -> Infinity, WorkingPrecision -> MachinePrecision,
Method -> "SOME CHOSEN METHOD"]


As you can see the function that I want to integrate is:

(Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])^(
2 S - 1) (1 + Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])


1) The above function can really be considered IN ALL ASPECTS as a rapidly oscillating function ?. I have investigated that the first aspect that should satisfy a function to be considered as a function that oscillates a lot is that it should be seen as the product of a non-oscillating function by an oscillating kernel which can be often expressed in the form of an imaginary exponential .

2) I have already tried to integrate with the only special integration method (in more than one variable) for rapidly oscillating functions that I know (LevinRule) but I have problems. First it tells me that: NIntegrate failed to converge to prescribed accuracy after 1 recursive bisections in ϕ near {θ, ϕ} = {point, point}. Also the error I get compared to the result of the integral is very big. In the same way, it tells me that the MaxOrder-> 50 option was exceeded and that I should treat it as a non-Levin function. This last one makes me doubt if my function is really (IN ALL ASPECTS) a function that oscillates rapidly.

3) If it is not a function that oscillates rapidly (IN ALL ASPECTS), which integration method do you recommend me to integrate this function?

4) In the same way you could recommend me a good method to remove the noise to the data that I get after integrating ?.

Thank you very much. Greetings.

• Not enough info. S[Chi] ? t? S ? – Mariusz Iwaniuk Jul 20 '18 at 17:22
• I am taking S = 70, Chi = 1 (S and Chi take values in natural numbers and can also be zero) and t (time) is a variable with respect to which I will graph the integral obtained by some integration method. Thank you very much. – Math Jul 20 '18 at 19:47
• What is the range for t? We need this type of information (IN ALL ASPECTS) to try to help you. – chuy Jul 20 '18 at 20:16
• Might want to check NIntegrate reference guide page and maybe follow links from that to more advanced documentation. Oscillatory integrands get some discussion. – Daniel Lichtblau Jul 20 '18 at 22:25
• As I understand the message NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. appears almost always in the presence of complex integrands even if there are no oscillations, singularity or small WorkingPrecision. – Alex Trounev Jul 21 '18 at 5:05

Symbolic Solution

For the constants provided by the OP, the integral can be evaluated exactly.

(Sin[θ] ((Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])^(2 S - 1)
(1 + Sin[θ] Cos[ϕ - 2 S χ t Cos[θ]])))/. S -> 70
(* Cos[ϕ - 140 t χ Cos[θ]]^139 Sin[θ]^140 (1 + Cos[ϕ - 140 t χ Cos[θ]] Sin[θ])*)


Use Integrate instead of NIntegrate.

(((2 S + 1)/(4 Pi)) /. S -> 70) Integrate[%, {θ, 0, Pi}, {ϕ, 0, 2 Pi}]
(* 1 *)


independent of t and of χ. The answer also appears to be independent of S. For instance, for S == 1,

Cos[ϕ - 2 t χ Cos[θ]] Sin[θ]^2 (1 + Cos[ϕ - 2 t χ Cos[θ]] Sin[θ]);
(((2 S + 1)/(4 Pi)) /. S -> 1) Integrate[%, {θ, 0, Pi}, {ϕ, 0, 2 Pi}]
(* 1 *)


Incidentally, because the result is independent of t, it can be performed roughly four times faster by setting t == 0.

In answer to a comment below by Gio, a table of symbolic solutions can be obtained in less than 30 minutes on my four-process laptop with

exϕ[S_?NumericQ, t_?NumericQ] := (2 S + 1)/(4 Pi)
Integrate[Sin[θ] ((Sin[θ] Cos[ϕ - 2 S t Cos[θ]])^(2 S - 1)
(1 + Sin[θ] Cos[ϕ - 2 S t Cos[θ]])), {θ, 0, Pi}, {ϕ, 0, 2 Pi}]
ParallelTable[{t, exϕ[70, t]}, {t, 0, 5, 1/10}]


All answers are 1, as expected. Note, however, that reversing the order of the integration variables ({ϕ, 0, 2 Pi}, {θ, 0, Pi} instead of {θ, 0, Pi}, {ϕ, 0, 2 Pi}) enormously increases the computation time.

Incidentally, solutions for S an odd half-integer (1/2, 3/2, 5/2, ....) are given by (S+1/2)/S.

A numerical solution, if desired, can be obtained by

intϕ[S_?IntegerQ, t_?NumericQ, θ_?NumericQ] := (2 S + 1)/(4 Pi)
NIntegrate[((Sin[θ] Cos[ϕ - 2 S t Cos[θ]])^(2 S - 1)
(1 + Sin[θ] Cos[ϕ - 2 S  t Cos[θ]])), {ϕ, 0, 2 Pi}]

NIntegrate[intϕ[70, 5, θ], {θ, 0, Pi}]
(* 1.00355 *)


Other values of t give the same values.

• Hi bbgodfrey. I'he used previously "Integrate" and obtained results, but are they really reliable results?. Previously I gave the order to the program to plot the integral vs the time (in t [0,5]) for 6 time values (t = 0,1,2,3,4,5) and I obtained a result (this result took a bit of time) that I thought was good, but when I ordered to the program to plot the integral vs the time (in t [0,5]) but in steps of 0.1 (for example) it never gave me results, well, at least in 15 hours I left the computer working. – Math Jul 21 '18 at 16:18
• @Gio Yes, I am confident that the solution is 1 for all χ t, if S is an integer. In fact, I can prove it analytically. By the way, the integration is difficult to perform numerically, because the integrand is like a 1D delta function in 2D space, not because it is oscillatory, although it is somewhat oscillatory for larger χ t. Try plotting the integrand to see what I mean. You need a very large number for PlotPoints to obtain a smooth curve. – bbgodfrey Jul 21 '18 at 16:40
• Thank you very much for your help @bbgodfrey. Sorry, your analytical demonstration lies in just integrating by hand with S integer, or something else is needed?. What happend if S is semi-integer?. – Math Jul 21 '18 at 18:20
• @Gio S a half integer also works, but does not yield 1. – bbgodfrey Jul 22 '18 at 2:05
• Thank you very much @bbgodfrey. I have been trying to prove analytically that the integral is always 1 for any time and I got interesting results, but I still do not get that the integral is always 1 for any time. Could you give me some advice to reach this result? – Math Jul 22 '18 at 16:01

The cartesian product of the "Trapeziodal" strategy does pretty well, even if the recursion seems high:

Block[{S = 70, χ = 1, t = 1},
((2 S + 1)/(4 Pi)) NIntegrate[
Sin[θ] ((Sin[θ] Cos[ϕ -
2 S χ t Cos[θ]])^(2 S - 1) (1 +
Sin[θ] Cos[ϕ -
2 S χ t Cos[θ]])), {θ, 0, Pi}, {ϕ,
0, 2 Pi}, Method -> "Trapezoidal", MaxRecursion -> 100]
] // AbsoluteTiming

(*  {0.032665, 1.}  *)

• Thank you very much, @Michael E2. – Math Jul 21 '18 at 18:46