fourier series of this function

조회 수: 1 (최근 30일)
HADIMARGO
HADIMARGO 2019년 6월 27일
댓글: HADIMARGO 2019년 6월 28일
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
infinity
infinity 2019년 6월 27일
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 2019년 6월 28일
i tryid but cannot find the correct code.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by