I want to get cosine series of the following functions.
$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}+\frac{1}{2} \cos x+\frac{2}{\pi} \sum_{k=1}^{\infty} \frac{(-1)^{k-1}}{4 k^{2}-1} \cos 2 k x \quad(0 \leqslant x \leqslant \pi)$
First, the finite term cosine series expression of the function can be obtained by FourierCosSeries
. For example, n=10:
Clear["Global`*"]
f[x_] := Piecewise[{{Cos[x], 0 <= x < Pi/2}, {0, Pi/2 <= x <= Pi}}];
sol = FourierCosSeries[f[x], x, 10]
$\frac{1}{\pi}+\frac{\operatorname{Cos}[x]}{2}+\frac{2 \operatorname{Cos}[2 x]}{3 \pi}-\frac{2 \operatorname{Cos}[4 x]}{15 \pi}+\frac{2 \operatorname{Cos}[6 x]}{35 \pi}-\frac{2 \operatorname{Cos}[8 x]}{63 \pi}+\frac{2 \operatorname{Cos}[10 x]}{99 \pi}$
I find that in addition to the first two terms of this series, the latter terms change regularly according to n. So I want to ask, how to use FindSequenceFunction to obtain the general expression of this Fourier cosine series: $f(x)=\frac{1}{\pi}+\frac{1}{2} \cos x+\frac{2}{\pi} \sum_{k=1}^{\infty} \frac{(-1)^{k-1}}{4 k^{2}-1} \cos 2 k x \quad(0 \leqslant x \leqslant \pi)$?
EDIT
I also tried to solve this problem in other ways.
The most convenient way is to use the following link program. https://mathematica.stackexchange.com/a/149469/69835
Another way, using the classic solution method in the textbook, there may be some errors in my code and the result is not perfect.
Clear["Global`*"]
g[x_] := Piecewise[{{0, -Pi <= x <= -Pi/2}, {Cos[x], -Pi/2 < x <
0}, {Cos[x], 0 <= x < Pi/2}, {0, Pi/2 <= x <= Pi}}];
f[x_] = Simplify`PWToUnitStep@g[x];
$Assumptions = n \[Element] Integers && n >= 0;
an = (1/Pi)*Integrate[f[x]*Cos[n*x], {x, -Pi, Pi}] // FullSimplify;
a1 = Limit[an, n -> 1] // FullSimplify;
a0 = (1/Pi)*Integrate[f[x], {x, -Pi, Pi}];
bn = (1/Pi)*Integrate[f[x]*Sin[n*x], {x, -Pi, Pi}] // FullSimplify;
b1 = Limit[bn, n -> 1] // FullSimplify;
series = a0/2 + a1 Cos[x] + b1 Sin[x] +
Inactive[Sum][an Cos[n x] + bn Sin[n x], {n, 2, Infinity}]
$\frac{1}{\pi}+\frac{\operatorname{Cos}[x]}{2}+\sum_{n=2}^{\infty} \frac{2 \operatorname{Cos}\left[\frac{n \pi}{2}\right] \operatorname{Cos}[n x]}{\pi-n^{2} \pi}$