1

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?

op-luffy
  • 21
  • 6
  • Have you read the documentation? What do you find confusing? – CA Trevillian Jan 13 '22 at 05:59
  • 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. – xzczd Jan 13 '22 at 06:05
  • Is your function periodic? Otherwise you need a Fourier Integral. – Daniel Huber Jan 13 '22 at 10:34
  • @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:) – op-luffy Jan 13 '22 at 10:44
  • @DanielHuber Thanks for your response. My function is not periodic, and what I want is its Fourier series that approximate in its interval. – op-luffy Jan 13 '22 at 10:46
  • Rescale already involves coordinate translation, and this isn't achievable with FourierParameters. Once again, please read the Details and Options section of FourierSeries. – xzczd Jan 13 '22 at 10:55
  • @xzczd You mean we can't use FourierParameters to realize what Rescale does, right? Can't we just use Rescale for general function defined on any interval? For more clearness, I updated the quesion. Thanks for your helpful comments. – op-luffy Jan 13 '22 at 11:04
  • Please make a bit more effort to edit your question, currently the edited question is just confusing. – xzczd Jan 13 '22 at 11:08
  • thank you very much. I update my post and I hope it is more clear now. So now my question becomes is Rescale method general enough? I am sure that you must know this method when you make easyFourier, then why you made it? Is it becasue Rescale method has some its limitations? I had naively think my question is similar to your question where I find easyFourier. – op-luffy Jan 13 '22 at 11:30
  • You need to add @xzczd in your comment or I won't get the reminder. Then, please observe the output of easyFourier more carefully. – xzczd Jan 14 '22 at 03:32
  • @xzczd, I made another update to my post. Please see my update 2, I understan why Rescale method can't solve your problem. Do I understand easyFourier right as stated in update 2? Thanks for your kind and helpful comments. – op-luffy Jan 14 '22 at 04:03
  • Yes, exactly. This is stated in the body of my question BTW. – xzczd Jan 14 '22 at 04:10
  • @xzczd Thanks! Sorry for not carfully reading your post :) Have a nice day, sir:) – op-luffy Jan 14 '22 at 04:13
  • @xzczd I think rmw gives a very infromative answer in his respone to my update 2. After all these discussions, I learned a lot from both of you. The Fourier series in Mathematica will definitely become more and more clear. – op-luffy Jan 15 '22 at 03:10

1 Answers1

2
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

rmw
  • 1,950
  • 6
  • 9
  • 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]? – op-luffy Jan 13 '22 at 10:50
  • @op-luffy Try it! Take any interval [a, b], e.g. [-Pi , 2.5Pi] or something similar. – rmw Jan 13 '22 at 11:20
  • @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." – rmw Jan 14 '22 at 15:17
  • Thanks you. @rmw, I have never expected such a beautiful solution! So it can realize what easyFourier aims to do? – op-luffy Jan 15 '22 at 03:29