2.4 Fourier series of periodic functions

If $ f(x)$ is a piecewise-defined polynomial function on $ -L<x<L$ then the Fourier series

$\displaystyle f(x) \sim \frac{a_0}{2} +
\sum_{n=1}^\infty \left[a_n\cos\left(\frac{n\pi x}{L}\right) + b_n\sin\left(\frac{n\pi x}{L}\right)\right]
$

converges. In addition to computing the coefficients $ a_n,b_n$ , it will also compute the partial sums (as a string), plot the partial sums (as a function of $ x$ over $ (-L,L)$ , for comparison with the plot of $ f(x)$ itself), compute the value of the FS at a point, and similar computations for the cosine series (if $ f(x)$ is even) and the sine series (if $ f(x)$ is odd). Also, it will plot the partial F.S. Cesaro mean sums (a ``smoother'' partial sum illustrating how the Gibbs phenomenon is mollified).

 
sage: f1 = lambda x: -1
sage: f2 = lambda x: 2
sage: f = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]])
sage: f.fourier_series_cosine_coefficient(5,pi)
-3/(5*pi)
sage: f.fourier_series_sine_coefficient(2,pi)
-3/pi
sage: f.fourier_series_partial_sum(3,pi)
-3*sin(2*x)/pi + sin(x)/pi - 3*cos(x)/pi + 1/4
Type show(f.plot_fourier_series_partial_sum(15,pi,-5,5)) and show(f.plot_fourier_series_partial_sum_cesaro(15,pi,-5,5)) (and be patient) to view the partial sums.

See About this document... for information on suggesting changes.