Fourier Series Expansion Graph Help

1 回表示 (過去 30 日間)
Kevin Krone
Kevin Krone 2019 年 10 月 8 日
回答済み: Star Strider 2019 年 10 月 8 日
So I am building the code to perform a Fourier Series Expansion, specifically for the function e^(-x) for the domain of 0=<x<2.
My graph looks like this, I don't know how well you will be able to see it, but in essence my function e^(-x) starts at the beginning of the domain and not at 0.
If anybody knows how I can get the function to start at zero, any help would be appreciated.
syms x n s
f = exp(-x);
L = input('Please enter a value for the domain ');
max = input('Please enter a value for n ');
X= 0:.01:L;
Ao = (1/L) * int(f,x,-L,L);
An = (2/L) * int((f*cos(2*pi*n*x/L)),x,-L, L);
Bn = (2/L) * int((f*sin(2*pi*n*x/L)),x,-L, L);
A = An * cos(2*pi*n*x/L);
B = Bn * sin(2*pi*n*x/L);
s = Ao;
for N = 1:max
s = s + subs(A,n,N) + subs(B,n,N);
end
figure
fplot(s,[-L L])
hold on
fplot(f,[-L L])

採用された回答

Star Strider
Star Strider 2019 年 10 月 8 日
If you want to plot them beginning at 0, remember to tell fplot:
figure
fplot(s,[0 L])
hold on
fplot(f,[0 L])
That will start them both at 0.

その他の回答 (0 件)

カテゴリ

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