How to plot Fourier series with 100 terms ?

5 vues (au cours des 30 derniers jours)
Sakusan Puwanendran
Sakusan Puwanendran le 27 Oct 2018
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 commentaire
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/

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 27 Oct 2018
Modifié(e) : Bruno Luong le 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 commentaire
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/

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by