Separation of Variables and 
Superposition (Plotting)

We have done a couple nominally pretty interesting things:

1. We have expressed a given function in terms of a Fourier series on a particular interval of interest, and 
2. Using the Fourier representation of a function we have expressed the solution of an initial/boundary value problem (for example)

u_t  = k u_{xx} on (0,L) X (0,T)
u_x(0,t) = 0 = u_x(L,t), t > 0 
u(x,0) = g(x)

for the 1-D heat equation as a Fourier series/superposition of separated variables solutions.  

Of course, maybe it is still a little unclear what it means to “represent” a function by a Fourier series.  We know, at any rate, how to formally write down a Fourier series associated with a function.  Similarly, we obtain a series we can at least imagine is associated with a solution.  

Here we carry out the details of these constructions and produce some plots which should encourage us that our construction is making some sense.  In order to make some plots, we will need to make some choices.  In particular, we will need to choose the length value L and the initial temperature distribution g=g(x).   Since Mathematica tends to use capital letters for standard functions, we will denote the right endpoint of the interval by b.  Here are our choices:

g[x_]=E^x;
b = 0.5;

We will also need to choose a conductivity k.  We can take k = 1, and free the symbol “k” to be used as an index for partial sums below.

Plot[g[x],{x,-1,1},AxesOrigin->{0,0}]

In our solution of the PDE we found the expansion of g near the end of our analysis.  We will do it here first.  We recall that the appropriate Fourier basis for the problem with insulated endpoints is 1, Cos[Pi x/L], Cos[2 Pi x/L],... and the coefficients are given by

azero=Integrate[g[x],{x,0,b}]/b

a[j_]=2 Integrate[g[x] Cos[j Pi x/b],{x,0,b}]/b

Consequently, we can write a partial sum of the Fourier series associated with g = g(x) as

gseries[x_,k_]=azero+Sum[a[j] Cos[j Pi x/b],{j,1,k}]

Plot[{g[x],gseries[x,1],gseries[x,5]},{x,-1,1},AxesOrigin->{0,0}]

Plot[{gseries[x,10],gPlot[{g[x],gseries[x,1],gseries[x,5]},{x,-1,1},AxesOrigin->{0,0}][x]},{x,-1,1},AxesOrigin->{0,0}]

Notice that 11 terms gives a pretty good approximation on the interval of interest.

The solution was then supposed to be given by

useries[x_,t_,k_] := azero+Sum[a[j] E^{-j^2 Pi^2 t/b^2} Cos[j Pi x/b],{j,1,k}]

Note that Mathematica sometimes has trouble with evaluation of partial sums like this, so I’ve put in a colon (:) so that the evaluation won’t be made until k is a specific integer.

Plot3D[useries[x,t,10],{x,0,b},{t,0,0.05},ViewPoint->{1.3, 2.4, 2.}]

Plot[useries[x,0,10],{x,0,0.5},AxesOrigin->{0,0}]

Plot[useries[x,0.01,10],{x,0,0.5},AxesOrigin->{0,0}]

Animate[Plot[useries[x,t,20],{x,0,0.5},AxesOrigin->{0,0},PlotRange->{0,1.6}],{t,0,0.05}]

There seems to be some computational trouble between t=0.04 and t=0.05.  Note that the limiting (constant) value should be azero = 1.29744, which seems to be what we see.  Note also that the initial temperature distribution g = g(x) does not satisfy the zero flux conditions at the endpoints (insulated ends), but these conditions are apparently obtained for all t > 0 
in the series solution.