(* 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[ 18862, 519] NotebookOptionsPosition[ 18454, 502] NotebookOutlinePosition[ 18796, 517] CellTagsIndexPosition[ 18753, 514] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell["\:041c\:0435\:0442\:043e\:0434\:0438", "Chapter", CellChangeTimes->{{3.747918045893719*^9, 3.7479180792016163`*^9}, { 3.748019567260964*^9, 3.7480195984310884`*^9}, {3.7491799306613116`*^9, 3.749179945330095*^9}, {3.7491820390416107`*^9, 3.749182140816432*^9}, { 3.7491822953940344`*^9, 3.7491823155841894`*^9}, {3.749182378833807*^9, 3.749182424987447*^9}, {3.749182543546228*^9, 3.74918254777547*^9}, { 3.7491855618392*^9, 3.749185791014152*^9}, 3.7494816355928173`*^9, { 3.7494826582226067`*^9, 3.749482678435937*^9}, {3.749483068682683*^9, 3.7494830721446886`*^9}, {3.7494884082644987`*^9, 3.7494884424507885`*^9}, {3.749488494590744*^9, 3.7494885492422333`*^9}, { 3.749488662765763*^9, 3.7494886848150673`*^9}, {3.7494887168485804`*^9, 3.749488740273077*^9}, 3.749490389264352*^9, {3.749789440131727*^9, 3.749789499828309*^9}, {3.74979010532883*^9, 3.7497901250714474`*^9}, 3.7499847604043837`*^9, {3.7499852544136286`*^9, 3.749985272769679*^9}, { 3.7515612145185156`*^9, 3.751561319842022*^9}, {3.751561379568722*^9, 3.751561400725582*^9}, {3.7521741297192936`*^9, 3.752174150598387*^9}}, FontFamily-> "Times New Roman",ExpressionUUID->"467d1ec9-6d84-4b2a-90de-bdb8eba1d886"], Cell[BoxData[ RowBox[{ RowBox[{"explicitEuler", "[", RowBox[{"f_", ",", "h_", ",", "t0_", ",", "T_", ",", "u0_"}], "]"}], ":=", " ", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"(", RowBox[{"T", "-", "t0"}], ")"}], "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"t0", "+", RowBox[{"i", "*", "h"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "1", "]"}], "]"}], " ", "=", "u0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "<", RowBox[{"n", "+", "1"}]}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], " ", "=", " ", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "]"}]}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{ 3.7515563087600636`*^9, {3.751556360006592*^9, 3.7515564799865913`*^9}, { 3.751556639141062*^9, 3.751556639357938*^9}, {3.75155671085882*^9, 3.751556714680622*^9}, {3.751556782540594*^9, 3.7515567830503016`*^9}, { 3.751557223977725*^9, 3.751557232127038*^9}, {3.751557273543219*^9, 3.75155727616871*^9}, {3.751557439493783*^9, 3.751557439852577*^9}, { 3.751558318906334*^9, 3.751558319058245*^9}, {3.7515586051607094`*^9, 3.75155861412757*^9}, {3.7521570890106964`*^9, 3.75215709038891*^9}, { 3.752176074470169*^9, 3.7521760830142946`*^9}}, ExpressionUUID -> "d0a40c0c-c125-4a61-9539-c7544c932fc8"], Cell[BoxData[ RowBox[{ RowBox[{"implicitEuler", "[", RowBox[{"f_", ",", "h_", ",", "t0_", ",", "T_", ",", "u0_"}], "]"}], ":=", " ", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"(", RowBox[{"T", "-", "t0"}], ")"}], "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"t0", "+", RowBox[{"i", "*", "h"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "1", "]"}], "]"}], " ", "=", "u0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "<", RowBox[{"n", "+", "1"}]}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"initial", " ", "=", " ", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], "=", RowBox[{"yNew", "/.", RowBox[{"FindRoot", "[", RowBox[{ RowBox[{"yNew", "==", " ", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", "yNew"}], "]"}]}]}]}], ",", RowBox[{"{", RowBox[{"yNew", ",", "initial"}], "}"}]}], "]"}]}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "]"}]}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{{3.7515574834674945`*^9, 3.7515575998356133`*^9}, { 3.751557648158707*^9, 3.7515576636607933`*^9}, {3.751557738529467*^9, 3.751557763031377*^9}, 3.7515580336403885`*^9, {3.7515580964512835`*^9, 3.751558123797539*^9}, {3.7515581689555693`*^9, 3.751558169385322*^9}, { 3.751558322920025*^9, 3.7515583230319777`*^9}, {3.751558458330151*^9, 3.7515585241552973`*^9}, {3.751570772243475*^9, 3.751570817505479*^9}, { 3.7521766927406673`*^9, 3.752176696682413*^9}},ExpressionUUID->"4a6b5a71-ee89-4044-925a-\ 9e0eca7f52ca"], Cell[BoxData[ RowBox[{ RowBox[{"RK4", "[", RowBox[{"f_", ",", "h_", ",", "t0_", ",", "T_", ",", "u0_"}], "]"}], ":=", " ", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"(", RowBox[{"T", "-", "t0"}], ")"}], "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"t0", "+", RowBox[{"i", "*", "h"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "1", "]"}], "]"}], " ", "=", " ", "u0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "<=", "n"}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k1", " ", "=", " ", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k2", " ", "=", " ", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k1", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k3", " ", "=", " ", RowBox[{"h", "*", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k2", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k4", " ", "=", RowBox[{"h", "*", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", "h"}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", "k3"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], " ", "=", " ", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{ RowBox[{"1", "/", "6"}], "k1"}], "+", RowBox[{ RowBox[{"1", "/", "3"}], "k2"}], "+", RowBox[{ RowBox[{"1", "/", "3"}], "k3"}], "+", RowBox[{ RowBox[{"1", "/", "6"}], "k4"}]}]}]}]}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "]"}]}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{{3.749790138229862*^9, 3.7497901566012683`*^9}, 3.7499849756016817`*^9, {3.750398226091392*^9, 3.750398389332283*^9}, { 3.7503984331110306`*^9, 3.750398439266488*^9}, {3.750398574497512*^9, 3.7503985813046026`*^9}, {3.7503986122967186`*^9, 3.75039861385282*^9}, { 3.7503987198976784`*^9, 3.7503987590611153`*^9}, {3.750861148761247*^9, 3.7508611531587133`*^9}, {3.750861592248006*^9, 3.7508615945696664`*^9}, 3.7508617880070868`*^9, 3.750861941006491*^9, {3.7508691323068924`*^9, 3.7508691387071886`*^9}, {3.750869283890499*^9, 3.750869292626458*^9}, 3.751556304862305*^9, {3.751558296542212*^9, 3.7515583069642015`*^9}, { 3.751560941093563*^9, 3.7515609415253134`*^9}, {3.7515692698583946`*^9, 3.7515692734823074`*^9}, {3.7521767011338625`*^9, 3.752176704922719*^9}, { 3.783328759467596*^9, 3.783328760144196*^9}},ExpressionUUID->"218c4638-48db-45f8-9652-\ b892485b01bc"], Cell[BoxData[ RowBox[{ RowBox[{"AB4", "[", RowBox[{"f_", ",", "h_", ",", "t0_", ",", "T_", ",", "u0_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"(", RowBox[{"T", "-", "t0"}], ")"}], "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"x", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"t0", "+", RowBox[{"i", " ", "h"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"fi", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", " ", RowBox[{"(*", RowBox[{ RowBox[{ "list", " ", "of", " ", "values", " ", "of", " ", "the", " ", "right"}], "-", RowBox[{"hand", " ", "side", " ", "f"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "1", "]"}], "]"}], "=", "u0"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "Compute", " ", "the", " ", "first", " ", "approximate", " ", "values"}], ",", " ", RowBox[{"using", " ", "the", " ", "RK4", " ", "method"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", " ", RowBox[{"i", "\[LessEqual]", "3"}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k1", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k2", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k1", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k3", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k2", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k4", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"x", "[", RowBox[{"[", "i", "]"}], "]"}], "+", "h"}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", "k3"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], "=", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{ FractionBox["1", "6"], RowBox[{"(", RowBox[{"k1", "+", RowBox[{"2", "k2"}], "+", RowBox[{"2", "k3"}], "+", "k4"}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"fi", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], "=", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"Compute", " ", "the", " ", "remaining", " ", "values"}], ",", " ", RowBox[{"using", " ", "the", " ", "AB4", " ", "formula"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "4"}], ",", RowBox[{"i", "<", RowBox[{"n", "+", "1"}]}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], "=", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{ FractionBox[ RowBox[{"h", " "}], "24"], RowBox[{"(", RowBox[{ RowBox[{"55", " ", RowBox[{"fi", "[", RowBox[{"[", "i", "]"}], "]"}]}], "-", " ", RowBox[{"59", " ", RowBox[{"fi", "[", RowBox[{"[", RowBox[{"i", "-", "1"}], "]"}], "]"}]}], "+", " ", RowBox[{"37", " ", RowBox[{"fi", "[", RowBox[{"[", RowBox[{"i", "-", "2"}], "]"}], "]"}]}], "-", " ", RowBox[{"9", RowBox[{"fi", "[", RowBox[{"[", RowBox[{"i", "-", "3"}], "]"}], "]"}]}]}], ")"}]}]}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"fi", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], "=", RowBox[{"f", "[", RowBox[{ RowBox[{"x", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", RowBox[{"i", "+", "1"}], "]"}], "]"}]}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "]"}]}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{{3.7515586981543894`*^9, 3.7515587517855453`*^9}, { 3.75156929377765*^9, 3.751569300563752*^9}, {3.7521767135187993`*^9, 3.752176717614464*^9}, {3.7521771841507807`*^9, 3.752177189484725*^9}, { 3.7521773558228617`*^9, 3.752177356058737*^9}, {3.7833287667353816`*^9, 3.783328767463978*^9}},ExpressionUUID->"36837f17-bac1-40b1-b9f2-\ 4ea41252841b"] }, WindowSize->{773, 676}, WindowMargins->{{-7, Automatic}, {Automatic, 0}}, FrontEndVersion->"8.0 for Microsoft Windows (64-bit) (October 6, 2011)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[557, 20, 1241, 17, 23, "Chapter"], Cell[1801, 39, 2512, 66, 252, "Input"], Cell[4316, 107, 3084, 83, 252, "Input"], Cell[7403, 192, 4384, 116, 292, "Input"], Cell[11790, 310, 6660, 190, 557, "Input"] } ] *)