An intro to Fourier series

via the solution of the heat problem

Fourier series originally arose as the solution of the heat problem:

(Subscript[u, t])=k (Subscript[u, x x])
u(0,t)=0=u(L,t)
u(x,0)=f(x).

Fourier’s solution in 1822 is a seminal moment in mathematics

The most basic, finite combination

If the initial condition f happens to be a linear combination of functions of the form sin(n π x/L), then it’s easy to verify that the solution is the corresponding linear combination of functions of the form

(Subscript[u, n])(x,t)=(e^(-k (n^2)(π^2)t/(L^2)))sin(n π x/L).

For the remainder today, we will take the diffusitivity k=1 and the length L=π. For example, if we want to solve

(Subscript[u, t])=(Subscript[u, x x])
u(0,t)=0=u(π,t)
u(x,0)=2sin(x)+(1/5)sin(2x)-(1/10)sin(3x),

we take

u(x,t)=2(e^(-t))+(1/5)(e^(-4t))sin(2x)-(1/10)(e^(-9t))sin(3x).

We can visualize this like so:

Animate[
Plot[{
2Sin[x]+3Sin[2x]-5Sin[3x],
2(E^(-t))Sin[x]+(E^(-4t))Sin[2x]3-(E^(-9t))5Sin[3x]
}, {x,0,Pi}], {t,0,2}]

The infinite expansion

If, on the other hand, f is more arbitrary, perhaps we could write

u(x,t)=(∑_(n=1)^∞)(Subscript[a, n])(e^(-(n^2)t))sin(n x),

where the (Subscript[a, n])s are carefully chosen so that

u(x,0)=(∑_(n=1)^∞)(Subscript[a, n])sin(n x)=f(x).

The (Subscript[a, n])s, it turns out, should be chosen to be

(Subscript[a, n])=(2/π)(∫_0^π)f(x)sin(n x)dx.

Why's that?

Suppose that

f(x)=(∑_(n=1)^∞)(Subscript[a, n])sin(n x).

Then multiplying both sides by sin(m x) and integrating we find that

(∫_0^π)f(x)sin(m x)dx=(∫_0^π)(∑_(n=1)^∞)(Subscript[a, n])sin(n x)sin(m x)dx
=(∑_(n=1)^∞)(Subscript[a, n])(∫_0^π)sin(n x)sin(m x)dx=(Subscript[a, m])(∫_0^π)(sin^2)(m x)dx.

Solving for (Subscript[a, m]) and replacing the dummy variable m with n yields the formula.

Note that we used two important integration formulae that are easy to verify with Mathematica.

FullSimplify[
(∫_0^π)((Sin[n*x])^2)\[DifferentialD]x,
Assumptions -> n∈Integers]

FullSimplify[
(∫_0^π)Sin[m*x]Sin[n*x]\[DifferentialD]x,
Assumptions -> {m∈Integers,n∈Integers}]

The integrals are actually very easy to compute using the identity.

TrigReduce[Sin[m*x]Sin[n*x]]

An example

Now, lets take f(x)=x over our bar of length π and diffusitivity 1.  Thus, our heat problem is

(Subscript[u, t])=(Subscript[u, x x])
u(0,t)=0=u(π,t)
u(x,0)=x.

The solution should be

u(x,t)=(∑_(n=1)^∞)(Subscript[a, n])(e^(-(n^2)t))sin(n x),

where the (Subscript[a, n])s are chosen so that

u(x,0)=(∑_(n=1)^∞)(Subscript[a, n])sin(n x)=x.

Thus, the (Subscript[a, n])s should be

(Subscript[a, n])=(2/π)(∫_0^π)x sin(n x)dx.

We might do this integral by parts, or with Mathematica.

FullSimplify[
(2/π)(∫_0^π)x*Sin[n*x]\[DifferentialD]x,
Assumptions -> {n∈Integers}]

Either way, the solution is

u(x,t)=(∑_(n=1)^∞)(((-1))^(n+1))(2/n)(e^(-(n^2)t))sin(n x).

Visualization

Here’s an illustration of the approximation to the inital condition via Fourier series.

Manipulate[
Plot[{x,Sum[2((((-1))^(n+1))/n)Sin[n*x],{n,1,m}]},
{x,-4,4},PlotRange -> 4],{m,1,100,1}]

Here's an animation of the solution.

Manipulate[
Plot[{x,2 (∑_(n=1)^200)((((-1))^(n+1))/n)(E^(-(n^2)t))Sin[n*x]},{x,0,π},
PlotRange -> {-0.1,3.5}],
{t,0,5}]