ClearAll["Global`*"]

1D Unsteady Heat Equation

In class, we solved this problem by hand. The answer is copied below:

lim=200;t1=1 (10^(-5));t2=0.05;t3=50; (* choose a few times to plot... *)
Θ[x_,t_]=x+(2/π) (∑_(n=1)^lim)((((-1))^n)/n) (E^(-(n^2)(π^2)t)) Sin[n π x];

Don’t forget that this solution is the non-dimensionalized solution. After obtaining the answer, you’d need to reconvert the x into a real position, the time into a real time, and the function Θ into a real temperature.

plot1=Plot[Θ[x,t1],{x,0,1.0},PlotStyle->Directive[RGBColor[1,0,0],AbsoluteThickness[2]],PlotRange-> {0,1.0}]//Quiet ;(*Red*)
plot2=Plot[Θ[x,t2],{x,0,1.0},PlotStyle->Directive[RGBColor[0,0,1],AbsoluteThickness[2]],PlotRange-> {0,1.0}]//Quiet ; (*Blue*)
plot3=Plot[Θ[x,t3],{x,0,1.0},PlotStyle->Directive[RGBColor[0,.67,0],AbsoluteThickness[2]],PlotRange-> {0,1.0}] //Quiet  ;(*Green*)

Legended[Show[plot1,plot2,plot3,ImageSize->{900,400},AspectRatio->0.7,AxesStyle->Black,FrameLabel->{"Position (SuperStar[x])","Temperature Θ"},Frame->True,FrameTicks->All,PlotRange-> {0,1.0},BaseStyle->{12,FontFamily->"Helvetica"}],Placed[LineLegend[{Red,Blue,Darker[Green]},{Style["Initial",12],Style["Intermediate",12],Style["Final",12]},LegendMargins->{{15,15},{5,5}},LabelStyle->Directive[{Bold}],LegendFunction->Framed],{{0.1,0.6},{0,0}}]]

We can also make an interactive plot control for time using the “Manipulate” command. I’m repeating the function definition (and making a smaller “lim” value) in the interest of making this plot update fast enough to see.

ClearAll["Global`*"]
lim=100;
Θ[x_,t_]=x+(2/π) (∑_(n=1)^lim)((((-1))^n)/n) (E^(-(n^2)(π^2)t)) Sin[n π x];dt = 0.0001;
Manipulate[Plot[Θ[x,t],{x,0,1},PlotRange->{{0,1},{0,1}},PlotStyle->Directive[RGBColor[1,0,0],AbsoluteThickness[2]],ImageSize->{900,400},AspectRatio->0.7,Frame-> True,LabelStyle->Directive[{Bold,Medium}],FrameLabel->{"Position (SuperStar[x])","Temperature Θ"}],{t,dt,1.00,dt}]//Quiet