# How to plot several terms in a Fourier series

• Mathematica
• rmiller70015
In summary, the conversation discusses a function that is periodic about 2π and needs to be plotted. The person is looking for a way to input a value and generate a new graph with a specific number of iterations using the function $\sum_{n=1}^{N}\frac{sin(nx)}{n}$ where n is an odd integer. They also mention an alternative expression for the function, $\sum_{k=0}^{N}\frac{sin((2k+1)x)}{2k+1}$. They are not familiar with how to approach this in Mathematica and are looking for help. They were able to find a python source code that achieved their goal, and mention a Matlab code that can also plot
rmiller70015
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.

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?

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;

Jamison Lahman and rmiller70015

## 1. What is a Fourier series?

A Fourier series is a mathematical representation of a function in terms of an infinite sum of sines and cosines. It is used to approximate periodic functions and has applications in signal processing, image processing, and differential equations.

## 2. How do I plot a Fourier series?

To plot a Fourier series, you will need to first determine the coefficients of the sines and cosines in the series. This can be done using integration or other mathematical methods. Once you have the coefficients, you can use a graphing calculator or software to plot the series. Alternatively, you can also plot the series by hand using a graphing paper and the calculated coefficients.

## 3. Can I plot more than one term in a Fourier series?

Yes, you can plot multiple terms in a Fourier series. In fact, the more terms you include in the series, the more accurate the approximation of the original function will be. However, plotting too many terms can make the graph look cluttered and difficult to interpret.

## 4. How do I determine the number of terms to include in a Fourier series?

The number of terms to include in a Fourier series depends on the complexity of the original function and the desired level of accuracy in the approximation. In general, including more terms will result in a more accurate approximation but will also require more computational resources. It is recommended to start with a small number of terms and gradually increase until the desired accuracy is achieved.

## 5. Are there any limitations to plotting a Fourier series?

There are a few limitations to plotting a Fourier series. First, the series can only approximate periodic functions. Second, the series may not accurately represent functions with sharp discontinuities or corners. Lastly, the accuracy of the approximation decreases as the function becomes more complex or has a larger range of values.

Replies
1
Views
2K
Replies
8
Views
2K
Replies
2
Views
478
Replies
1
Views
951
Replies
6
Views
7K
Replies
1
Views
642
Replies
12
Views
3K
Replies
1
Views
1K
Replies
6
Views
1K
Replies
1
Views
2K