How to plot Fourier series with 100 terms ?
4 次查看(过去 30 天)
显示 更早的评论
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
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
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
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 Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!