calculating fourier series for the given functions and drawing the curve?

6 ビュー (過去 30 日間)
sina
sina 2014 年 9 月 24 日
回答済み: VBBV 2024 年 9 月 17 日
hey guys, one of my friends has just given me a question.I wrote the code for it but don't know how to draw the chart or curve for that,would you please help me out...??thanks
here's the code: clc syms x f=exp(-abs(x)); N=15; a_0=(1/pi)*int(f*cos(0*x),-pi,pi) for n=1:N a_n(n)=(1/pi)*int(f*cos(n*x),-pi,pi); b_n(n)=(1/pi)*int(f*sin(n*x),-pi,pi); end a_n b_n f_new=a_0/2; for n=1:N f_new=f_new+a_n(n)*cos(n*x)+b_n(n)*sin(n*x); end

回答 (1 件)

VBBV
VBBV 2024 年 9 月 17 日
clear
syms x
N=[5 15 30];
f1=exp(-abs(x));
a_01=(1/pi)*int(f1.*cos(0*x),x,-pi,pi);
f_new10=vpa(a_01/2)
f2=exp(-(x));
a_02=(1/pi)*int(f2.*cos(0*x),x,-2,1);
f_new20=vpa(a_02/2)
f3 = -2*x.^2;
a_03=(1/pi)*int(f3.*cos(0*x),x,1,2);
f_new30=vpa(a_03/2)
f4 = 4;
a_04=(1/pi)*int(f4.*cos(0*x),x,2,pi);
f_new40=vpa(a_04/2)
X = linspace(-pi,pi,100);
for k = 1:length(X)
for n=1:N(2)
a_n1(n)=(1/pi)*int(f1.*cos(n*x),x,-pi,pi);
b_n1(n)=(1/pi)*int(f1.*sin(n*x),x,-pi,pi);
f_new1(n,k)=f_new10+a_n1(n).*cos(n*X(k))+b_n1(n).*sin(n*X(k));
a_n2(n)=(1/pi)*int(f2.*cos(n*x),x,-2,1);
b_n2(n)=(1/pi)*int(f2.*sin(n*x),x,-2,1);
f_new2(n,k)=f_new20+a_n2(n).*cos(n*X(k))+b_n2(n).*sin(n*X(k));
a_n3(n)=(1/pi)*int(f3.*cos(n*x),x,1,2);
b_n3(n)=(1/pi)*int(f3.*sin(n*x),x,1,2);
f_new3(n,k)=f_new30+a_n3(n).*cos(n*X(k))+b_n3(n).*sin(n*X(k));
a_n4(n)=(1/pi)*int(f4.*cos(n*x),x,2,pi);
b_n4(n)=(1/pi)*int(f4.*sin(n*x),x,2,pi);
f_new4(n,k)=f_new40+a_n4(n).*cos(n*X(k))+b_n4(n).*sin(n*X(k));
end
F_new(k) = sum(f_new1(:,k)); % similarly do it for remaining functions
end
plot(F_new)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by