SetDirectory[StringJoin[$HomeDirectory,"/Documents/handouts/math467/HeatRectangularDomain"]]

Graphics[{EdgeForm[{Black,Thick}],Lighter[Gray],Rectangle[{0,0},{GoldenRatio,1}],Black,Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["u", "TI"], "(", 
RowBox[{
StyleBox["x", "TI"], ",", 
StyleBox["y", "TI"], ",", 
StyleBox["t", "TI"]}], ")"}], TraditionalForm], "errors" -> {}, "input" -> "u(x, y, t)", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{GoldenRatio,1}/2],Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["B", "TI"], 
SubscriptBox[
StyleBox["C", "TI"], "1"]}], TraditionalForm], "errors" -> {}, "input" -> "BC_{1}", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{-0.2,1}/2],Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["B", "TI"], 
SubscriptBox[
StyleBox["C", "TI"], "2"]}], TraditionalForm], "errors" -> {}, "input" -> "BC_{2}", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{GoldenRatio,-0.2}/2],Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["B", "TI"], 
SubscriptBox[
StyleBox["C", "TI"], "3"]}], TraditionalForm], "errors" -> {}, "input" -> "BC_{3}", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{2GoldenRatio+0.2,1}/2],Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["B", "TI"], 
SubscriptBox[
StyleBox["C", "TI"], "4"]}], TraditionalForm], "errors" -> {}, "input" -> "BC_{4}", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{GoldenRatio,2.2}/2],Text["\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["u", "TI"], 
RowBox[{"(", 
RowBox[{
StyleBox["x", "TI"], ",", 
StyleBox["y", "TI"], ",", "0"}], ")"}], "==", 
StyleBox["f", "TI"], 
RowBox[{"(", 
RowBox[{
StyleBox["x", "TI"], ",", 
StyleBox["y", "TI"]}], ")"}]}], TraditionalForm], "errors" -> {}, "input" -> "u(x, y, 0) = f(x, y)", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",{GoldenRatio,0.8}/2]},Axes->True,AxesLabel->{"\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["x", "TI"], TraditionalForm], "errors" -> {}, "input" -> "x", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)","\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["y", "TI"], TraditionalForm], "errors" -> {}, "input" -> "y", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)"},Ticks->{{{GoldenRatio,"\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["L", "TI"], TraditionalForm], "errors" -> {}, "input" -> "L", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)"}},{{1,"\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["M", "TI"], TraditionalForm], "errors" -> {}, "input" -> "M", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)"}}},BaseStyle->FontSize->12]

Export["Rect.eps",%,"EPS"]

Export["Rect.pdf",%%,"PDF"]

Example (Dirichlet Boundary Conditions)

DSolve[{D[u[x,y,t],t]==D[u[x,y,t],x,x]+D[u[x,y,t],y,y],u[0,y,t]==0,u[1,y,t]==0,u[x,0,t]==0,u[x,2,t]==0,u[x,y,0]==1000x(1-x)Sin[2π y]},u[x,y,t],{{x,0,1},{y,0,2},t}]

Integrate[((Sin[2π y])^2),{y,0,2}]

2Integrate[x(1-x)Sin[n π x],{x,0,1},Assumptions->{n∈Integers,n≥1}]

Clear[u,v,x,y,t]

u[x_,y_,t_]:=(8/(π^3))Sin[2π y](∑_(n=1)^40)((1/(((2n-1))^3))(E^(-(π^2)((((2n-1))^2)+4)t))Sin[(2n-1)π x])

D[u[x,y,t],t]==D[u[x,y,t],x,x]+D[u[x,y,t],y,y]//Simplify

u[0,y,t]

u[1,y,t]

u[x,0,t]

u[x,2,t]

nsoln=First[NDSolve[{D[v[x,y,t],t]==D[v[x,y,t],x,x]+D[v[x,y,t],y,y],v[0,y,t]==0,v[1,y,t]==0,v[x,0,t]==0,v[x,2,t]==0,v[x,y,0]==1000x(1-x)Sin[2π y]},v,{x,0,1},{y,0,2},{t,0,1/2}]]

ContourPlot[x(1-x)Sin[2π y],{x,0,1},{y,0,2},FrameLabel->{"x","y"},PlotRange->All,Contours->10]

ContourPlot[v[x,y,0.1]/.nsoln,{y,0,2},{x,0,1},FrameLabel->{"\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["y", "TI"], TraditionalForm], "errors" -> {}, "input" -> "y", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)","\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["x", "TI"], TraditionalForm], "errors" -> {}, "input" -> "x", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)"},PlotRange->All,Contours->Range[-1.5,1.5,0.3],AspectRatio->1/2,PlotLabel->"\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["t", "TI"], "==", "0.1"}], TraditionalForm], "errors" -> {}, "input" -> "t = 0.1", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",ContourLabels->Function[{x,y,z},Text[z,{x,y},Background->White]]]

Export["FSS2D.eps",%,"EPS"]

