(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 12337, 385] NotebookOptionsPosition[ 10892, 335] NotebookOutlinePosition[ 11311, 351] CellTagsIndexPosition[ 11268, 348] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Adapted from Patrick Van Fleet's DE class ", "Title", CellChangeTimes->{{3.4429223375371523`*^9, 3.4429223407715273`*^9}, { 3.460980908714895*^9, 3.460980951241517*^9}}], Cell["Slope Fields", "Subtitle", CellChangeTimes->{{3.4429223442090273`*^9, 3.4429223470840273`*^9}}], Cell[CellGroupData[{ Cell["Preliminaries", "Section"], Cell[TextData[{ "This ", StyleBox["Mathematica", FontSlant->"Italic"], " notebook shows you how to use slope fields to obtain graphical solutions \ to first order differential equations.\n\nThe first thing you need to do is \ to execute the cell below. It contains code for plotting slope fields and \ solutions." }], "Text", CellChangeTimes->{{3.4429223595840273`*^9, 3.4429224243809023`*^9}}], Cell["\<\ SlopeField[func_,xlist_,ylist_,initcond_:Automatic]:= Block[{g,unit,param1,param2,x,y,z,r,s,u,lines,xmin,xmax,ymin,ymax,vector, scale,j,k,m,totalplot,forth,back,tmin,tmax,funclist},funclist={1,func}; param1=xlist[[1]]; param2=ylist[[1]]; xmin=xlist[[2]]; xmax=xlist[[3]]; ymin=ylist[[2]]; ymax=ylist[[3]]; n=20; scale=4.; r=N[(xmax-xmin)/n]; s=N[(ymax-ymin)/n]; u=Min[r,s]/scale; unit[vector_]=vector/Sqrt[(vector.vector)]; g[x_,y_]=funclist/.{param1\[Rule]x,param2\[Rule]y}; lines= Table[Graphics[ Line[{{x=xmin+(j-1/2)r,y=ymin+(k-1/2)s}-(z=u unit[g[x,y]]),{x,y}+ z}]],{j,1,n},{k,1,n}]; If[initcond===Automatic,Return[Show[lines,Axes\[Rule]Automatic]]]; Clear[j,k]; step=0.1; init=initcond; length=Length[init]; For[j=1,j\[LessEqual]length,j++,Clear[forth,back]; numstepback=Round[(init[[j]][[1]]-xmin)/step]; numstepforth=Round[(xmax-init[[j]][[1]])/step]; forth[0]=Take[init[[j]],2]; forth[k_]:=forth[k]=forth[k-1]+step Apply[g,forth[k-1]]; back[0]=Take[init[[j]],2]; back[k_]:=back[k]=back[k-1]-step Apply[g,back[k-1]]; plot[j]= Show[ListPlot[Table[forth[k],{k,0,Abs[numstepforth]}], PlotRange\[Rule]{{xmin,xmax},{ymin,ymax}},Joined\[Rule]True, DisplayFunction\[Rule]Identity, PlotStyle\[Rule]RGBColor[1-(j-1)/length,0,(j-1)/length]], ListPlot[Table[back[k],{k,0,Abs[numstepback]}], PlotRange\[Rule]{{xmin,xmax},{ymin,ymax}},Joined\[Rule]True, DisplayFunction\[Rule]Identity, PlotStyle\[Rule]RGBColor[1-(j-1)/length,0,(j-1)/length]]]]; totalplot=Table[plot[m],{m,1,length}]; Show[totalplot,lines,DisplayFunction\[Rule]$DisplayFunction]] \ \>", "Input", CellChangeTimes->{{3.4429224521777773`*^9, 3.4429224859277773`*^9}}, TextAlignment->Left, TextJustification->0] }, Open ]], Cell[CellGroupData[{ Cell["Direction Fields - How to Use the SlopeField Command", "Section", CellChangeTimes->{{3.4429225059434023`*^9, 3.4429225129434023`*^9}}], Cell[TextData[{ "Using the ", StyleBox["SlopeField", FontWeight->"Bold"], " command is straightforward. Let's illustrate the process with the \ differential equation" }], "Text", CellChangeTimes->{{3.4429225293965273`*^9, 3.4429225732715273`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{ SuperscriptBox["y", "'"], "=", RowBox[{"x", "-", "y"}]}]], "Text", TextAlignment->Center], Cell[TextData[{ StyleBox["SlopeField", FontWeight->"Bold"], " requires three arguments and a fourth list is optional. The first \ argument is the right hand side of your differential equation - in this case \ x-y. The second argument is the x-range you would like ", StyleBox["SlopeField", FontWeight->"Bold"], " to use while the third argument is the y-range you would like ", StyleBox["SlopeFields", FontWeight->"Bold"], " to use. An example call is given below. Go ahead and execute the cell. \ Try changing the x,y ranges and the function.\n" }], "Text", CellChangeTimes->{{3.4429225804277773`*^9, 3.4429226206777773`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{ RowBox[{"x", "-", "y"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "4"}], ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{"-", "8"}], ",", "8"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.4429226308340273`*^9, 3.4429226354434023`*^9}, { 3.460980805776059*^9, 3.460980823210434*^9}, {3.4609809725048285`*^9, 3.460980977738686*^9}}], Cell[TextData[{ "\nThe fourth optional argument lets you give a list of ordered pairs that \ represent initial conditions and in addition to plotting the direction \ fields, it will use Euler's method to plot solutoins using the \ initialconditions.For example,suppose y(0)=2 is our initial condition. ", StyleBox["SlopeField", FontWeight->"Bold"], " would then have a fourth argument. Go ahead and execute the cell below to \ see the result.\n" }], "Text", CellChangeTimes->{{3.4429226514277773`*^9, 3.4429226537402773`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{ RowBox[{"x", "-", "y"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "4"}], ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{"-", "8"}], ",", "8"}], "}"}], ",", StyleBox[ RowBox[{"{", RowBox[{"{", RowBox[{"0", ",", "2"}], "}"}], "}"}], FontColor->GrayLevel[0]]}], "]"}]], "Input", CellChangeTimes->{{3.4429226597871523`*^9, 3.4429226662559023`*^9}, { 3.4609808429412727`*^9, 3.4609808517210965`*^9}, {3.460980986987798*^9, 3.4609809877533493`*^9}}], Cell[TextData[{ "\nIt may seem strange that there are two sets of { } around 0,2. That's \ because ", StyleBox["SlopeField", FontWeight->"Bold"], " will let you enter more than one initial condition. Suppose in addition to \ y(0)=2 as an initial condition, you were also interested in y(0)=3 and \ y(0)=4. Then your call would look like:\n " }], "Text", CellChangeTimes->{{3.4429226897246523`*^9, 3.4429226933496523`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{ RowBox[{"x", "-", "y"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "4"}], ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{"-", "8"}], ",", "8"}], "}"}], ",", StyleBox[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "4"}], "}"}]}], "}"}], FontColor->GrayLevel[0]]}], "]"}]], "Input", CellChangeTimes->{{3.4429227035996523`*^9, 3.4429227077246523`*^9}, 3.4609808741092854`*^9, {3.4609809965629015`*^9, 3.4609810021387773`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["A Simple Example", "Section", CellChangeTimes->{{3.4429232982090273`*^9, 3.4429233016934023`*^9}}], Cell["\<\ Consider the differential equation (we know the answer) \ \>", "Text", CellChangeTimes->{{3.4429227215215273`*^9, 3.4429227246777773`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{ SuperscriptBox["y", "'"], "=", "y"}]], "Text", CellChangeTimes->{3.4429227305527773`*^9}, TextAlignment->Center], Cell["\<\ Plot the slopefield and solutions that satisfy y(0) = 1 and y(0) = -2\ \>", "Text", CellChangeTimes->{{3.4429227373652773`*^9, 3.4429227609590273`*^9}}], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{"y", ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "4"}], ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{"-", "6"}], ",", "6"}], "}"}], ",", StyleBox[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1"}]}], "}"}]}], "}"}], FontColor->GrayLevel[0]]}], "]"}]], "Input", CellChangeTimes->{{3.4429227731621523`*^9, 3.4429227956777773`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Problems 1-6 in section 1.3", "Section", CellChangeTimes->{{3.4429228480527773`*^9, 3.4429228512871523`*^9}, { 3.4429229455215273`*^9, 3.4429229645684023`*^9}, 3.4429231981621523`*^9, { 3.4609811087051673`*^9, 3.460981160777913*^9}, {3.4609813280305786`*^9, 3.460981329545893*^9}}], Cell[TextData[{ "Use ", StyleBox["SlopeField", FontWeight->"Bold"], " to solve problems 1-6 c. As shown below\"" }], "Text", CellChangeTimes->{{3.4429228580371523`*^9, 3.4429228708965273`*^9}, { 3.4429229492090273`*^9, 3.4429229605215273`*^9}, 3.4429232010996523`*^9, { 3.460981170461507*^9, 3.460981220660009*^9}, {3.460981275356696*^9, 3.460981280995047*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell[BoxData[ RowBox[{"SlopeField", "[", RowBox[{ RowBox[{ RowBox[{"x", "^", "2"}], "-", "x"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{"-", "3"}], ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", ".5"}], "}"}]}], "}"}]}], "]"}]], "Input", CellChangeTimes->{{3.4429228761621523`*^9, 3.4429229097090273`*^9}, { 3.4429229749121523`*^9, 3.4429231021934023`*^9}, {3.4429232072090273`*^9, 3.4429232639121523`*^9}, {3.4609812315930986`*^9, 3.460981261940233*^9}}, FontColor->RGBColor[0, 0, 1]] }, Open ]], Cell[CellGroupData[{ Cell["Problem 7-10 in section 1.3", "Section", CellChangeTimes->{{3.4429228480527773`*^9, 3.4429228512871523`*^9}, { 3.4429229455215273`*^9, 3.4429229645684023`*^9}, {3.46098133481044*^9, 3.460981342246417*^9}}], Cell["\<\ Answer the exercises without using any technology, and then confirm your \ answers below :-)\ \>", "Text", CellChangeTimes->{{3.4429228580371523`*^9, 3.4429228708965273`*^9}, { 3.4429229492090273`*^9, 3.4429229605215273`*^9}, {3.4609813496511497`*^9, 3.4609813883463483`*^9}}, FontSize->12, FontColor->GrayLevel[0]], Cell["", "Text", CellChangeTimes->{{3.4429231065059023`*^9, 3.4429231278340273`*^9}, 3.46098139651655*^9}] }, Open ]] }, Open ]] }, WindowSize->{1016, 668}, WindowMargins->{{104, Automatic}, {Automatic, 38}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (June 19, 2007)", StyleDefinitions->FrontEnd`FileName[{"Creative"}, "PastelColor.nb", CharacterEncoding -> "WindowsANSI"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 179, 2, 73, "Title"], Cell[772, 27, 102, 1, 36, "Subtitle"], Cell[CellGroupData[{ Cell[899, 32, 32, 0, 75, "Section"], Cell[934, 34, 401, 9, 65, "Text"], Cell[1338, 45, 1944, 48, 772, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3319, 98, 141, 1, 75, "Section"], Cell[3463, 101, 296, 9, 29, "Text"], Cell[3762, 112, 119, 4, 29, "Text"], Cell[3884, 118, 686, 16, 83, "Text"], Cell[4573, 136, 450, 12, 41, "Input"], Cell[5026, 150, 574, 12, 101, "Text"], Cell[5603, 164, 585, 17, 41, "Input"], Cell[6191, 183, 476, 11, 83, "Text"], Cell[6670, 196, 707, 21, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7414, 222, 105, 1, 75, "Section"], Cell[7522, 225, 191, 6, 47, "Text"], Cell[7716, 233, 140, 4, 29, "Text"], Cell[7859, 239, 163, 3, 29, "Text"], Cell[8025, 244, 564, 18, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8626, 267, 298, 4, 75, "Section"], Cell[8927, 273, 418, 11, 29, "Text"], Cell[9348, 286, 812, 23, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10197, 314, 217, 3, 75, "Section"], Cell[10417, 319, 333, 8, 29, "Text"], Cell[10753, 329, 111, 2, 29, "Text"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)