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