(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 11982, 345] NotebookOptionsPosition[ 11414, 321] NotebookOutlinePosition[ 11775, 337] CellTagsIndexPosition[ 11732, 334] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Slope Fields and Solutions", "Title", CellChangeTimes->{{3.472517259081543*^9, 3.472517266638839*^9}, 3.4725185460779877`*^9, {3.6297358272552853`*^9, 3.6297358308938704`*^9}}, TextAlignment->Center], Cell["\<\ by Ruth Dover Illinois Mathematics and Science Academy\ \>", "Subsubtitle", CellChangeTimes->{{3.6931844952338963`*^9, 3.69318450622464*^9}}], Cell[TextData[{ "Enter the DE as a function \[Florin] in terms of ", StyleBox["t", FontSlant->"Italic"], " and ", StyleBox["y. ", FontSlant->"Italic"], "This must be in the form ", StyleBox["y' =", FontSlant->"Italic"], "...", StyleBox[" ", FontSlant->"Italic"], "Then enter min and max ", StyleBox["t", FontSlant->"Italic"], " and ", StyleBox["y", FontSlant->"Italic"], " values. Examples are given. The default \"", StyleBox["plotshape\" ", FontSlant->"Italic"], "is given as \"Automatic\" which makes the ", StyleBox["t-", FontSlant->"Italic"], " and ", StyleBox["y-", FontSlant->"Italic"], "scales will be the same. If you desire another shape, replace \ \"Automatic\" with 1/2 or 2 or other such values. (This may take some \ experimentation to find an appropriate shape.)\n" }], "Text", CellChangeTimes->{{3.4725173393065557`*^9, 3.472517416952784*^9}, { 3.472517451919492*^9, 3.4725174851352167`*^9}, {3.472517516952696*^9, 3.472517536347237*^9}, {3.472517623008811*^9, 3.472517760052394*^9}, { 3.4725184943515673`*^9, 3.4725185288423986`*^9}, {3.472603900196918*^9, 3.472603903788615*^9}, 3.629726355921853*^9, {3.629735699619893*^9, 3.629735729804356*^9}, {3.693184593268361*^9, 3.6931846114477787`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"f", "[", RowBox[{"t_", ",", " ", "y_"}], "]"}], ":=", RowBox[{"t", "+", "y"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tmin", "=", " ", RowBox[{"-", "4"}]}], ";", " ", RowBox[{"tmax", "=", "4"}], ";", RowBox[{"ymin", "=", RowBox[{"-", "4"}]}], ";", RowBox[{"ymax", "=", "4"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"plotshape", "=", "Automatic"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Do", " ", "not", " ", "mess", " ", "with", " ", "the", " ", "coding", " ", RowBox[{"below", "!"}]}], "*)"}]}], "\[IndentingNewLine]", RowBox[{"Manipulate", "[", RowBox[{ RowBox[{ RowBox[{"slp", "=", RowBox[{"SlopeField", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"t", ",", "y"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"t", ",", " ", "tmin", ",", " ", "tmax"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", " ", "ymin", ",", " ", "ymax"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ds", "=", RowBox[{"DSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "t", "]"}], "\[Equal]", RowBox[{"f", "[", RowBox[{"t", ",", " ", RowBox[{"y", "[", "t", "]"}]}], "]"}]}], ",", " ", RowBox[{ RowBox[{"y", "[", RowBox[{"initpt", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}], "\[Equal]", RowBox[{"initpt", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], "}"}], ",", " ", "y", ",", " ", "t"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Show", "[", RowBox[{"slp", ",", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{ RowBox[{"y", "[", "t", "]"}], "/.", "ds"}], "]"}], " ", ",", " ", RowBox[{"{", RowBox[{"t", ",", " ", "tmin", ",", " ", "tmax"}], "}"}], ",", " ", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{"ymin", ",", " ", "ymax"}], "}"}]}], ",", " ", RowBox[{"PlotStyle", "\[Rule]", "Thick"}]}], "]"}], ",", RowBox[{"Graphics", "[", RowBox[{"{", RowBox[{ RowBox[{"PointSize", "[", "Large", "]"}], ",", "Red", ",", " ", RowBox[{"Point", "[", "initpt", "]"}]}], "}"}], "]"}], ",", " ", RowBox[{"AspectRatio", "\[Rule]", "plotshape"}]}], "]"}]}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"initpt", ",", RowBox[{"{", " ", RowBox[{ RowBox[{"tmin", "+", RowBox[{".1", RowBox[{"(", RowBox[{"tmax", "-", "tmin"}], ")"}]}]}], ",", FractionBox[ RowBox[{"ymin", "+", "ymax"}], "2"]}], "}"}]}], " ", "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"tmin", "+", RowBox[{".01", RowBox[{"(", RowBox[{"tmax", "-", "tmin"}], ")"}]}]}], ",", " ", RowBox[{"ymin", "+", RowBox[{".1", RowBox[{"(", RowBox[{"ymax", "-", "ymin"}], ")"}]}]}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"tmax", ",", " ", "ymax"}], "}"}]}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.4725793087992907`*^9, 3.472579314953559*^9}, { 3.472579396707346*^9, 3.4725795047121058`*^9}, {3.472579577701034*^9, 3.4725795840850554`*^9}, {3.472579614414262*^9, 3.472579640871395*^9}, 3.4726035070253963`*^9, {3.472603682148116*^9, 3.472603708717244*^9}, { 3.472604348886073*^9, 3.472604350003976*^9}, {3.6297263108599997`*^9, 3.629726312298409*^9}}], Cell[CellGroupData[{ Cell["initialization", "Subsection", CellChangeTimes->{{3.629548442633709*^9, 3.629548456983066*^9}, { 3.629718008906405*^9, 3.629718013303976*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Options", "[", "SlopeField", "]"}], "=", RowBox[{"{", RowBox[{"Marks", "->", RowBox[{"{", RowBox[{"15", ",", " ", "13"}], "}"}]}], "}"}]}], ";"}], "\n", RowBox[{ RowBox[{"SlopeField", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"x_", ",", " ", "a_", ",", " ", "b_"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y_", ",", " ", "c_", ",", " ", "d_"}], "}"}], ",", " ", "opts___"}], "]"}], ":=", "\n", " ", "\n", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "m", ",", " ", "n", ",", " ", "slope", ",", " ", "h", ",", " ", "k", ",", "u", ",", " ", "v", ",", "i", ",", " ", "j", ",", " ", "centerpts", ",", "tiltlines", ",", " ", "littlemark", ",", " ", "\n", " ", "ourlist"}], "}"}], ",", "\n", " ", RowBox[{ RowBox[{"marks", "=", RowBox[{ RowBox[{"Marks", "/.", " ", RowBox[{"{", "opts", "}"}]}], "/.", RowBox[{"Options", "[", "SlopeField", "]"}]}]}], ";", "\n", " ", RowBox[{"m", "=", RowBox[{"marks", "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"n", "=", RowBox[{"marks", "[", RowBox[{"[", "2", "]"}], "]"}]}], ";", " ", "\n", " ", RowBox[{"h", "=", RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], "/", "m"}]}], ";", " ", RowBox[{"k", "=", RowBox[{ RowBox[{"(", RowBox[{"d", "-", "c"}], ")"}], "/", "n"}]}], ";", "\n", " ", RowBox[{"centerpts", "=", "\n", " ", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "+", RowBox[{ RowBox[{"(", RowBox[{"i", "+", ".5"}], ")"}], "h"}]}], ",", " ", RowBox[{"c", "+", RowBox[{ RowBox[{"(", RowBox[{"j", "+", ".5"}], ")"}], "k"}]}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", " ", "0", ",", " ", RowBox[{"m", "-", "1"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"j", ",", " ", "0", ",", " ", RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}], ",", "1"}], "]"}]}], ";", "\n", " ", RowBox[{ RowBox[{"tiltlines", "[", "ourlist_List", "]"}], ":=", "\n", " ", RowBox[{"(", "\n", " ", RowBox[{ RowBox[{ RowBox[{"littlemark", "[", RowBox[{"{", RowBox[{"xpt_", ",", " ", "ypt_"}], "}"}], "]"}], "=", "\n", " ", RowBox[{"(", RowBox[{ RowBox[{"slope", "=", RowBox[{ RowBox[{"Function", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", " ", "y"}], "}"}], ",", " ", RowBox[{"Evaluate", "[", "f", "]"}]}], "]"}], "[", RowBox[{"xpt", ",", " ", "ypt"}], "]"}]}], ";", "\n", " ", RowBox[{"u", "=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Abs", "[", "slope", "]"}], ">", RowBox[{"k", "/", "h"}]}], ",", RowBox[{"Evaluate", "[", RowBox[{"k", "/", "slope"}], "]"}], ",", " ", "h"}], " ", "]"}]}], ";", "\n", " ", RowBox[{"v", "=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Abs", "[", "slope", "]"}], ">", RowBox[{"k", "/", "h"}]}], ",", " ", "k", ",", RowBox[{"Evaluate", "[", RowBox[{"h", " ", "slope"}], "]"}]}], " ", "]"}]}], ";", "\n", " ", RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"xpt", "-", RowBox[{".4", "u"}]}], " ", ",", " ", RowBox[{"ypt", "-", RowBox[{".4", "v"}]}]}], " ", "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"xpt", "+", RowBox[{".4", "u"}]}], ",", " ", RowBox[{"ypt", "+", RowBox[{".4", "v"}]}]}], " ", "}"}]}], "}"}], "]"}]}], "\n", " ", ")"}]}], ";", "\n", " ", RowBox[{"Map", "[", RowBox[{"littlemark", ",", " ", "ourlist"}], "]"}]}], "\n", " ", ")"}]}], ";", "\n", " ", RowBox[{"Show", "[", RowBox[{"Graphics", "[", RowBox[{ RowBox[{"tiltlines", "[", "centerpts", "]"}], ",", RowBox[{"Evaluate", "[", RowBox[{ RowBox[{"Sequence", " ", "@@", " ", RowBox[{"FilterRules", "[", RowBox[{ RowBox[{"{", "opts", "}"}], ",", " ", RowBox[{"Options", "[", "Plot", "]"}]}], "]"}]}], ",", " ", "\n", " ", RowBox[{"Axes", "->", " ", "Automatic"}]}], "]"}]}], "]"}], "\n", " ", "]"}]}]}], "]"}]}], "\n"}], "Input", InitializationCell->True] }, Closed]] }, Open ]] }, WindowSize->{708, 729}, WindowMargins->{{Automatic, 910}, {Automatic, 119}}, 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[567, 22, 211, 3, 92, "Title"], Cell[781, 27, 152, 4, 49, "Subsubtitle"], Cell[936, 33, 1276, 37, 125, "Text"], Cell[2215, 72, 3740, 100, 295, "Input"], Cell[CellGroupData[{ Cell[5980, 176, 151, 2, 44, "Subsection"], Cell[6134, 180, 5252, 137, 454, "Input", InitializationCell->True] }, Closed]] }, Open ]] } ] *)