Fourier Series using MATLAB

5 vues (au cours des 30 derniers jours)
MathWizardry
MathWizardry le 11 Mai 2021
Réponse apportée : Paul le 11 Mai 2021
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.

Réponses (1)

Paul
Paul le 11 Mai 2021
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.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by