Fourier Series Expansions of Functions
Dr. M. Leigh Lunsford
In this worksheet we will examine the Fourier Series expansions of several functions.
Example 1 - A Piecewise Smooth Function
We first define our piecewise smooth function and plot it:
> restart:
>
g := x -> piecewise(x<=0,0, x<=3,x):
plot(g,-3..3, scaling=constrained, title="Plot of Piecewise Smooth Function g" );
Next we find the coeficients for the Fourier series:
The coefficients, , for the sine terms are given by the integral .
> assume(n,integer); bn := simplify((1/3)*int(g(x)*sin(n*Pi*x/3),x=-3..3));
and the coeffiecients for the cosine terms, , of the series are given by the integral .
and the coefficient is given by the integral .
> a0:=(1/6)*int(g(x),x=-3..3);
> an := simplify((1/3)*int(g(x)*cos(n*Pi*x/3),x=-3..3));
Let's compute a few of the partial sums of the series and plot them with the original function .
> u1 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..1):
> u2 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..2):
> u4 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..4):
> u10 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..10):
> u20 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..20):
Now we will plot each of these partial sums with the original function. We will plot the partial sums in red and the function in black. Examine the convergence of the series. Verify that the convergence theorems of Section 14.2 predict this behavior. What do you think is happening with the series outside the interval from to ? Also see if you can understand how the Gibss phenomenon is illustrated in these plots.
> plot([g(x),u1], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=1");
> plot([g(x),u2], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=2");
> plot([g(x),u4], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=4");
> plot([g(x),u10], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=10");
> plot([g(x),u20], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=20");
> plot(u20, x = -6..6, color=[black,red], scaling=constrained,title="Partial Sum for n=20");
>
Example 2 - Fourier Series of an Easy Odd Function ( )
> restart:
This is a more detailed example of the example you have in your text on pages 676 and 677. We will expand into its Fourier Series on the interval from to .
First we define the function and find its Fourier coefficients:
> f:=x->x;
Of course we know how this graph looks but we will plot it here for reference (and also for you to review the plot command)
> plot(f,-Pi..Pi,color=black, scaling=constrained);
Now we find the Fourier coefficients of . Since is odd we know that we will only have coefficients for the sine terms of the series.
>
q := (2/(Pi))*Int(f(x)*sin(n*Pi*x/Pi),x=0..Pi);
> assume(n,integer); b := combine(value(q),trig);
So, the Fourier Series looks like , where . Let's compute a few of the partial sums of the series and plot them with the original function .
> u1 := sum(b*sin(n*x),n=1..1):
> u2 := sum(b*sin(n*x),n=1..2):
> u3 := sum(b*sin(n*x),n=1..3):
> u4 := sum(b*sin(n*x),n=1..4):
> u10 := sum(b*sin(n*x),n=1..10):
> u20 := sum(b*sin(n*x),n=1..20):
> u30 := sum(b*sin(n*x),n=1..30):
> u40 := sum(b*sin(n*x),n=1..40):
Now we will plot each of these partial sums with the original function. We will plot the partial sums in red and the function in black. Examine the convergence of the series. Verify that the convergence theorems of Section 14.2 predict this behavior. What do you think is happening with the series outside the interval from to ? Also see if you can understand how the Gibss phenomenon is illustrated in these plots.
> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");
> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");
> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");
> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");
> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");
> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");
> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");
> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");
>
Example 3 - Fourier Sine and Cosine Series of a Discontinuous Function
We now look at a function where the function is no longer defined on an interval of the form to but instead on an interval of the form to . Here we will let and define our function below. This is essentially the same function use in Example 14.18 of your texton page 688.
> restart:
>
f := x -> piecewise(x<=0,0,x<=Pi/2,1, x<=Pi, 2):
> plot(f,0..Pi, scaling=constrained, title="Plot of Function f");
>
Now we find our Fourier sine and cosine series for this function:
Fourier Sine Series
We first compute the Fourier sine series of . The coefficients of this series are given by the integral .
> assume(n,integer); bn := simplify((2/(Pi))*int(f(x)*sin(n*Pi*x/Pi),x=0..Pi));
So, the Fourier Sine Series looks like . Let's compute a few of the partial sums of the series and plot them with the original function .
> u1 := sum(bn*sin(n*x),n=1..1):
> u2 := sum(bn*sin(n*x),n=1..2):
> u3 := sum(bn*sin(n*x),n=1..3):
> u4 := sum(bn*sin(n*x),n=1..4):
> u10 := sum(bn*sin(n*x),n=1..10):
> u20 := sum(bn*sin(n*x),n=1..20):
> u30 := sum(bn*sin(n*x),n=1..30):
> u40 := sum(bn*sin(n*x),n=1..40):
Notice in the plots below that I plotted over the interval to . (Why do you think I did this??)
> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");
> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");
> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");
> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");
> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");
> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");
> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");
> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");
>
Fourier Cosine Series
We next compute the Fourier cosine series of . The coefficients, , of this series are given by the integral and is given by the integral .
> an := simplify((2/(Pi))*int(f(x)*cos(n*Pi*x/Pi),x=0..Pi));
> a0:=simplify((1/(Pi))*int(f(x),x=0..Pi));
So, the Fourier Cosine Series looks like . Let's compute a few of the partial sums of the series and plot them with the original function .
> u1 := a0+sum(an*cos(n*x),n=1..1):
> u2 := a0+sum(an*cos(n*x),n=1..2):
> u3 := a0+sum(an*cos(n*x),n=1..3):
> u4 := a0+sum(an*cos(n*x),n=1..4):
> u10 := a0+sum(an*cos(n*x),n=1..10):
> u20 := a0+sum(an*cos(n*x),n=1..20):
> u30 := a0+sum(an*cos(n*x),n=1..30):
> u40 := a0+sum(an*cos(n*x),n=1..40):
Notice in the plots below that I plotted over the interval to . (Why do you think I did this??)
> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");
> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");
> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");
> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");
> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");
> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");
> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");
> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");
>
>
>