Fourier Series using MATLAB

7 ビュー (過去 30 日間)
MathWizardry
MathWizardry 2021 年 5 月 11 日
回答済み: Paul 2021 年 5 月 11 日
MATLAB CODE:
syms x
n=1:1;
k=1*n;
L=pi;
f1(x)=piecewise(x>pi&<0,-x-pi;x>0&<pi,x+i);
a1=int(f1(x),x,-L,L);
a0=a1/(2*pi);
ak=it(f1(x)*cos(k*x),x,-L,L);
bk=int(f1(x)*sin(k*x),x,-L,L);
a=ak/pi;
b=bk/pi;
F1=a0+sum(a.*(cos(k*pix/L))+b.*(sin(k*pi*x/L)));
please correct my codes.
it says that:
f1(x)=piecewise(x>pi&<0,-x-pi;x>0&<pi,x+i);
Invalid use of operator.

回答 (1 件)

Paul
Paul 2021 年 5 月 11 日
You probably want
f1(x) = piecewise(x < -sym(pi), 0,x < 0,-x-sym(pi), x<=sym(pi), x+sym(pi), x>sym(pi), 0);
You'll find some other typos in your code, like using "it" instead of "int" in the equation for ak and pix instead of pi*x in the equation for F1.
Recommend defining
syms L
L = sym(pi)
and then use L everywhere instead of pi.

カテゴリ

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