Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica How to plot several terms in a Fourier series

  1. Feb 4, 2017 #1
    I was given a function that is periodic about 2π and I need to plot it. I was wondering if there is a way to input a value and have mathematica generate a new graph with the number of iterations. The function is:

    $$\sum_{n=1}^{N}\frac{sin(nx)}{n}$$ where n is an odd integer. I guess a better way to express the function is

    So far I've only used mathematica to plot simple functions and solve ODE's so I'm not quite sure how to approach this.
  2. jcsd
  3. Feb 5, 2017 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member
    2017 Award

    Exactly what do you want to do? Do you want to update the figure (like an animation) or do you want to add additional curves to the same plot?
  4. Feb 5, 2017 #3
    I actually found a python source code that did what I needed, but thank you for your willingness to help.
  5. Feb 6, 2017 #4

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Matlab in about 10 lines....

    Code (Text):

    clear all;

    x=linspace(0, 3*pi, 1000);
    Z = 0;
    for k = 1:3
        y = sin((2*k+1)*x)/(2*k+1);
       hold on;
       Z = Z+y;
    hold off;

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads - plot several terms Date
Plot a stereographic hypercube in a Mac's Grapher.app? Saturday at 8:22 AM
Mathematica Errors when plotting but not when evaluating Mar 13, 2018
Mathematica Color Contour Plots Mar 8, 2018
Mathematica Taking forever to plot Feb 27, 2018
Mathematica plotting several functions Jun 27, 2012