The PDE is \[ \frac {\partial T\left ( x,t\right ) }{\partial t}=k\frac {\partial ^{2}T\left ( x,t\right ) }{\partial x^{2}} \] Problem: given a bar of length \(L\) , solve the above 1-D heat PDE for 4 different boundary/initial condition to show that the solution depends on these.
Mathematica
Clear[y,x,t,k]; SetDirectory[NotebookDirectory[]]; barLength = 4*Pi; timeDuration = 10; eq = D[y[x, t], t] == k*D[y[x, t], x, x]; eq = eq /. k -> 0.5; solveHeat[eq_,bc_,ic_,y_,x_,t_,len_,timeDuration_]:=Module[{sol}, sol=First@NDSolve[{eq,bc,ic},y[x,t],{x,0,len},{t,0,timeDuration}]; Plot3D[y[x,t]/.sol,{x,0,barLength},{t,0,timeDuration}, PlotPoints->30,PlotRange->All,AxesLabel->{"x","time","y[x,t]"}, ImageSize->200,PlotLabel->bc] ]; bc={{y[0,t]==1,y[barLength,t]==1}, {y[0,t]==0,y[barLength,t]==0}, {y[0,t]==1,y[barLength,t]==Exp[-t barLength]}, {y[0,t]==0,y[barLength,t]==0} }; ic={y[x,0]== Cos[x], y[x,0]==Sin[x], y[x,0]==1, y[x,0]== Cos[x]Sin[x] }; sol = MapThread[solveHeat[eq,#1,#2,y,x,t,barLength ,timeDuration]&,{bc,ic}]; Grid[Partition[sol,2],Frame->All] Export["images/mma_e58_1.pdf",%]
Each plot shows the boundary conditions used.