# Plotting Fourier Series Expansion

9 views (last 30 days)
Hanif on 9 Mar 2023
Commented: Hanif on 9 Mar 2023
I was given a problem of the Fourier series expansion of with a periodicity interval . I found that the Fourier series expansion of such function with given periodicity interval is . However, I am new to MATLAB and my knowledge is limited to simple plotting. Suppose that my answer is correct, how to subplot and its Fourier series expansion using loop that generates the n-order of the expansion? I searched in this community and actually find a really good plotting, but I don't understand how it works. Thanks in advance!
##### 2 CommentsShow 1 older commentHide 1 older comment
Hanif on 9 Mar 2023
I also want to share my attempt on this:
x = linspace(-10,10,100);
y = 1-(4*cos(x))/pi - (4*cos(3*x))/(9*pi) - (4*cos(5*x))/(25*pi);
plot(x,y,'r-');
Of course, it is very simple because I am new to MATLAB.

Paul on 9 Mar 2023
Hi Hanif,
Maybe this will help.
First, the problem statement says that one period spans -1 < x <= 1 (I don't think it matter if using < or <=)
x = linspace(-1,1,100);
Instead of using your problem, let's do something simpler, like 1 - 2*sum(n=1:5,n*x)
fsum = 0*x; % initialize
for n = 1:5
fsum = fsum + n*x;
end
plot(x,1-2*fsum)
I think you can adapt that to your problem. Of course we can't compute an infinite sum, so you'll have to pick an upper bound for the sum over n.
Hanif on 9 Mar 2023
I see. I actually tried to put the plot function into the loop, but it did not work because I forgot to put the hold-on command. As you also mentioned, I haven't check my derivation again, but I will do! Thank you for your helps, Paul.

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2022b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!