fourier series of this function

1 vue (au cours des 30 derniers jours)
HADIMARGO
HADIMARGO le 27 Juin 2019
Commenté : HADIMARGO le 28 Juin 2019
i want the fourier seris of function:
my code:
clear all
clc
syms x
f=(x+2).*(x>-2)-(x+2).*(x>-1)+(1).*(x<=1)-(1).*(x<=-1)+(2-x).*(x>1)-(2-x).*(x>=2);
N=10;
a_0=(1/pi)*int(f*cos(0*x),-pi,pi)
for n=1:N
a_n(n)=(1/pi)*int(f*cos(n*x),-pi,pi);
b_n(n)=(1/pi)*int(f*sin(n*x),-pi,pi);
end
a_n
b_n
f_new=a_0/2;
for n=1:N
f_new=f_new+a_n(n)*cos(n*x)+b_n(n)*sin(n*x);
end
subs(f_new,x,5)
subs(f,x,5)
the error:
Error using symengine
Invalid integrand.
Error in sym/int (line 162)
rSym = mupadmex('symobj::intdef',f.s,x.s,a.s,b.s,options);
Error in Untitled3 (line 7)
a_0=(1/pi)*int(f*cos(0*x),-pi,pi)
my function:
Untitled-2.jpg
  2 commentaires
infinity
infinity le 27 Juin 2019
Hello,
It is seen that the function "f" is not easy for Matlab to find it intergrand by using the fucntion "int". Maybe, you should try to split the piecewise function "f" into some small intervals, for example, [0, -2], [-2, -1], [-1, 1], .... Then, you can get the integral over these intervals.
HADIMARGO
HADIMARGO le 28 Juin 2019
i tryid but cannot find the correct code.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering 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