Fourier Series Aproximation
M.M. Yovanovich
FOURSERIES1.MWS
Fourier series approximation of a periodic function.
Plot the function and approximations based on 2,4,6,8,10 and 12 terms of the Fourier series.
> restart:
Function.
>
f:= proc(x) if x>=0 and x<1 then 1
elif x<0 and x>=-1 then -x
elif x>=1 then f(x-2) fi
end:
> plot('f(x)', 'x'=-1..5);
Fourier coefficients.
>
f1:= x->-x:
f2:= x->1:
>
a:= table():
a[0]:= evalf(1/2*(int(f1(x),x=-1..0) +
int(f2(x),x=0..1))):
>
for j from 1 to 12 do
a[j]:= evalf(Int(f1(x)*cos(j*Pi*x),x =-1..0) +
Int(f2(x)*cos(j*Pi*x), x=0..1)) od:
>
b:= table():
for j from 1 to 12 do
b[j]:= evalf(Int(f1(x)*sin(j*Pi*x), x = -1..0) +
Int(f2(x)*sin(j*Pi*x), x = 0..1)) od:
Fourier coefficients values.
> [seq(a[j], j = 1..12)];
> [seq(b[j], j = 1..12)];
kth term of the Fourier series for L = 1.
> kterm:= k-> a[k]*cos(k*Pi*x) + b[k]*sin(k*Pi*x);
Approximation of the function with n terms of the series.
> fapp:= n-> a[0] + sum(kterm(i), i = 1..n);
Two term approximation.
> fapp(2);
Create several plots of the function and the approximations for
terms of the series.
>
for j from 2 by 2 to 12 do
plot({'f(x)', fapp(j)}, x = -1..5,
numpoints=150)
od;
>