Cooling Rod Example

Approximate solution to PDE

u[t_,x_,M_]:=4/π*Sum[(-1)^(n+1)/(2*n-1)^2*Exp[-(2*n-1)^2*t]*Sin[(2*n-1)*x],{n,1,M}]

Plotting at Different Times

Plot[{u[0,x,10],u[1,x,10],u[2,x,10]},{x,-π,π},PlotStyle->Thick,AxesLabel->{"x","u(t,x)"},LabelStyle->Directive[Black, Large],PlotRange->{-5,4}]

DensityPlot[u[t,x,10],{x,-π,π},{t,0,2},PlotLegends->Automatic]

Animate[Plot[u[t,x,5],{x,-π,π},PlotRange->{-4,4},PlotStyle->Thick,AxesLabel->{"x","u(t,x)"},LabelStyle->Directive[Black, Large]],{t,0,3},AnimationRunning->False]