Borrar filtros
Borrar filtros

fourier series of this function

2 visualizaciones (últimos 30 días)
HADIMARGO
HADIMARGO el 27 de Jun. de 2019
Comentada: HADIMARGO el 28 de Jun. de 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 comentarios
infinity
infinity el 27 de Jun. de 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 el 28 de Jun. de 2019
i tryid but cannot find the correct code.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by