(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 8.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] NotebookDataLength[ 15352, 417] NotebookOptionsPosition[ 14874, 396] NotebookOutlinePosition[ 15218, 411] CellTagsIndexPosition[ 15175, 408] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[ RowBox[{ RowBox[{"heatEquation", "[", RowBox[{ "l_", ",", "T_", ",", "h_", ",", "f_", ",", "u0_", ",", "uL_", ",", "uR_", ",", "d_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Tau]", "=", FractionBox[ SuperscriptBox["h", "2"], RowBox[{"3", "d"}]]}], ";", "\[IndentingNewLine]", RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{"l", "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"m", "=", RowBox[{"Ceiling", "[", RowBox[{"T", "/", "\[Tau]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"t", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"j", "-", "1"}], ")"}], "\[Tau]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"m", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}], "h"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"n", "+", "1"}]}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"m", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Initial", " ", "condition"}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "\[LessEqual]", " ", RowBox[{"n", "+", "1"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], "=", RowBox[{"u0", "[", RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Iterate", " ", "over", " ", "the", " ", "time", " ", "nodes"}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"j", "=", "1"}], ",", RowBox[{"j", "\[LessEqual]", "m"}], ",", RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Compute", " ", "the", " ", "internal", " ", "values", " ", "from", " ", "the", " ", "main", " ", "PDE"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "2"}], ",", RowBox[{"i", "\[LessEqual]", "n"}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", ",", RowBox[{"j", "+", "1"}]}], "]"}], "]"}], "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", RowBox[{"2", FractionBox[ RowBox[{"d", " ", "\[Tau]"}], SuperscriptBox["h", "2"]]}]}], ")"}], RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}]}], "+", RowBox[{ FractionBox[ RowBox[{"d", " ", "\[Tau]"}], SuperscriptBox["h", "2"]], RowBox[{"(", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{ RowBox[{"i", "-", "1"}], ",", "j"}], "]"}], "]"}], "+", RowBox[{"y", "[", RowBox[{"[", RowBox[{ RowBox[{"i", "+", "1"}], ",", "j"}], "]"}], "]"}]}], ")"}]}], "+", RowBox[{"\[Tau]", " ", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"t", "[", RowBox[{"[", "j", "]"}], "]"}]}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Compute", " ", "the", " ", "boundary", " ", "values", " ", "from", " ", "the", " ", "boundary", " ", "conditions"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"1", ",", RowBox[{"j", "+", "1"}]}], "]"}], "]"}], "=", RowBox[{"uL", "[", RowBox[{"t", "[", RowBox[{"[", RowBox[{"j", "+", "1"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{ RowBox[{"n", "+", "1"}], ",", RowBox[{"j", "+", "1"}]}], "]"}], "]"}], "=", RowBox[{"uR", "[", RowBox[{"t", "[", RowBox[{"[", RowBox[{"j", "+", "1"}], "]"}], "]"}], "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"x", ",", "t", ",", "y"}], "}"}]}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{{3.671273700734398*^9, 3.6712737594466867`*^9}, { 3.671273797744271*^9, 3.6712740104285936`*^9}, {3.671274085817326*^9, 3.671274363019038*^9}, {3.6712744641319275`*^9, 3.6712744656745353`*^9}, { 3.671274537146551*^9, 3.671274539844946*^9}, {3.6712747426099524`*^9, 3.671274748460289*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"f", "[", RowBox[{"x_", ",", "t_"}], "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"u0", "[", "x_", "]"}], ":=", RowBox[{"Sin", "[", RowBox[{"2", "Pi", " ", "x"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"uL", "[", "t_", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"uR", "[", "t_", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"resX", "=", RowBox[{ RowBox[{"heatEquation", "[", RowBox[{ "1", ",", "0.1", ",", "0.01", ",", "f", ",", "u0", ",", "uL", ",", "uR", ",", "1"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"resT", "=", RowBox[{ RowBox[{"heatEquation", "[", RowBox[{ "1", ",", "0.1", ",", "0.01", ",", "f", ",", "u0", ",", "uL", ",", "uR", ",", "1"}], "]"}], "[", RowBox[{"[", "2", "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"resY", "=", RowBox[{ RowBox[{"heatEquation", "[", RowBox[{ "1", ",", "0.1", ",", "0.01", ",", "f", ",", "u0", ",", "uL", ",", "uR", ",", "1"}], "]"}], "[", RowBox[{"[", "3", "]"}], "]"}]}], ";"}], "\n", RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Show", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"resX", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"resY", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "resX", "]"}]}], "}"}]}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{ SuperscriptBox["E", RowBox[{ RowBox[{"-", "4"}], RowBox[{"Pi", "^", "2"}], RowBox[{"resT", "[", RowBox[{"[", "j", "]"}], "]"}]}]], RowBox[{"Sin", "[", RowBox[{"2", "Pi", " ", "x"}], "]"}]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", "Red"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "[", "resT", "]"}], ",", "1"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.6712743766596103`*^9, 3.671274431590646*^9}, { 3.671274478635186*^9, 3.671274490692809*^9}, {3.671274551123468*^9, 3.6712745761812973`*^9}, {3.671274660918176*^9, 3.6712746884120226`*^9}, { 3.671274770056466*^9, 3.6712748221193027`*^9}, {3.6712748575025187`*^9, 3.6712748728469095`*^9}, {3.671274920464421*^9, 3.671274932027517*^9}, { 3.671274976202646*^9, 3.671274981992981*^9}, {3.6712750226205964`*^9, 3.6712750427469187`*^9}, {3.6712775677375326`*^9, 3.671277627645192*^9}, { 3.6712776629714594`*^9, 3.6712777516199193`*^9}, 3.6712777987270374`*^9, { 3.671277837861479*^9, 3.6712778410688667`*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`j$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{ Hold[$CellContext`j$$], 1, 3001, 1}}, Typeset`size$$ = { 360., {106., 110.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`j$1398$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`j$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`j$$, $CellContext`j$1398$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> Show[ ListPlot[ Table[{ Part[$CellContext`resX, $CellContext`i], Part[$CellContext`resY, $CellContext`i, $CellContext`j$$]}, \ {$CellContext`i, 1, Length[$CellContext`resX]}], PlotRange -> {{0, 1}, {-1, 1}}], Plot[ E^((-4) Pi^2 Part[$CellContext`resT, $CellContext`j$$]) Sin[2 Pi $CellContext`x], {$CellContext`x, 0, 1}, PlotStyle -> Red]], "Specifications" :> {{$CellContext`j$$, 1, 3001, 1}}, "Options" :> {}, "DefaultOptions" :> {}], ImageSizeCache->{411., {164., 171.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UndoTrackedVariables:>{Typeset`show$$, Typeset`bookmarkMode$$}, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellChangeTimes->{3.7036565809976625`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Show", "[", "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"resX", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"Abs", "[", RowBox[{ RowBox[{"resY", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "-", RowBox[{ SuperscriptBox["E", RowBox[{ RowBox[{"-", "4"}], RowBox[{"Pi", "^", "2"}], RowBox[{"resT", "[", RowBox[{"[", "j", "]"}], "]"}]}]], RowBox[{"Sin", "[", RowBox[{"2", "Pi", " ", RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "resX", "]"}]}], "}"}]}], "]"}], "]"}], "\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "[", "resT", "]"}], ",", "1"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6712778586797113`*^9, 3.6712778815037217`*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`j$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{ Hold[$CellContext`j$$], 1, 3001, 1}}, Typeset`size$$ = { 360., {104., 108.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`j$4099$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`j$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`j$$, $CellContext`j$4099$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> Show[ ListPlot[ Table[{ Part[$CellContext`resX, $CellContext`i], Abs[ Part[$CellContext`resY, $CellContext`i, $CellContext`j$$] - E^((-4) Pi^2 Part[$CellContext`resT, $CellContext`j$$]) Sin[2 Pi Part[$CellContext`x, $CellContext`i]]]}, {$CellContext`i, 1, Length[$CellContext`resX]}]]], "Specifications" :> {{$CellContext`j$$, 1, 3001, 1}}, "Options" :> {}, "DefaultOptions" :> {}], ImageSizeCache->{411., {162., 169.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UndoTrackedVariables:>{Typeset`show$$, Typeset`bookmarkMode$$}, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellChangeTimes->{3.671277883420677*^9, 3.703656594378681*^9}] }, Open ]] }, WindowSize->{1920, 998}, WindowMargins->{{-8, Automatic}, {Automatic, -8}}, FrontEndVersion->"10.1 for Microsoft Windows (64-bit) (March 23, 2015)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[557, 20, 5556, 151, 584, "Input"], Cell[CellGroupData[{ Cell[6138, 175, 3453, 90, 283, "Input"], Cell[9594, 267, 1969, 42, 352, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[11600, 314, 1310, 36, 121, "Input"], Cell[12913, 352, 1945, 41, 348, "Output"] }, Open ]] } ] *) (* End of internal cache information *)