# FindSequenceFunction on trigonometric series

I want to get the sine series general expression of the following two functions by FindSequenceFunction.

(1)

$$f(x)=\left\{\begin{array}{l}0,-2 \leqslant x<0, \\ h, 0 \leqslant x<2\end{array} \quad(h \neq 0)\right.$$

The result is $$f(x)=\frac{h}{2}+\frac{2 h}{\pi}\left(\sin \frac{\pi x}{2}+\frac{1}{3} \sin \frac{3 \pi x}{2}+\frac{1}{5} \sin \frac{5 \pi x}{2}+\cdots+\frac{1}{2 n-1} \sin \frac{(2 n-1) \pi x}{2}+\cdots\right)$$

I first calculated the Fourier series of the finite term of the function.

Clear["Global*"];
f[x_] := Piecewise[{{0, -2 ≤ x < 0}, {h, 0 ≤ x ≤ 2}}];
sol = FourierTrigSeries[f[t], t, 24,
FourierParameters -> {1, 2 π/4}]


$$\frac{\mathrm{h}}{2}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{\pi \mathrm{t}}{2}\right]}{\pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{3 \pi \mathrm{t}}{2}\right]}{3 \pi}+\frac{2 h \operatorname{Sin}\left[\frac{5 \pi \mathrm{t}}{2}\right]}{5 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{7 \pi \mathrm{t}}{2}\right]}{7 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{9 \pi \mathrm{t}}{2}\right]}{9 \pi}+$$ $$\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{11 \pi \mathrm{t}}{2}\right]}{11 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{13 \pi \mathrm{t}}{2}\right]}{13 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{15 \pi \mathrm{t}}{2}\right]}{15 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{17 \pi \mathrm{t}}{2}\right]}{17 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{19 \pi \mathrm{t}}{2}\right]}{19 \pi}+\frac{2 \mathrm{~h} \mathrm{Sin}\left[\frac{21 \pi \mathrm{t}}{2}\right]}{21 \pi}+\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{23 \pi \mathrm{t}}{2}\right]}{23 \pi}$$

Then the function sequence of sine function coefficients can be calculated by FindSequenceFunction.

c[k_] = FindSequenceFunction[(List @@ sol)[[2 ;;]] /. _Sin :> 1, k]


$$\frac{2 h}{(-1+2 k) \pi}$$

But the angle of sine function is not operated by FindSequenceFunction. How to extract the angle from sine function? Such as extract $$\frac{13 \pi t}{2}$$ from the term $$\frac{2 \mathrm{~h} \operatorname{Sin}\left[\frac{13 \pi \mathrm{t}}{2}\right]}{13 \pi}$$, build a list, and then operate it with FindSequenceFunction? I know this example is very simple and easy to calculate manually. But I just give this example. I want to know how to use MMA to realize this idea.

(2)The following function also does not get the result.

