(* 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[ 12707, 349] NotebookOptionsPosition[ 12348, 332] NotebookOutlinePosition[ 12691, 347] CellTagsIndexPosition[ 12648, 344] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[{ RowBox[{ RowBox[{"h", "=", "0.01"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Tau]", "=", "0.01"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"l", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"T", "=", "0.1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{"l", "/", "h"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"m", "=", RowBox[{"Ceiling", "[", RowBox[{"T", "/", "\[Tau]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"t", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"j", "-", "1"}], ")"}], "\[Tau]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"m", "+", "1"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}], "h"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"n", "+", "1"}]}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"m", "+", "1"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Initial", " ", "condition"}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "\[LessEqual]", " ", RowBox[{"n", "+", "1"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", ",", "1"}], "]"}], "]"}], "=", RowBox[{"Sin", "[", RowBox[{"2", " ", "Pi", " ", RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}], "h"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{ "Generate", " ", "the", " ", "matrix", " ", "of", " ", "the", " ", "linear", " ", RowBox[{"system", ".", " ", "This"}], " ", "can", " ", "be", " ", "done", " ", "outside", " ", "the", " ", "for"}], "-", "loop"}], ",", " ", RowBox[{ "since", " ", "the", "\[IndentingNewLine]", "matrix", " ", "is", " ", "constant"}]}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"1", ",", "1"}], "]"}], "]"}], "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{ RowBox[{"n", "+", "1"}], ",", RowBox[{"n", "+", "1"}]}], "]"}], "]"}], "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "2"}], ",", RowBox[{"i", "<", RowBox[{"n", "+", "1"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", RowBox[{"i", "-", "1"}]}], "]"}], "]"}], "=", RowBox[{ RowBox[{"-", "1"}], "/", RowBox[{"(", RowBox[{"2", RowBox[{"h", "^", "2"}]}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", "i"}], "]"}], "]"}], "=", RowBox[{ RowBox[{"1", "/", "\[Tau]"}], "+", RowBox[{"1", "/", RowBox[{"h", "^", "2"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "[", RowBox[{"[", RowBox[{"i", ",", RowBox[{"i", "+", "1"}]}], "]"}], "]"}], "=", RowBox[{ RowBox[{"-", "1"}], "/", RowBox[{"(", RowBox[{"2", RowBox[{"h", "^", "2"}]}], ")"}]}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}], "\[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[{ RowBox[{"Generate", " ", "the", " ", "right"}], "-", RowBox[{ "hand", " ", "side", " ", "vector", " ", "of", " ", "the", " ", "linear", " ", "system"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"k", "=", "2"}], ",", RowBox[{"k", "\[LessEqual]", "n"}], ",", RowBox[{"k", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"b", "[", RowBox[{"[", "k", "]"}], "]"}], "=", RowBox[{ FractionBox[ RowBox[{"y", "[", RowBox[{"[", RowBox[{"k", ",", "j"}], "]"}], "]"}], "\[Tau]"], "+", FractionBox[ RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{ RowBox[{"k", "-", "1"}], ",", "j"}], "]"}], "]"}], "-", RowBox[{"2", RowBox[{"y", "[", RowBox[{"[", RowBox[{"k", ",", "j"}], "]"}], "]"}]}], "+", RowBox[{"y", "[", RowBox[{"[", RowBox[{ RowBox[{"k", "+", "1"}], ",", "j"}], "]"}], "]"}]}], RowBox[{"2", RowBox[{"h", "^", "2"}]}]]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"yNew", "=", RowBox[{"LinearSolve", "[", RowBox[{"A", ",", "b"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"All", ",", RowBox[{"j", "+", "1"}]}], "]"}], "]"}], "=", "yNew"}]}]}], "\[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}, {3.6721296836775656`*^9, 3.672129683889578*^9}, { 3.6721297303852367`*^9, 3.6721297621110516`*^9}, {3.673002940676425*^9, 3.6730029490629044`*^9}, {3.6730030222540903`*^9, 3.673003024404214*^9}, { 3.6730103567128496`*^9, 3.673010396484124*^9}, {3.673010461153823*^9, 3.6730104645530176`*^9}, {3.673010570225062*^9, 3.6730105771254563`*^9}, { 3.6730106348407574`*^9, 3.673010716127407*^9}, {3.673010753012517*^9, 3.673010756856736*^9}, 3.6730108489580045`*^9, {3.67301118509523*^9, 3.6730112048833623`*^9}, {3.6730115862381744`*^9, 3.673011587082223*^9}, { 3.7036592205146074`*^9, 3.703659224384612*^9}, {3.7036592718556795`*^9, 3.7036593935201917`*^9}, {3.7036594334492593`*^9, 3.7036594445422754`*^9}, {3.703659479745325*^9, 3.703659502182358*^9}, { 3.7036610584638224`*^9, 3.703661206254036*^9}, {3.7036615480265255`*^9, 3.7036617061167545`*^9}, {3.703661761731847*^9, 3.703661768719857*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "x", "]"}]}], "}"}]}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "[", "t", "]"}], ",", "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}, {3.672129797523077*^9, 3.6721298196813445`*^9}, {3.6730030293694973`*^9, 3.6730030349778185`*^9}, {3.6730105543091516`*^9, 3.6730105618995857`*^9}, {3.6730108584775486`*^9, 3.6730108790867276`*^9}, {3.6730109138067136`*^9, 3.673010966401722*^9}, { 3.673011218082117*^9, 3.673011294862509*^9}, {3.673011443424006*^9, 3.6730114447700825`*^9}, {3.6730651834165444`*^9, 3.6730652006825323`*^9}, {3.6730654720040507`*^9, 3.673065494150317*^9}, { 3.703661552194532*^9, 3.703661593963592*^9}, {3.7036617766378756`*^9, 3.703661776987876*^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, 11, 1}}, Typeset`size$$ = { 360., {106., 110.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`j$122398$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`j$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`j$$, $CellContext`j$122398$$, 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" :> ListPlot[ Table[{ Part[$CellContext`x, $CellContext`i], Part[$CellContext`y, $CellContext`i, $CellContext`j$$]}, \ {$CellContext`i, 1, Length[$CellContext`x]}], PlotRange -> {{0, 1}, {-1, 1}}], "Specifications" :> {{$CellContext`j$$, 1, 11, 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.6730659635251637`*^9, 3.7036569628305793`*^9, {3.703661771601867*^9, 3.703661777697877*^9}}] }, Open ]] }, WindowSize->{1634, 931}, WindowMargins->{{85, Automatic}, {Automatic, 0}}, 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, 7737, 217, 800, "Input"], Cell[CellGroupData[{ Cell[8319, 241, 2151, 46, 72, "Input"], Cell[10473, 289, 1859, 40, 385, "Output"] }, Open ]] } ] *) (* End of internal cache information *)