Heat Equation - Dirichlet BC: 
(Subscript[u, t])=k (Subscript[u, xx]) with u[0,t]=u[L,t]=0

Our first example is the classic considered by Fourier 
Théorie de la Chaleur, 1822.  Available (in French) at
http://www.proba.jussieu.fr/~mazliak/Fourier_1822.pdf

Big picture: words

We look for special solutions of the form u[x,t]=ϕ[x]G[t] by plugging this ansatz into the PDE and BC and separating the variables.

We argue that the two parts of the separated equation have to equal the same constant λ.

Solving the “x” ODE for ϕ[x] and satisfying the BC gives a discrete set of separation constants λ.

Plugging those values for λ into the “t” ODE for G[t] gives the time dependence for each of the special solutions.

Weighted sums of these special solutions are also solutions since the PDE is linear.

Turns out the weighted sums are sufficiently general that every solution can be represented in that form.

The time dependence of the weighted sums gives us really interesting information about the solutions.

Big picture: Eqs

u[x,t]=ϕ[x]G[t]

ϕ[x]G'[t]==k ϕ''[x]G[t]

((G'[t])/(k G[t]))==((ϕ''[x])/(ϕ[x]))==-λ

G'[t]==-λ k G[t] and ϕ''[x]==-λ ϕ[x]

ϕ''[x]==-λ ϕ[x]  and ϕ[0]==ϕ[L]==0

G'[t]==-λ k G[t]  and G[0]==1

ϕ''[x]==-λ ϕ[x]  and ϕ[0]==ϕ[L]==0

λ=(ω^2)>0:  ϕ''[x]+(ω^2)ϕ[x]==0 
⟹ϕ[x]=(Subscript[C, 1])Sin[ω x]+(Subscript[C, 2])Cos[ω x]

ϕ[x]=(Subscript[C, 1])Sin[ω x]+(Subscript[C, 2])Cos[ω x]  and ϕ[0]==ϕ[L]==0

({{(Subscript[C, 1])*0, +, (Subscript[C, 2])*1, =, 0}, {(Subscript[C, 1])*Sin[ω L], +, (Subscript[C, 2])*Cos[ω L], =, 0}})

⟹(Subscript[C, 2])=0 and either (Subscript[C, 1])=0 or Sin[ω L]=0

λ=0:  ϕ''[x]==0 
⟹ϕ[x]=(Subscript[C, 1])+(Subscript[C, 2])x

ϕ[x]=(Subscript[C, 1])+(Subscript[C, 2])x  and ϕ[0]==ϕ[L]==0

({{(Subscript[C, 1])*1, +, (Subscript[C, 2])*0, =, 0}, {(Subscript[C, 1])*1, +, (Subscript[C, 2])*L, =, 0}})

⟹(Subscript[C, 1])=0 and (Subscript[C, 2])=0.

λ=-(ω^2)<0:  ϕ''[x]-(ω^2)ϕ[x]==0 
⟹ϕ[x]=(Subscript[C, 1])(e^(ω x))+(Subscript[C, 2]) (e^(-ω x))

ϕ[x]=(Subscript[C, 1])(e^(ω x))+(Subscript[C, 2])(e^(-ω x))  and ϕ[0]==ϕ[L]==0

({{(Subscript[C, 1])*1, +, (Subscript[C, 2])*1, =, 0}, {(Subscript[C, 1])*(e^(ω L)), +, (Subscript[C, 2])*(e^(-ω L)), =, 0}})

⟹(Subscript[C, 1])=0 and (Subscript[C, 2])=0.

Only non-trivial solution is λ=(ω^2) where Sin[ω L]=0.

ω ∈{({{π/L, ,, 2π/L, ,, …, }}})

Define (Subscript[ω, n])=n π/L and (Subscript[λ, n])=((Subscript[ω, n])^2) and (Subscript[ϕ, n])[x]=Sin[(Subscript[ω, n])x]

Go back to the “t” ODE for G[t].

(Subscript[G, n])'[t]==-k (Subscript[λ, n]) (Subscript[G, n])[t]⟹(Subscript[G, n])[t]=(Subscript[C, 3])(e^(-(Subscript[λ, n])k t))

(Subscript[G, n])[0]==1 gives (Subscript[C, 3])=1.

Define (Subscript[G, n])[t]=(e^(-(Subscript[λ, n])k t)).

Define (Subscript[u, n])[x,t]=(Subscript[ϕ, n])[x](Subscript[G, n])[t].

Our solns are ∑ (Subscript[b, n])(Subscript[u, n])[x,t]

Big picture: Each Special Solutions

Look at each of the special soutions we found.

L=2;
TMax=1;
u[n_][x_,t_]:= (E^(-(((((n π)/L)))^2)t))Sin[n π x/L]  
Manipulate[ 
Plot[ u[n][x,t],{x,0,L},
PlotLabel->StringForm["n=`` and t=``", n,t],
PlotRange->{-1,1},
AxesLabel->{"x",(Subscript["u", n])}],
{t,0, TMax},
{n,Range[1,5]}]

Look at them in a 3D pic

L=2;
TMax=1;
u[n_][x_,t_]:= (E^(-(((((n π)/L)))^2)t))Sin[n π x/L]  
Manipulate[ 
Plot3D[ u[n][x,t],{x,0,L},
{t,0, TMax},
PlotLabel->StringForm["n=``", n],
PlotRange->{-1,1},
AxesLabel->{"x","t",(Subscript["u", n])}],
{n,Range[1,5]}
]

L=2;
TMax=1;
u[n_][x_,t_]:= (E^(-(((((n π)/L)))^2)t))Sin[n π x/L]  
Manipulate[ 
ContourPlot[ u[n][x,t],{x,0,L},
{t,0, TMax},
Contours->10,
PlotLabel->StringForm["n=``", n],
PlotRange->{-1,1},
FrameLabel->{"x","t"}],
{n,Range[1,5]}
]

Big picture: Sums of Special solutions

L=2;
TMax=1;
u[n_][x_,t_]:= (E^(-(((((n π)/L)))^2)t))Sin[n π x/L]  

Manipulate[ 
Plot3D[
b[1]u[1][x,t]+b[2]u[2][x,t]+b[3]u[3][x,t]+b[4] u[4][x,t]+b[5]u[5][x,t],
{x,0,L},
{t,0, TMax},
PlotRange->{-4,4},
AxesLabel->{"x","t","u"}],
{{b[1],1},-2,2},
{{b[2],1},-2,2},
{{b[3],1},-2,2},
{{b[4],1},-2,2},
{{b[5],1},-2,2}
]

Easier to see what the intial condtion is.

L=2;
TMax=1;
u[n_][x_,t_]:= (E^(-(((((n π)/L)))^2)t))Sin[n π x/L]  

Manipulate[ 
Plot[
b[1]u[1][x,0]+b[2]u[2][x,0]+b[3]u[3][x,0]+b[4] u[4][x,0]+b[5]u[5][x,0],
{x,0,L},
PlotLabel->"IC: t=0",
PlotRange->{-4,4},
AxesLabel->{"x","t","u"}],
{{b[1],1},-2,2},
{{b[2],1},-2,2},
{{b[3],1},-2,2},
{{b[4],1},-2,2},
{{b[5],1},-2,2}
]

Of course what we want to be able to do is compute the values of (Subscript[b, 1]),(Subscript[b, 2]),… for a given IC u[x,0]=f[x].   Plugging t=0 into the special solutions shows that we want to make 
	({{(∑_(n=1)^∞)b[n]Sin[n π x/L], =, f[x]}})
The big question is what conditions on f allow us to compute this Fourier Sine Series?  A less obvious question is what does the equals sign mean in this formula!

Clear[n1,n2, L]
Integrate[ Sin[n1 π x/L] Sin[n1 π x/L] ,{x,0,L}]

L=3.2
n1=10;
n2=4 
Plot[ {Sin[n1 π x/L], Sin[n2 π x/L],Sin[n1 π x/L] Sin[n2 π x/L] }, {x, 0, L}]
Integrate[ Sin[n1 π x/L] Sin[n2 π x/L] ,{x,0,L}]

Fourier Sine Series

A Fourier Sine Series for f[x] defined on an interval 0<x<L is defined by the constants b[1], b[2],…
	({{(∑_(n=1)^∞)b[n]Sin[n π x/L], =, f[x]}})
It turns out provided you are prepared to be slightly flexible about what the “=” means that you can write down a Fourier Sine series for almost any function most folks can imagine.

The first thing to do is to see the structure underneath the construction.

Pretend you have ({{(∑_(n=1)^∞)b[n]Sin[n π x/L], =, f[x]}}).

Multiply both sides by Sin[π x/L]

({{(∑_(n=1)^∞)b[n]Sin[n π x/L] Sin[π x/L], =, f[x]}})Sin[π x/L]

Integrate from 0<x<L.

({{(∑_(n=1)^∞)b[n](∫_0^L)Sin[n π x/L] Sin[π x/L]dx, =, (∫_0^L)f[x] Sin[π x/L]dx}})

The Sin*Sin integrals are computable and simple.

If n≠1 (∫_0^L)Sin[n π x/L] Sin[π x/L]dx=0

(∫_0^L)Sin[π x/L] Sin[π x/L]dx=L/2

Simplify and solve for b[1]

({{b[1], =, (2/L)(∫_0^L)f[x] Sin[π x/L]dx}})

Multiply both sides by Sin[2π x/L]

({{(∑_(n=1)^∞)b[n]Sin[n π x/L] Sin[2π x/L], =, f[x]}})Sin[2π x/L]

Integrate from 0<x<L.

({{(∑_(n=1)^∞)b[n](∫_0^L)Sin[n π x/L] Sin[2π x/L]dx, =, (∫_0^L)f[x] Sin[2π x/L]dx}})

The Sin*Sin integrals are computable and simple.

If n≠2 (∫_0^L)Sin[n π x/L] Sin[2π x/L]dx=0

(∫_0^L)Sin[2π x/L] Sin[2π x/L]dx=L/2

Simplify and solve for b[2]

({{b[2], =, (2/L)(∫_0^L)f[x] Sin[2π x/L]dx}})

Multiply both sides by Sin[3π x/L] …

What you wind up with is a simple formula
	b[n]=(2/L)(∫_0^L)f[x] Sin[nπ x/L]dx
Lets be carefull, we have shown that:

If f[x] has a Fourier Sine series; and
It is OK to switch the order of integration and summation; and
Everything converges then b[n] has to be given above.

L=2;
nMax=12;
f[x_]:=(x^5)
Do[
b[n]=NIntegrate[Sin[n π x/L] f[x],{x,0, L}],
{n, 1,nMax}]
Manipulate[
Plot[ 
{f[x], Sum[b[n] Sin[n π x /L],{n,1, nn}]},
{x, -1.5 L, 1.5 L}
],
{{nn,4},Range[1,nMax]}]