How to plot several terms in a Fourier series

Click For Summary

Discussion Overview

The discussion revolves around plotting a Fourier series representation of a periodic function using different programming tools, specifically Mathematica and Python. Participants explore how to visualize the series as more terms are added, focusing on the mathematical formulation and practical implementation of the plotting process.

Discussion Character

  • Technical explanation, Experimental/applied, Homework-related

Main Points Raised

  • One participant presents a Fourier series function expressed as $$\sum_{k=0}^{N}\frac{sin((2k+1)x)}{2k+1}$$ and seeks guidance on plotting it in Mathematica.
  • Another participant asks for clarification on whether the goal is to create an animated figure or to overlay multiple curves on a single plot.
  • A participant mentions finding a Python source code that meets their needs for plotting the function.
  • A fourth participant provides a MATLAB code snippet that demonstrates how to plot the Fourier series using a loop to add terms incrementally.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to plotting the Fourier series, as different programming languages and methods are proposed without resolving which is superior.

Contextual Notes

The discussion includes various programming approaches and lacks a unified method for plotting the Fourier series, highlighting different preferences for software tools among participants.

Who May Find This Useful

This discussion may be useful for individuals interested in Fourier series, mathematical visualization, and programming in Mathematica, Python, or MATLAB.

rmiller70015
Messages
110
Reaction score
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
$$\sum_{k=0}^{N}\frac{sin((2k+1)x)}{2k+1}$$

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.
 
Physics news on Phys.org
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?
 
  • Like
Likes   Reactions: rmiller70015
I actually found a python source code that did what I needed, but thank you for your willingness to help.
 
Matlab in about 10 lines...

Code:
clear all;

x=linspace(0, 3*pi, 1000);
Z = 0;
for k = 1:3
    y = sin((2*k+1)*x)/(2*k+1);
   plot(x,y)
   hold on;
   Z = Z+y;
end
plot(x,Z);
hold off;
 
  • Like
Likes   Reactions: Jamison Lahman and rmiller70015

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K