I have done the piecewise Fourier transform and now I am stuck with trying to get the final plot (on final picture) to make a manipulable plot.

I am new to Mathematica, hence I am using the trial version. The question has been done and I am not sure if answer is correct. I just need to know how to manipulate a double plotted wave of the step wave and the Fourier one with respect to n.

Any help would be appreciated!

Regards, Ben.

enter image description here

enter image description here

  • 2
    $\begingroup$ Welcome to Mathematica.SE! Please do not post screenshots of your code. Instead, post the code in proper Mathematica syntax, properly formatted in code blocks. Edit our post by clicking the grey edit button at the bottom of your post and click the grey question mark on the right side of the editing toolbar for formatting help. $\endgroup$ – march Mar 17 '17 at 20:24

I am going to use Piecewise rather than While. Not a big deal but Piecewise is specifically designed for this type of problem. I am also going to use less than or equal so that there are no gaps (again, probably no affect for this problem).

f[t_] := Piecewise[{{-2, -π < t < -π/2}, {0, -π/2 <= t < 0},
          { 3, 0 <= t < π}}]

Now plot it and save the plot

plot1 = Plot[f[t], {t, -π, π}, Exclusions -> None, 
  Ticks -> {{-π, -π/2, 0, π/2, π}, {-2, 3}}, 
  PlotRange -> {Automatic, {-2.5, 3.5}}, PlotStyle -> Black]

Mathematica graphics

For the second plot the input function will be

FourierTrigSeries[f[t], t, n]

where n is the integer selected in Manipulate. However one needs to wrap this expression in Evaluate before feeding it to plot.

Below is an example with n = 3.

Plot[Evaluate[FourierTrigSeries[f[t], t, 3]], {t, -π, π}, 
 Ticks -> {{-π, -(π/2), 0, π/2, π}, {-2, 3}}, 
 PlotStyle -> Red]

Mathematica graphics

Put this in a Manipulate where we ask for the number n to be an odd integer from 1 to 21. Use Show to display the two plots together.

  Plot[Evaluate[FourierTrigSeries[f[t], t, n]], {t, -\[Pi], \[Pi]}, 
   Ticks -> {{-\[Pi], -(\[Pi]/2), 0, \[Pi]/2, \[Pi]}, {-2, 3}}, 
   PlotStyle -> Red]
 {{n, 3}, 1, 21, 2}

Mathematica graphics

The above was for n=3. The figure below is for n=7.

Mathematica graphics

| improve this answer | |
  • $\begingroup$ That's great thank you! This is good for visualizing the convergence, very helpful. $\endgroup$ – Benjamin Crump Mar 18 '17 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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