0
$\begingroup$

I would like to build this piecewise function

piecewise function

Please help me to find the appropriated code.

P.S: In a second step, I would like to obtain the Fourier series of this function.

$\endgroup$
  • $\begingroup$ Look up SawtoothWave[]. See this as well. $\endgroup$ – J. M. will be back soon Aug 9 '17 at 17:53
  • $\begingroup$ I tried this f[x_] = SawtoothWave[{-1, 1}, x] but it is not yet the result i want. Moreover, does Mathematica know how to use this function to calcultate the Fourier series ? $\endgroup$ – Bendesarts Aug 9 '17 at 20:39
4
$\begingroup$
f[x_] := SawtoothWave[{-1, 1}, (x + 1)/2]
Plot[f[x], {x, -3, 3}]

plot

and perhaps this for the 1st 20 terms.

g[x_] = FourierSinSeries[f[x], x, 20];
Plot[g[x], {x, -3, 3}]

plot

Update

Or perhaps you are looking for this.

 a[n_] = FourierSinCoefficient[f[x], x, n]
-((2 ((-1)^n (-4 + π) + 2 Cos[n] + 2 Cos[3 n]))/(n π))
 h[x_] = Sum[a[n] Sin[n x], {n, 20}];
 Plot[h[x], {x, -3, 3}]

plot

$\endgroup$
  • $\begingroup$ thank you for your help, is there a function which gives directly all the Fourier Series that is to say with the an (terms related to the cosinus) and bn (terms related to the sinus) $\endgroup$ – Bendesarts Aug 9 '17 at 21:10
  • $\begingroup$ @Bendesarts. Mathematica has around 20 functions for working with Fourier series. Pleas consult the documentation. $\endgroup$ – m_goldberg Aug 9 '17 at 21:16
  • $\begingroup$ of course, thank you but, i didn't see this one and normally it should be the most direct function $\endgroup$ – Bendesarts Aug 9 '17 at 21:16
  • $\begingroup$ @Bendesarts. I not sure I understand what you think is "the most direct function", but I made an update based on a guess. To my thinking, h is no more direct than g. $\endgroup$ – m_goldberg Aug 9 '17 at 21:52

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