Fourier Series Solution 13.5.11

a=3
f[x_]=x (x-a)

A[j_,x_]=Sin[j Pi x/a]

bj[j_]=(2/a)  Integrate[ f[x] A[j,x],{x,0,a}]

B[j_,y_]=bj[j] E^(- j Pi y/a)

u[x_,y_,k_]:=Sum[A[j,x] B[j,y],{j,1,k}]

Plot[{f[x],u[x,0,10]},{x,0,a}]

Plot[{f[x],u[x,0,10]},{x,-2 a,2 a}]

Plot3D[u[x,y,10],{x,0,a},{y,0,1},PlotRange->All]

Animate[Plot[u[x,y,10],{x,0,a},PlotRange->{-2.5,0}],{y,0,3}]

Compare to heat equation

HB[j_,t_]=bj[j] E^(-Sqrt[ j Pi/a] t)

hu[x_,t_,k_]:=Sum[A[j,x] HB[j,t],{j,1,k}]

Plot3D[hu[x,t,10],{x,0,a},{t,0,1},PlotRange->All]

Animate[Plot[hu[x,t,10],{x,0,a},PlotRange->{-2.5,0}],{t,0,3}]

Animate[Plot[{u[x,t,10],hu[x,t,10]},{x,0,a},PlotRange->{-2.5,0}],{t,0,3}]

Animate[Plot[{u[x,t,10],hu[x,t,10]},{x,0,a/10},PlotRange->{-0.5,0}],{t,0,3}]