How to plot Fourier series with 100 terms ?

조회 수: 5 (최근 30일)
Sakusan Puwanendran
Sakusan Puwanendran 2018년 10월 27일
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
Korosh Agha Mohammad Ghasemi
Korosh Agha Mohammad Ghasemi 2020년 9월 22일
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/

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2018년 10월 27일
편집: Bruno Luong 2018년 10월 27일
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
Korosh Agha Mohammad Ghasemi
Korosh Agha Mohammad Ghasemi 2020년 9월 22일
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/

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by