# Generating a sawtooth wave [closed]

I would like to build this piecewise function

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

• Look up SawtoothWave[]. See this as well. – J. M. will be back soon Aug 9 '17 at 17:53
• 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 ? – Bendesarts Aug 9 '17 at 20:39

f[x_] := SawtoothWave[{-1, 1}, (x + 1)/2]
Plot[f[x], {x, -3, 3}]


and perhaps this for the 1st 20 terms.

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


### 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}]


• 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) – Bendesarts Aug 9 '17 at 21:10
• @Bendesarts. Mathematica has around 20 functions for working with Fourier series. Pleas consult the documentation. – m_goldberg Aug 9 '17 at 21:16
• of course, thank you but, i didn't see this one and normally it should be the most direct function – Bendesarts Aug 9 '17 at 21:16
• @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. – m_goldberg Aug 9 '17 at 21:52