$$f(x)=\left\{\begin{array}{cc}\cos x, & 0 \leqslant x<\frac{\pi}{2} \\ 0, & \frac{\pi}{2} \leqslant x \leqslant \pi\end{array}\right.$$

The result is $$f(x)=\frac{1}{\pi}\left[\sin x+2 \sum_{n=2}^{\infty} \frac{1}{n^{2}-1}\left(n-\sin \frac{n \pi}{2}\right) \sin n x\right] \quad(0

Clear["Global*"]
f[x_] := Piecewise[{{Cos[x], 0 ≤ x < π/2}, {0, π/2 ≤ x <= π}}];
sol = FourierSinSeries[f[x], x, 12]


$$\frac{\operatorname{Sin}[x]}{\pi}+\frac{4 \operatorname{Sin}[2 x]}{3 \pi}+\frac{\operatorname{Sin}[3 x]}{\pi}+\frac{8 \operatorname{Sin}[4 x]}{15 \pi}+\frac{\operatorname{Sin}[5 x]}{3 \pi}+\frac{12 \operatorname{Sin}[6 x]}{35 \pi}+\frac{\operatorname{Sin}[7 x]}{3 \pi}+\frac{16 \operatorname{Sin}[8 x]}{63 \pi}+\frac{\operatorname{Sin}[9 x]}{5 \pi}+\frac{20 \operatorname{Sin}[10 x]}{99 \pi}+\frac{\operatorname{Sin}[11 x]}{5 \pi}+\frac{24 \operatorname{Sin}[12 x]}{143 \pi}$$

c[k_] = FindSequenceFunction[(List @@ sol)[[2 ;;]] /. _Sin :> 1, k]


DifferenceRoot $$\left[\right.$$ Function $$\left.\left[\{\dot{y}, \dot{n}\},\left\{-4+\dot{n} \pi \dot{y}[\dot{n}]+(4+\dot{n}) \pi \dot{y}[2+\dot{n}]=0, \dot{y}[1]==\frac{4}{3 \pi}, \dot{y}[2]==\frac{1}{\pi}\right\}\right]\right][k]$$

Clear["Global*"];

f[x_] := Piecewise[{{0, -2 <= x < 0}, {h, 0 <= x <= 2}}];

sol = FourierTrigSeries[f[x], x, 24, FourierParameters -> {1, 2 π/4}]

(* h/2 + (2 h Sin[(π x)/2])/π + (2 h Sin[(3 π x)/2])/(3 π) + (
2 h Sin[(5 π x)/2])/(5 π) + (2 h Sin[(7 π x)/2])/(7 π) + (
2 h Sin[(9 π x)/2])/(9 π) + (2 h Sin[(11 π x)/2])/(11 π) + (
2 h Sin[(13 π x)/2])/(13 π) + (2 h Sin[(15 π x)/2])/(
15 π) + (2 h Sin[(17 π x)/2])/(17 π) + (
2 h Sin[(19 π x)/2])/(19 π) + (2 h Sin[(21 π x)/2])/(
21 π) + (2 h Sin[(23 π x)/2])/(23 π) *)


The arguments of the Sin terms are

a[k_] = FindSequenceFunction[Cases[sol, Sin[arg_] :> arg, Infinity], k] //
Simplify

(* 1/2 (-1 + 2 k) π x *)


The coefficients of the Sin terms are

c[k_] = FindSequenceFunction[Cases[sol, coef_*Sin[_] :> coef, Infinity], k]

(* (2 h)/((-1 + 2 k) π) *)

sum = sol[[1]] + Inactive[Sum][c[k]*Sin[a[k]], {k, 1, Infinity}]


sumr = sum // Activate // ComplexExpand[#, TargetFunctions -> {Re, Im}] & //
FullSimplify

(* (1/(2 π))h (π - ArcTan[1 + Cos[(π x)/2], -Sin[(π x)/2]] +
ArcTan[1 + Cos[(π x)/2], Sin[(π x)/2]] -
ArcTan[2 Sin[(π x)/4]^2, -Sin[(π x)/2]] +
ArcTan[2 Sin[(π x)/4]^2, Sin[(π x)/2]]) *)

Plot[f[x] - sumr, {x, 0, 2}, PlotRange -> {-0.01, 0.01}]


For the second example,

Clear["Global*"]

f[x_] := Piecewise[{{Cos[x], 0 <= x < Pi/2}, {0, Pi/2 <= x <= Pi}}];

sol = FourierSinSeries[f[x], x, 12]

(* Sin[x]/π + (4 Sin[2 x])/(3 π) + Sin[3 x]/π + (8 Sin[4 x])/(
15 π) + Sin[5 x]/(3 π) + (12 Sin[6 x])/(35 π) + Sin[7 x]/(
3 π) + (16 Sin[8 x])/(63 π) + Sin[9 x]/(5 π) + (20 Sin[10 x])/(
99 π) + Sin[11 x]/(5 π) + (24 Sin[12 x])/(143 π) *)


The coefficients for terms 3 and up

c[k_] = Assuming[Element[k, PositiveIntegers],
FindSequenceFunction[(List @@ sol)[[3 ;;]] /. _Sin :> 1, k] // Simplify]

(* (4 - I I^k + I^(1 + 3 k) + 2 k)/((1 + k) (3 + k) π) *)


Checking,

((List @@ sol)[[3 ;;]] /. _Sin :> 1) === (c /@ Range[10])

(* True *)

sum = sol[[;; 2]] + Inactive[Sum][c[k]*Sin[(k + 2) x], {k, 1, Infinity}]


sumr = sum // Activate // ComplexExpand[#, TargetFunctions -> {Re, Im}] & //
FullSimplify

(* (1/(2 π))(-2 ArcTan[1 - Cos[x], -Sin[x]] + 2 ArcTan[1 - Cos[x], Sin[x]] -
ArcTan[1 - Sin[x], -Cos[x]] + ArcTan[1 - Sin[x], Cos[x]] +
ArcTan[1 + Sin[x], -Cos[x]] - ArcTan[1 + Sin[x], Cos[x]]) Cos[x] *)


Graphically comparing f with sumr

Plot[f[x] - sumr, {x, 0, Pi/2},
PlotRange -> {-0.01, 0.01},
WorkingPrecision -> 15]


• Perfect! Extracting the arguments of the Sin terms by Case is great! Thank you! Mar 22, 2022 at 15:03

But the angle of sine function is not operated by FindSequenceFunction. How to extract the angle from sine function?

The following gives you the arguments of the Sin function

Table[List @@@ sol[[ii]][[4]][[1]], {ii, 2, Length@(List @@ sol)}]


{(π t)/2, (3 π t)/2, (5 π t)/2, (7 π t)/2, ( 9 π t)/2, (11 π t)/2, (13 π t)/2, (15 π t)/2, ( 17 π t)/2, (19 π t)/2, (21 π t)/2, (23 π t)/2}

and something like that afterwards I guess

Sin@FullSimplify@
FindSequenceFunction[
Table[List @@@ sol[[ii]][[4]][[1]], {ii, 2, Length@(List @@ sol)}],
xx]


Sin[1/2 π t (-1 + 2 xx)]

Is this what you are after or did I misunderstand what you wanted to achieve?

• Your answer has solved the key part of this problem. Thank you very much! Mar 22, 2022 at 3:13
• Don't mention it. Glad I was able to help :-)
– bmf
Mar 22, 2022 at 3:14

f[x_] := Piecewise[{{Cos[x],   0 <= x < \[Pi]/2}, {0, \[Pi]/2 <= x <= \[Pi]}}];
sol = FourierSinSeries[f[x], x, 12];
c[k_] = FindSequenceFunction[(List @@ sol)[[2 ;;]] /. _Sin :> 1, k]


DifferenceRoot[ Function[{\[FormalY], \[FormalN]}, {-4 + \[FormalN] Pi \[FormalY][\ \[FormalN]] + (4 + \[FormalN]) Pi \[FormalY][2 + \[FormalN]] == 0, \[FormalY][1] == Rational[4, 3]/Pi, \[FormalY][2] == Pi^(-1)}]][k]

, namely,

RSolve[{-4 + k*Pi*y[k] + (4 + k) Pi y[2 + k] == 0, y[1] == 4/3/Pi,
y[2] == Pi^(-1)}, y[k], k]


one obtains a long output. Here is its part.

{{y[k] -> (1575 Sqrt[\[Pi]] LegendreP[k, -(3/2), 2, 0] LegendreQ[1, -(3/2), 0] LegendreQ[ 1, -(3/2), 2, 0]...-21 LegendreQ[2,-(3/2),2,0]))}}

• FullSimplify shortens that output. Mar 22, 2022 at 6:30
• Thanks! It seems that if odd items and even items can be sorted in a separate list, it should be able to get a simpler summation expression. But I don't know how to use 'FindSequenceFunction' to get the result. Mar 22, 2022 at 7:59
• @lotus2019: Can you present a code instead of fuzzy words? Mar 22, 2022 at 8:57
• First, List1=Table[sol[[2 i + 1]], {i, 0, 5}]; List2=Table[sol[[2 i]], {i, 1, 5}], then, apply FindSequenceFunction to these two lists respectively. Mar 22, 2022 at 12:39