4.3 Fourier Approximations
In-class demo by Russell Blyth.
> restart:with(plots):
Warning, the name changecoords has been redefined
We use Maple to perform the tedious computations for us.
Verify that the functions used as basis vectors in the approximating subspace are orthogonal.
>
Int(sin(i*Pi*x)*sin(j*Pi*x),x=-1..1) = int(sin(i*Pi*x)*sin(j*Pi*x),x=-1..1);
Int(sin(i*Pi*x)*sin(i*Pi*x),x=-1..1) = int(sin(i*Pi*x)*sin(i*Pi*x),x=-1..1);
Int(sin(i*Pi*x)*cos(j*Pi*x),x=-1..1) = int(sin(i*Pi*x)*cos(j*Pi*x),x=-1..1);
Int(cos(i*Pi*x)*cos(j*Pi*x),x=-1..1) = int(cos(i*Pi*x)*cos(j*Pi*x),x=-1..1);
Int(cos(i*Pi*x)*cos(i*Pi*x),x=-1..1) = int(cos(i*Pi*x)*cos(i*Pi*x),x=-1..1);
That left us with some work still to do. Try again. This time we first tell Maple that i and j are integers (Maple assumes i and j are nonzero):
>
assume(i,integer): assume(j,integer):
interface(showassumed=0):
>
Int(sin(i*Pi*x)*sin(j*Pi*x),x=-1..1) = int(sin(i*Pi*x)*sin(j*Pi*x),x=-1..1);
Int(sin(i*Pi*x)*sin(i*Pi*x),x=-1..1) = int(sin(i*Pi*x)*sin(i*Pi*x),x=-1..1);
Int(sin(i*Pi*x)*cos(j*Pi*x),x=-1..1) = int(sin(i*Pi*x)*cos(j*Pi*x),x=-1..1);
Int(cos(i*Pi*x)*cos(j*Pi*x),x=-1..1) = int(cos(i*Pi*x)*cos(j*Pi*x),x=-1..1);
Int(cos(i*Pi*x)*cos(i*Pi*x),x=-1..1) = int(cos(i*Pi*x)*cos(i*Pi*x),x=-1..1);
We need to also integrate against 1:
>
Int(sin(i*Pi*x)*1,x=-1..1) = int(sin(i*Pi*x)*1,x=-1..1);
Int(cos(i*Pi*x)*1,x=-1..1) = int(cos(i*Pi*x)*1,x=-1..1);
Int(1*1,x=-1..1) = int(1*1,x=-1..1);
To compensate for this final integral, we must remember to half the coefficient of this function later.
Graph several of these integrals as a reality check:
> plot(sin(2*Pi*x)*sin(3*Pi*x),x=-1..1);
> plot(sin(3*Pi*x)*cos(4*Pi*x),x=-1..1);
> plot(cos(5*Pi*x)*cos(3*Pi*x),x=-1..1);
> plot(sin(3*Pi*x)*sin(3*Pi*x),x=-1..1);
Example
Find Fourier approximations for f(x) = x
We compute the Fourier coefficients for f(x) = x
>
Int(x*sin(j*Pi*x),x=-1..1) = int(x*sin(j*Pi*x),x=-1..1);
Int(x*cos(j*Pi*x),x=-1..1) = int(x*cos(j*Pi*x),x=-1..1);
Int(x,x=-1..1) = int(x,x=-1..1);
Note there are only sine terms (not surprising because f is an odd function).
Next use Maple to find a general expression for the order n approximation
>
Fapprox := (x,n) ->
sum(-2*(-1)^j/(j*Pi)*sin(j*Pi*x),j=1..n);
We can now plot (say) a 10 term approximation against the function.
>
eval(Fapprox(x,10));
plot([Fapprox(x,10),x],x=-2..2,y = -2..2,
title = " 10th Order Fourier approximation to y =x", titlefont = [HELVETICA,12], color = [green,blue]);
It is also useful to plot the error between the function and the approximation.
>
plot(Fapprox(x,10)-x,x=-1..1,y=-1..1,
title = "error in 10th Order Fourier approximation to y = x", titlefont = [HELVETICA,12], color = red);
Higher order approximations match the function f even more closely!
>
>