Message Boards Message Boards

[?] Use Manipulate to plot the Fourier Series?

Posted 6 years ago

Hi. I'm new with Mathematica and would like to know where my coding is wrong using Manipulate and Plot functions:

This Expression works fine:

Manipulate[ExpToTrig[FourierSeries[Cosh[x], x, N]], {N, 1, 10, 1}]

However, when I try to use Manipulate to plot the Fourier Series, it does not plot anything:

Manipulate[Plot[ExpToTrig[FourierSeries[Cosh[x], x, N]], {x, -3, 3}], {N, 1, 10,1}]

Thank you.

Andre

POSTED BY: andreusp6
5 Replies
Posted 6 years ago

Shanghai, Man, a huge difference! When I tried a few polynomials, it took forever and the program crashed a few times. With your little code, it is smooth and fast! Thanks a lot. Andre

POSTED BY: Updating Name
Posted 6 years ago

Hey, I noticed that! Let me try and let you know. Andre

POSTED BY: andreusp6

One thing can be improved for smooth animation is that to pre-compute all cases before plot in the Manipulate function:

Clear[f, fs];
f[x_,n_]:=ExpToTrig[FourierSeries[Cosh[x],x,n]]
fs=Table[f[x,n],{n,10}];
Manipulate[
Plot[
fs[[n]],{x,-3,3}],
{n,1,10,1}]

You can now drag the slider without glitch.

POSTED BY: Shenghui Yang
Posted 6 years ago

Fantastic Hans! You used the function Evaluate. I was not aware of this function. It is working now for several functions and expansions just fine! Thank you very much!!! Awesome! Andre

POSTED BY: andreusp6

Generally: be careful using upper-case characters, they are very often predefined, although it works in your case. Then: Plot behaves sometimes peculiar. Try

Manipulate[Plot[Evaluate[ExpToTrig[FourierSeries[Cosh[x], x, n]]], {x, -3, 3}], {n, 1, 10, 1}]
POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract