1
$\begingroup$

I am struggling to understand the Fourier series in Mathematica.

I don't find a way to calculate Fourier series for a general function which is not periodic and defined on a interval but not on typical inervals like [-Pi, Pi] as required by FourierSeries command. For example like a function shown below.

My first naive idea to use FourierParameters option of FourierSeries, but I don't know how to set them.

I search the forum for my problem. I saw the great answer by xzczd who invented easyFourier , but that is too much programming for me.

func[x_] := Piecewise[{{x, 1 <= x < 2}, {1, 2 <= x <= 3}}, Undefined]
Plot[func[x], {x, 0, 4}]

enter image description here

Thanks in advance! :)

======================= Update 1 ============================

Thanks to the helpful comments by xzczd, it seems that the FourierParameters is not feaible to obtain a non-periodic function defined on any interval.

As inspired by @rmw's Rescale method, problem seems to be solved. Thus, now my question changed to "this Rescale based method is general enough? What are its limitations?"

======================= Update 2 ============================

As kindly suggested by @xzczd in the comments, I double checked the easyFourier and find some useful observation.

Beside making Fourier series for an function on genral interval [a, b], the other motivation for making easyFourier by xzczd is that a general form of Fourier series is highly desired,for example, for solving pdes. In this general form, a symbol parameter C, instead of a specific numeric integer, is used to control the order of expansion.

Although, Rescale method as shown by rmw can be used to give Fourier for an fucntion on any interval, it can't gives the general form of Fourier series.

======================= Update 3 ============================

Now, I think I should give another update. rmw gives such a good answer which shows that Rescale method can do what easyFourier aimed to do. Do I understand this Right?

$\endgroup$
14
  • $\begingroup$ Have you read the documentation? What do you find confusing? $\endgroup$ Jan 13, 2022 at 5:59
  • $\begingroup$ Well, if it can be achieved with FourierParameter, I won't have created easyFourier… Just read the Details and Options section of FourierSeries, you'll see it's not possible to Translate with FourierParameter. $\endgroup$
    – xzczd
    Jan 13, 2022 at 6:05
  • $\begingroup$ Is your function periodic? Otherwise you need a Fourier Integral. $\endgroup$ Jan 13, 2022 at 10:34
  • $\begingroup$ @xzczd: Why is that? Is it beacuse that the specific form of FourierParameters {a,b} not general enough? Can't we just use variable change or Rescale method as shown by @rmw ? Please, can you show a example whose Fourierseries cannot be obtaiined? Thanks:) $\endgroup$
    – op-luffy
    Jan 13, 2022 at 10:44
  • $\begingroup$ @DanielHuber Thanks for your response. My function is not periodic, and what I want is its Fourier series that approximate in its interval. $\endgroup$
    – op-luffy
    Jan 13, 2022 at 10:46

1 Answer 1

2
$\begingroup$
func[x_] = Piecewise[{{x, 1 <= x < 2}, {1, 2 <= x <= 3}}];

The Fourier functions of Mathematica calculate in the interval [-Pi,Pi] or in case of Sin- and CosSeries in the interval [0, Pi]. To translate the Pi-interval in your function-interval, work with Rescale.

{\[Pi]Interval, fInterval} = {Rescale[x, {-Pi, Pi}, {1, 3}], Rescale[x, {1, 3}, {-Pi, Pi}]};
fR = FourierTrigSeries[func[x] /. x -> \[Pi]Interval, x, 10] /. x -> fInterval // Simplify;
Plot[fR, {x, 1, 3}]

enter image description here

Supplement because of OP's statement in his 2nd update.

cn = FourierCoefficient[func[x] /. x -> \[Pi]Interval, x, n] /.  x -> fInterval;
T = 3 - 1;
a0 = cn[[1, 1, 1]];
an = 2 ComplexExpand@Re@cn[[2]]*Cos[2 \[Pi] n x/T] // Simplify;
bn = -2 ComplexExpand@Im@cn[[2]]*Sin[2 \[Pi] n x/T] // Simplify;

serie = a0 + Inactivate[Sum[Limit[an + bn, n -> k], {k, 1,Infinity]}],  Sum | Limit] // Simplify

enter image description here

fPoly = serie /. \[Infinity] -> 20 // Activate;
Plot[fPoly, {x, 1, 3}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks for your help! I wonder that is this Rescale based method genral enough for an arbitrary function f[x]defined on any interval [a, b]? $\endgroup$
    – op-luffy
    Jan 13, 2022 at 10:50
  • $\begingroup$ @op-luffy Try it! Take any interval [a, b], e.g. [-Pi , 2.5Pi] or something similar. $\endgroup$
    – rmw
    Jan 13, 2022 at 11:20
  • $\begingroup$ @op-luffy Regarding update 2; if you really understood Rescale, I don't understand your statement: "...it can't gives the general form of Fourier series." $\endgroup$
    – rmw
    Jan 14, 2022 at 15:17
  • $\begingroup$ Thanks you. @rmw, I have never expected such a beautiful solution! So it can realize what easyFourier aims to do? $\endgroup$
    – op-luffy
    Jan 15, 2022 at 3:29

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.