Export["FSS2D.pdf",%%,"PDF"]

ContourPlot3D[u[x,y,t],{x,0,1},{y,0,2},{t,0,1/3},AxesLabel->{"x","y","t"},PlotRange->{{0,1},{0,2},{0,1/3}},ContourStyle->{Opacity[0.5]},Mesh->False,BoxRatios->{1,2,1/3}]

SliceContourPlot3D[u[x,y,t],"ZStackedPlanes",{x,0,1},{y,0,2},{t,0,1/3},AxesLabel->{"x","y","t"},BoxRatios->{1,2,1/3},ContourShading->None,PlotTheme->"Monochrome"]

ContourPlot3D[u[x,y,t],{x,0,1},{y,0,2},{t,0,1/3},AxesLabel->{"x","y","t"},PlotRange->{{0,1},{0,2},{0,1/3}},ContourStyle->{Opacity[0.5]},Mesh->False,BoxRatios->{1,2,1/3},ColorFunction->(Lighter[GrayLevel[#]]&)]

ContourPlot3D[u[x,y,t],{x,0,1},{y,0,2},{t,0,1/3},AxesLabel->{"x","y","t"},PlotRange->{{0,1},{0,2},{0,1/3}},ContourStyle->{Opacity[0.5]},Mesh->False,BoxRatios->{1,2,1/3},PlotTheme->{"Monochrome"}]

Example (Mixed Boundary Conditions)

D[Sin[n π x]Cos[m π y],x,x]+D[Sin[n π x]Cos[m π y],y,y]

D[(E^(-(π^2)((n^2)+(m^2))t))Sin[n π x]Cos[m π y],x,x]+D[(E^(-(π^2)((n^2)+(m^2))t))Sin[n π x]Cos[m π y],y,y]-D[(E^(-(π^2)((n^2)+(m^2))t))Sin[n π x]Cos[m π y],t]//Simplify

f[x_,y_]:=Sin[π x]Cos[2π y]

ContourPlot[f[x,y],{x,0,1},{y,0,1},FrameLabel->{"x","y"},PlotRange->All,PlotPoints->50]

f[x,y]

2Integrate[f[x,y],{y,0,1}]

2Integrate[Integrate[f[x,y],{y,0,1}]Sin[n π x],{x,0,1},Assumptions->{n∈Integers,n≥1}]

u[x_,y_,t_]:=(E^(-5(π^2)t))Sin[π x]Cos[2π y]

u[0,y,t]

u[1,y,t]

Derivative[0,1,0][u][x,0,t]

Derivative[0,1,0][u][x,1,t]

u[x,y,0]

D[u[x,y,t],t]-D[u[x,y,t],x,x]-D[u[x,y,t],y,y]//Simplify

ContourPlot3D[u[x,y,t],{x,0,1},{y,0,1},{t,0,1/4},AxesLabel->{"x","y","t"},PlotRange->{{0,1},{0,1},{0,1/4}},ContourStyle->{Opacity[0.5]},Mesh->False,BoxRatios->{1,1,1/2},Contours->{1,2,3,4,5},ColorFunction->(Lighter[GrayLevel[#]]&)]

SliceContourPlot3D[u[x,y,t],{{"XStackedPlanes",2},{"YStackedPlanes",2}},{x,0,1},{y,0,1},{t,0,1/4},AxesLabel->{"x","y","t"},BoxRatios->{1,1,1/2},PlotTheme->{"Monochrome"},Contours->15]

ContourPlot[u[x,y,0.1],{x,0,1},{y,0,1},FrameLabel->{"\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["x", "TI"], TraditionalForm], "errors" -> {}, "input" -> "x", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)","\!\(\*TemplateBox[<|"boxes" -> FormBox[
StyleBox["y", "TI"], TraditionalForm], "errors" -> {}, "input" -> "y", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)"},PlotLabel->"\!\(\*TemplateBox[<|"boxes" -> FormBox[
RowBox[{
StyleBox["t", "TI"], "==", "0.1"}], TraditionalForm], "errors" -> {}, "input" -> "t = 0.1", "state" -> "Boxes"|>,"TeXAssistantTemplate"]\)",ContourLabels->Function[{x,y,z},Text[z,{x,y},Background->White]]]

Export["FSN2D.eps",%,"EPS"]

Export["FSN2D.pdf",%%,"PDF"]

ContourPlot3D[u[x,y,t],{x,0,1},{y,0,1},{t,0,1/4},AxesLabel->{"x","y","t"},PlotRange->{{0,1},{0,1},{0,1/4}},ContourStyle->{Opacity[0.5]},Mesh->False,BoxRatios->{1,1,1/2},Contours->{1,2,3,4,5},PlotTheme->{"Monochrome"}]

ContourPlot[u[x,y,t]/.t->0.0,{x,0,1},{y,0,1},FrameLabel->{"x","y"},PlotRange->All,PlotPoints->50]