(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 9.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] NotebookDataLength[ 4092, 130] NotebookOptionsPosition[ 3849, 117] NotebookOutlinePosition[ 4193, 132] CellTagsIndexPosition[ 4150, 129] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[ RowBox[{ RowBox[{"RK4", "[", RowBox[{"f_", ",", "u0_", ",", "h_", ",", "t0_", ",", "T_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"n", "=", RowBox[{"Ceiling", "[", RowBox[{ RowBox[{"(", RowBox[{"T", "-", "t0"}], ")"}], "/", "h"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"t", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"i", " ", "h"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "n"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"y", "=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"n", "+", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "1", "]"}], "]"}], "=", "u0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", "n"}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k1", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{"t", "[", RowBox[{"[", "i", "]"}], "]"}], ",", RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k2", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"t", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k1", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k3", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"t", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"h", "/", "2"}]}], ",", RowBox[{ RowBox[{"y", "[", RowBox[{"[", "i", "]"}], "]"}], "+", RowBox[{"k2", "/", "2"}]}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"k4", "=", RowBox[{"h", " ", RowBox[{"f", "[", RowBox[{ RowBox[{ RowBox[{"t", "[", 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]", "]"}], ";", "\[IndentingNewLine]", "y"}], "\[IndentingNewLine]", ")"}]}]], "Input", CellChangeTimes->{{3.664889161346874*^9, 3.6648892186583633`*^9}, { 3.6691041921064377`*^9, 3.669104263666531*^9}}] }, 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, 3288, 95, 386, "Input"] } ] *) (* End of internal cache information *)