Fourier Series using MATLAB

2 次查看(过去 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 CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by