Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I want to express a function as a sum of fourier series.
I tried the code below. It works. But only get one period (from 0 to 1).
How to display every period correctly?

f = Piecewise[{{10 x, 0 <= x < 0.1}, {-(10/9) x + (10/9), 0.1 <= x < 1}}];
coeff[0] = 1/4 Integrate[f, {x, 0, 1}];
coeff[n_] = 1/4 Integrate[f*Exp[I Pi n x/2], {x, 0, 1}];
series[m_, x_] := Sum[Exp[-I Pi n x/2] coeff[n], {n, -m, m}];
Plot[Evaluate[Table[series[j, x], {j, 1, 5}]], {x, -2, 2}]

enter image description here

share|improve this question

marked as duplicate by Artes, belisarius, rm -rf Nov 14 '13 at 14:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This question, as it is asked, is more related to mathematics rather than Mathematica. I suggest you read more about Fourier Transform, Integral, Series, so you grasp the concepts and the relationships between them. –  Sektor Nov 14 '13 at 6:49

1 Answer 1

You can try using Mathematica FourierSeries function directly. Change the plot range to see more periods.

enter image description here

Manipulate[

 Module[{x, f, g},
  f = Piecewise[{{10 x, 0 <= x < 01/10}, {-(10/9) x + (10/9),1/10 <= x < 1}}];
  g = FourierSeries[f, x, n];
  Plot[{f, g}, {x, -lim, lim}, PlotRange -> All, ImageSize -> 300,ImagePadding -> 20]
  ],

 {{n, 3, "number of terms"}, 0, 10, 1, ImageSize -> Tiny,Appearance -> "Labeled"},
 {{lim, 10, "plot range"}, 1, 30, .1, ImageSize -> Tiny,Appearance -> "Labeled"},

 SynchronousUpdating -> False,
 SynchronousInitialization -> False,
 ContinuousAction -> False,
 Alignment -> Center,
 ImageMargins -> 5,
 FrameMargins -> 5,
 ControlPlacement -> Top
 ]
share|improve this answer

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