#To find fourier series
f = abs(cos(x))
c(x) = 0
s(x) = 0
a0 = integrate(f,(x,-pi,pi))
g(x) = a0
for n in range(1,5):
    an = integrate((2*f(x)*cos((n*pi*x)/pi))/pi, (x,-pi,pi))                          #Even Periodic Extension
    bn = integrate((2*f(x)*sin((n*pi*x)/pi))/pi, (x,-pi,pi))                          #Odd  Periodic Extension
    
    c(x) = c(x) + an*cos((n*pi*x)/pi)
    s(x) = s(x) + bn*sin((n*pi*x)/pi)
    g(x) = g(x) + c(x) + s(x)

print 'Fourier Series is '
print g(x),
print "+..."

* Solution by:

Kreyszig-10Review-23-U (last edited 2010-12-18 12:35:13 by ArnabBasu)