(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 12949, 386] NotebookOptionsPosition[ 12080, 351] NotebookOutlinePosition[ 12440, 367] CellTagsIndexPosition[ 12397, 364] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Euler\[CloseCurlyQuote]s Method", "Title", CellChangeTimes->{{3.629718437092924*^9, 3.629718440677018*^9}}, TextAlignment->Center], Cell["\<\ by Ruth Dover Illinois Mathematics and Science Academy\ \>", "Subsubtitle", CellChangeTimes->{{3.693184770716885*^9, 3.693184782292611*^9}}], Cell[CellGroupData[{ Cell["one differential equation", "Section", CellChangeTimes->{{3.629718584851274*^9, 3.629718593580724*^9}, { 3.6297189951577663`*^9, 3.629718995956278*^9}}], Cell[TextData[{ "The command to be used has the general form:\n", StyleBox["EulerGraph[", "Input"], StyleBox["expression for y\[CloseCurlyQuote]", "Input", FontSlant->"Italic"], StyleBox[", {", "Input"], StyleBox["t", "Input", FontSlant->"Italic"], StyleBox[", ", "Input"], StyleBox["tmin, tmax, stepsize", "Input", FontSlant->"Italic"], StyleBox["}, {", "Input"], StyleBox["y", "Input", FontSlant->"Italic"], StyleBox[", ", "Input"], StyleBox["initial y", "Input", FontSlant->"Italic"], StyleBox["}]\n", "Input"], "Check out the example below and then edit the values as appropriate. Any \ letters may be used as the variables, but they must be used consistently in \ the DE and the domains." }], "Text", CellChangeTimes->{{3.629718604492638*^9, 3.6297186579875317`*^9}, { 3.629718693472612*^9, 3.629718732432876*^9}, {3.629718778693623*^9, 3.6297188117026157`*^9}, {3.629719160164177*^9, 3.6297191648517103`*^9}, { 3.629719204856904*^9, 3.629719208905024*^9}}], Cell[BoxData[ RowBox[{"EulerGraph", "[", RowBox[{ RowBox[{"t", "+", "y"}], ",", " ", RowBox[{"{", RowBox[{"t", ",", " ", "0", ",", " ", "6", ",", " ", "2"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", "0"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.629718735823243*^9, 3.629718775631*^9}, { 3.629719186757766*^9, 3.629719191147793*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["system of two differential equations", "Section", CellChangeTimes->{{3.629718931931752*^9, 3.629718955757119*^9}, { 3.6297190023319197`*^9, 3.62971900319559*^9}}], Cell[TextData[{ "This is similar to the Euler command for a single DE. The basic command has \ the general form:\n", StyleBox["EulerGraphSystem[{exprone, exprtwo}, {indvar, min, max, stepsize}, \ {{depvarone, initvalone}, {depvartwo, initvaltwo}}] ", "Input"] }], "Text", CellChangeTimes->{{3.617837013127303*^9, 3.6178370442674417`*^9}, { 3.617837132494979*^9, 3.617837146844696*^9}, {3.617837237412538*^9, 3.617837312611195*^9}, {3.629719078702857*^9, 3.629719092484922*^9}}], Cell[TextData[{ "The example below is , ", StyleBox["x\[CloseCurlyQuote] = ", FontSlant->"Italic"], "2", StyleBox["x - y ", FontSlant->"Italic"], "and ", StyleBox["y\[CloseCurlyQuote]", FontSlant->"Italic"], " = 2", StyleBox["x", FontSlant->"Italic"], ", where both ", StyleBox["x", FontSlant->"Italic"], " and ", StyleBox["y", FontSlant->"Italic"], " depend on ", StyleBox["t", FontSlant->"Italic"], "." }], "Text", CellChangeTimes->{{3.6178376763057947`*^9, 3.6178377622988234`*^9}}], Cell[BoxData[ RowBox[{"EulerGraphSystem", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "x"}], "-", "y"}], ",", " ", RowBox[{"2", "x"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"t", ",", " ", "0", ",", " ", "3", ",", " ", ".2"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "2"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", "1"}], "}"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.6178370577562647`*^9, 3.617837063668584*^9}, { 3.617837108969762*^9, 3.6178371134218473`*^9}, {3.617837444835628*^9, 3.617837524783856*^9}, {3.6178375831671*^9, 3.6178376257208776`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["initialization", "Section", CellChangeTimes->{{3.629718387728837*^9, 3.629718394063612*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"EulerGraph", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "xmin_", ",", " ", "xmax_", ",", " ", "step_"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y_", ",", " ", "initialy_"}], "}"}], ",", " ", "opts___"}], "]"}], ":=", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "xval", ",", " ", "yval", ",", " ", "pointsToPlot", ",", " ", "n", ",", " ", "k"}], "}"}], ",", "\n", "\t\t", RowBox[{ RowBox[{"xval", " ", "=", " ", "xmin"}], ";", "\n", "\t\t", RowBox[{"yval", " ", "=", " ", "initialy"}], ";", "\n", "\t\t", RowBox[{"k", " ", "=", " ", "1"}], ";", "\n", "\t\t", RowBox[{"n", " ", "=", " ", RowBox[{"N", "[", RowBox[{ RowBox[{"(", RowBox[{"xmax", "-", "xmin"}], ")"}], "/", "step"}], "]"}]}], ";", "\n", "\t\t", RowBox[{"pointsToPlot", " ", "=", " ", RowBox[{"{", RowBox[{"{", RowBox[{"xmin", ",", " ", "initialy"}], "}"}], "}"}]}], ";", "\n", "\t\t", RowBox[{"While", "[", RowBox[{ RowBox[{"k", "<=", "n"}], ",", "\n", "\t\t", RowBox[{ RowBox[{"yval", "=", " ", RowBox[{"N", "[", RowBox[{"yval", "+", "\t", RowBox[{ RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", " ", "y"}], "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"xval", ",", " ", "yval"}], "]"}], "*", "step"}]}], "]"}]}], ";", "\n", "\t\t\t", RowBox[{"xval", " ", "=", " ", RowBox[{"xval", " ", "+", " ", "step"}]}], ";", "\n", "\t\t\t", RowBox[{"k", "=", RowBox[{"k", "+", "1"}]}], ";", "\n", "\t\t\t", RowBox[{"AppendTo", "[", RowBox[{"pointsToPlot", ",", " ", RowBox[{"{", RowBox[{"xval", ",", " ", "yval"}], "}"}]}], "]"}]}]}], "\n", "\t\t\t\t\t\t", "]"}], ";", "\n", "\t", RowBox[{"gr1", " ", "=", " ", RowBox[{"ListLinePlot", "[", RowBox[{"pointsToPlot", ",", " ", RowBox[{"Mesh", " ", "->", " ", "All"}], ",", " ", RowBox[{"MeshStyle", "->", RowBox[{"{", RowBox[{"Red", ",", " ", RowBox[{"PointSize", "[", "Medium", "]"}]}], "}"}]}], ",", " ", RowBox[{"PlotRange", " ", "->", "All"}], ",", " ", "\n", " ", RowBox[{"Axes", " ", "->", "True"}]}], "]"}]}], ";", "\n", RowBox[{"Show", "[", RowBox[{"gr1", ",", " ", RowBox[{"Graphics", "[", RowBox[{"Text", "[", RowBox[{ RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{ "\"\\"", ",", "xval", ",", " ", "yval"}], "]"}], ",", " ", RowBox[{"FontSize", "->", "14"}]}], "]"}], ",", "\n", RowBox[{"{", RowBox[{ RowBox[{"xval", "-", RowBox[{".01", RowBox[{"(", RowBox[{"xmax", "-", "xmin"}], ")"}]}]}], ",", " ", "yval"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"1", ",", " ", "0"}], "}"}]}], "]"}], "]"}], ",", " ", RowBox[{"Evaluate", "[", " ", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}]}], "\n", "]"}]}]}], "]"}]}]], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{ RowBox[{"EulerGraphSystem", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", " ", "g_"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"t_", ",", " ", "a_", ",", " ", "b_", ",", " ", "step_"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x_", ",", " ", "initx_"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y_", ",", " ", "inity_"}], "}"}]}], "}"}], ",", " ", "opts___"}], "]"}], ":=", "\n", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "tval", ",", "xval", ",", " ", "newxval", ",", "yval", ",", " ", "pointsToPlot", ",", " ", "n", ",", " ", "k"}], "}"}], ",", "\n", RowBox[{ RowBox[{"tval", "=", "a"}], ";", " ", RowBox[{"xval", "=", "initx"}], ";", " ", RowBox[{"yval", "=", "inity"}], ";", "\n", RowBox[{"k", "=", "1"}], ";", " ", RowBox[{"n", "=", RowBox[{"N", "[", RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "/", "step"}], "]"}]}], ";", " ", "\n", RowBox[{"pointsToPlot", "=", RowBox[{"{", RowBox[{"{", RowBox[{"initx", ",", " ", "inity"}], "}"}], "}"}]}], ";", "\n", RowBox[{"While", "[", RowBox[{ RowBox[{"k", "<=", "n"}], ",", " ", RowBox[{ RowBox[{"newxval", "=", RowBox[{"N", "[", RowBox[{"xval", "+", RowBox[{"step", "*", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], ",", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"xval", ",", " ", "yval"}], "]"}]}]}], "]"}]}], ";", "\n", RowBox[{"yval", "=", RowBox[{"N", "[", RowBox[{"yval", "+", RowBox[{"step", "*", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", " ", "y"}], "}"}], ",", " ", RowBox[{"Evaluate", "[", "g", "]"}]}], "]"}], "[", RowBox[{"xval", ",", " ", "yval"}], "]"}]}]}], "]"}]}], ";", "\n", RowBox[{"xval", "=", "newxval"}], ";", "\n", RowBox[{"tval", "=", RowBox[{"tval", "+", "step"}]}], ";", "\n", RowBox[{"k", "=", RowBox[{"k", "+", "1"}]}], ";", "\n", RowBox[{"AppendTo", "[", RowBox[{"pointsToPlot", ",", " ", RowBox[{"{", RowBox[{"xval", ",", " ", "yval"}], "}"}]}], "]"}]}]}], "\n", "]"}], ";", "\n", RowBox[{"gr1", "=", RowBox[{"ListLinePlot", "[", RowBox[{"pointsToPlot", ",", " ", RowBox[{"PlotRange", "->", "All"}], ",", " ", RowBox[{"Axes", "->", "True"}], ",", " ", RowBox[{"Mesh", "->", "All"}], ",", " ", RowBox[{"MeshStyle", "->", RowBox[{"{", RowBox[{"Red", ",", " ", RowBox[{"PointSize", "[", "Medium", "]"}]}], "}"}]}]}], "]"}]}], ";", "\n", RowBox[{"Show", "[", RowBox[{"gr1", ",", " ", RowBox[{"PlotLabel", "->", RowBox[{"Text", "[", RowBox[{"Style", "[", RowBox[{ RowBox[{"StringForm", "[", RowBox[{ "\"\\"", ",", " ", "xval", ",", "yval"}], "]"}], ",", " ", RowBox[{"FontSize", "->", "14"}]}], "]"}], "]"}]}], ",", RowBox[{"Evaluate", "[", " ", RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], "]"}]}], "]"}]}]}], "\n", " ", "]"}]}]], "Input", InitializationCell->True] }, Closed]] }, Open ]] }, WindowSize->{808, 724}, WindowMargins->{{Automatic, 800}, {Automatic, 83}}, FrontEndVersion->"11.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (September \ 21, 2016)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 138, 2, 92, "Title"], Cell[721, 26, 151, 4, 49, "Subsubtitle"], Cell[CellGroupData[{ Cell[897, 34, 161, 2, 64, "Section"], Cell[1061, 38, 993, 25, 88, "Text"], Cell[2057, 65, 379, 10, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2473, 80, 171, 2, 64, "Section"], Cell[2647, 84, 485, 8, 70, "Text"], Cell[3135, 94, 516, 24, 30, "Text"], Cell[3654, 120, 698, 19, 32, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4389, 144, 99, 1, 64, "Section"], Cell[4491, 147, 3700, 94, 369, "Input", InitializationCell->True], Cell[8194, 243, 3858, 104, 335, "Input", InitializationCell->True] }, Closed]] }, Open ]] } ] *)