How to plot Fourier series with 100 terms ?

2 views (last 30 days)
I'm trying to plot the attached Fourier series for 100 terms but the plot shows values reaching 40 when I'm expecting maximum values to be around 4. This is what I've managed so far. I would appreciate if someone could help me understand where I'm going wrong
t=-pi:pi/10:pi;
vt=zeros(1,length(t));
for m=1:1:2;
bm=(8/m*pi)*(1-cos(m*pi/2))
vt= vt + bm*sin(m*t);
end
plot(t,vt)
  1 Comment
Korosh Agha Mohammad Ghasemi
clear all;clc;
syms x
pi=3.14;
sum=0;
y=exp(x); %function you want
a0=(1/pi)*int(y,x,-pi,pi);
for n=1:3
%finding the coefficients
an=(1/pi)*int(y*cos(n*x),x,-pi,pi);
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi);
sum=sum+(an*cos(n*x)+bn*sin(n*x));
end
% https://www.instagram.com/koroshkorosh1/
ezplot(x,y,[-pi,pi]);
grid on;hold on;
ezplot(x,(sum+a0/2),[-pi,pi]);
% https://www.instagram.com/koroshkorosh1/

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 27 Oct 2018
Edited: Bruno Luong on 27 Oct 2018
for m=1:1:2;
And you think this makes 100 terms??
Then
bm=(8/m*pi)*(1-cos(m*pi/2))
So you multiply by pi? Look like you need to concentrate on the parenthesis:
bm=8/(m*pi)*(1-cos(m*pi/2));
  1 Comment
Korosh Agha Mohammad Ghasemi
clear all;clc;
syms x
pi=3.14;
sum=0;
y=exp(x); %function you want
a0=(1/pi)*int(y,x,-pi,pi);
for n=1:3
%finding the coefficients
an=(1/pi)*int(y*cos(n*x),x,-pi,pi);
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi);
sum=sum+(an*cos(n*x)+bn*sin(n*x));
end
% https://www.instagram.com/koroshkorosh1/
ezplot(x,y,[-pi,pi]);
grid on;hold on;
ezplot(x,(sum+a0/2),[-pi,pi]);
% https://www.instagram.com/koroshkorosh1/

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!