(* 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[ 8011, 232] NotebookOptionsPosition[ 7465, 208] NotebookOutlinePosition[ 7824, 224] CellTagsIndexPosition[ 7781, 221] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Slope Fields", "Title", CellChangeTimes->{{3.62954850876572*^9, 3.629548513461597*^9}}, TextAlignment->Center], Cell["\<\ by Ruth Dover Illinois Mathematics and Science Academy\ \>", "Subsubtitle", CellChangeTimes->{{3.69318416873153*^9, 3.693184182095831*^9}}], Cell[TextData[{ "This notebook will allow you to draw a slope field. The DE must be in the \ form ", StyleBox["y\[CloseCurlyQuote]", FontSlant->"Italic"], " = ... An example is shown below for the DE ", StyleBox["y\[CloseCurlyQuote] = t + y", FontSlant->"Italic"], ". Some options for the familiar graphics commands may be added. For this \ command, there is also an option for the the number of Marks in each \ direction. The default is Marks \[Rule] { 15, 13 }." }], "Text", CellChangeTimes->{{3.629548653666703*^9, 3.629548856396091*^9}, { 3.62971823245179*^9, 3.6297182344596643`*^9}, 3.69318452748936*^9}], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{ RowBox[{"t", "+", "y"}], ",", " ", RowBox[{"{", RowBox[{"t", ",", " ", RowBox[{"-", "3"}], ",", " ", "3"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"y", ",", " ", RowBox[{"-", "3"}], ",", " ", "3"}], "}"}]}], " ", "]"}]], "Input", CellChangeTimes->{{3.62954836621712*^9, 3.629548391011628*^9}, { 3.629718029968251*^9, 3.629718078912778*^9}, {3.629718138279142*^9, 3.629718227664207*^9}, {3.6931845359703712`*^9, 3.693184538873048*^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->{808, 724}, WindowMargins->{{60, Automatic}, {Automatic, 24}}, 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, 118, 2, 92, "Title"], Cell[701, 26, 150, 4, 49, "Subsubtitle"], Cell[854, 32, 623, 13, 68, "Text"], Cell[1480, 47, 526, 12, 32, "Input"], Cell[CellGroupData[{ Cell[2031, 63, 151, 2, 44, "Subsection"], Cell[2185, 67, 5252, 137, 454, "Input", InitializationCell->True] }, Closed]] }, Open ]] } ] *)