-1
$\begingroup$

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}$

$\endgroup$

2 Answers 2

3
$\begingroup$
$Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global`*"]

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

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

(* 1/π + Cos[x]/2 + (2 Cos[2 x])/(3 π) - (2 Cos[4 x])/(15 π) + (
 2 Cos[6 x])/(35 π) - (2 Cos[8 x])/(63 π) + (2 Cos[10 x])/(
 99 π) - (2 Cos[12 x])/(143 π) *)

Working with the coefficients of the Cos terms from the third term on

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

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

Constructing the sum,

sum = sol[[;; 2]] +
  Inactive[Sum][c[k] Cos[2 k x], {k, 1, Infinity}]

enter image description here

f2[x_] = sum // Activate //
   ComplexExpand[#, TargetFunctions -> {Re, Im}] & //
  FullSimplify[#, 0 <= x < Pi/2] &

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

Graphically comparing f2 with Cos

Plot[f2[x] - Cos[x], {x, 0, Pi/2},
 WorkingPrecision -> 20,
 PlotRange -> {-0.01, 0.01}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Perfect. Thanks a lot! $\endgroup$
    – lotus2019
    Mar 21, 2022 at 3:54
  • $\begingroup$ Hello! I use this method to obtain the summation expression of a series, but the angle part of the sin function of this series is also variable: Clear["Global`*"]; f[x_] := Piecewise[{{0, -2 <= x < 0}, {h, 0 <= x <= 2}}]; sol = FourierTrigSeries[f[t], t, 24, FourierParameters -> {1, 2 [Pi]/4}] So how should I modify this Code: c[k_] = FindSequenceFunction[(List @@ sol)[[2 ;;]] /. _Sin :> 1, k] ? $\endgroup$
    – lotus2019
    Mar 21, 2022 at 9:30
  • $\begingroup$ I do not understand what you are trying to do in the comment. Post a new question explaining what you are trying to do, what you have tried, and the problems that you are experiencing. $\endgroup$
    – Bob Hanlon
    Mar 21, 2022 at 17:13
  • $\begingroup$ OK. Thanks! I have post a new question ‘’FindSequenceFunction on trigonometric series‘’ just now. $\endgroup$
    – lotus2019
    Mar 22, 2022 at 2:58
1
$\begingroup$

So I want to ask, how to use FindSequenceFunction to obtain the general expression of this Fourier cosine series:

Perhaps the following -or maybe I misunderstood the task at hand

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

Then

FindSequenceFunction[{3, -15, 35, -63, 99, -143, 195, -255}, n]

(-1)^(1 + n) (-1 + 4 n^2)

gives you the alternating pattern and the denominator.

Then you can define the FindSequenceFunction output

guess[x_, xx_] := 
 1/Pi + Cos[x]/2 + 
  2/Pi Sum[((-1)^(1 + n)) /(-1 + 4 n^2) Cos[2 n x], {n, 1, xx}]

tests

$\endgroup$
5
  • $\begingroup$ Thank you. This is indeed a solution. But there are too many manual operations. And the value of some items is 0. These items are not taken into account when using FindSequenceFunction, which is easy to make mistakes. $\endgroup$
    – lotus2019
    Mar 21, 2022 at 3:24
  • $\begingroup$ I am sorry, but this is not quite clear to me and I cannot help. Since you said that mine is indeed a solution, perhaps you could update the OP and explain with a minimal example -say 5 terms- how automated you'd like to be. I will come back to this :) $\endgroup$
    – bmf
    Mar 21, 2022 at 3:26
  • 1
    $\begingroup$ In my question, I mean to use FindSequenceFunction to get the expression directly, automatically, in one step, or with a small amount of manual operation, but not too much, otherwise it will be almost like manual calculation. This doesn't seem to need much explanation, does it? :) Thank you all the same. $\endgroup$
    – lotus2019
    Mar 21, 2022 at 3:33
  • 1
    $\begingroup$ You might go another step: guess[x, Infinity] // FullSimplify. $\endgroup$
    – Michael E2
    Mar 21, 2022 at 3:37
  • $\begingroup$ @MichaelE2 yes, of course. Thanks for pointing this out :) $\endgroup$
    – bmf
    Mar 21, 2022 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.