(* 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[ 55236, 1583] NotebookOptionsPosition[ 48279, 1385] NotebookOutlinePosition[ 50860, 1455] CellTagsIndexPosition[ 50533, 1445] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell["First-Order Ordinary Differential Equations", "Title"], Cell[CellGroupData[{ Cell["Background--Simple iteration from a Fixed Boundary Condition", \ "Subtitle", CellChangeTimes->{{3.4032753485708513`*^9, 3.403275361937262*^9}}, CellTags->"mmtag:19:simple_forward_time_interation"], Cell["\<\ Suppose a function, F[i], changes proportional to its current size, i.e., \ F[i+1] = F[i] + \[Alpha]F[i]\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"i_", ",", "\[Alpha]_"}], "]"}], " ", ":=", " ", RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"i", ",", "\[Alpha]"}], "]"}], " ", "=", RowBox[{ RowBox[{"ExplFun", "[", RowBox[{ RowBox[{"i", "-", "1"}], ",", "\[Alpha]"}], "]"}], " ", "+", " ", RowBox[{"\[Alpha]", "*", RowBox[{"ExplFun", "[", RowBox[{ RowBox[{"i", "-", "1"}], ",", "\[Alpha]"}], "]"}]}]}]}]}]], "Input", CellChangeTimes->{{3.403274695626001*^9, 3.4032746957244797`*^9}, { 3.403275056874063*^9, 3.4032750741416597`*^9}}], Cell["\<\ In the above, the symbol is assigned (ExplFun[i,alpha] = ...) as part of the \ function definition, so that intermediate values are ``remembered.'' The function needs some value at some time (an initial condition) from which \ it obtains all its other values:\ \>", "Text", CellChangeTimes->{3.4032746957622347`*^9}], Cell[BoxData[ RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"0", ",", "0.25"}], "]"}], " ", "=", " ", RowBox[{"\[Pi]", "/", "4"}]}]], "Input", CellChangeTimes->{3.403274695823576*^9}], Cell[BoxData[ RowBox[{"ExplFun", "[", RowBox[{"18", ",", "0.25"}], "]"}]], "Input", CellChangeTimes->{3.4032746958905373`*^9}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Background--Simple iteration from a Specified Boundary Condition\ \>", "Subtitle", CellChangeTimes->{{3.4032753485708513`*^9, 3.403275380433255*^9}}, CellTags->"mmtag:19:simple_forward_time_interation"], Cell["\<\ ExplFun[0,0.25] = \[Pi]/4 above serves as an initial value for the function. \ The initial value and \[Alpha] determine the value at any later time. The \ initial value can be expressed as another parameter for the function. We use \ a recursive method to define the function and store computed values in \ memory.\ \>", "Text", CellChangeTimes->{ 3.403274695923868*^9, {3.4032755619402742`*^9, 3.4032755989772587`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"0", " ", ",", " ", "\[Alpha]_", ",", " ", "InitVal_"}], "]"}], " ", ":=", " ", "InitVal"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"Inc_Integer", ",", " ", "\[Alpha]_", ",", " ", "InitVal_"}], "]"}], " ", ":=", " ", RowBox[{ RowBox[{"ExplFun", "[", RowBox[{"Inc", ",", "\[Alpha]", ",", " ", "InitVal"}], "]"}], " ", "=", RowBox[{ RowBox[{"ExplFun", "[", RowBox[{ RowBox[{"Inc", "-", "1"}], ",", "\[Alpha]", ",", " ", "InitVal"}], "]"}], " ", "+", " ", RowBox[{"\[Alpha]", "*", RowBox[{"ExplFun", "[", RowBox[{ RowBox[{"Inc", "-", "1"}], ",", "\[Alpha]", ",", "InitVal"}], "]"}]}]}]}]}]}], "Input", CellChangeTimes->{{3.4031747655681267`*^9, 3.403174792029461*^9}, { 3.403274695974387*^9, 3.4032746961077433`*^9}, {3.403274727024548*^9, 3.40327472719037*^9}, {3.403275079327093*^9, 3.4032750934707327`*^9}, { 3.403275883345147*^9, 3.403275883393779*^9}}], Cell["\<\ One might as well write a function to calculate a vector representing \ `trajectory', here is an implementation to compute a trajectory vector of \ specified length. We use AppendTo to grow an initially empty list. We will \ do the same thing with another method (Nest) below.\ \>", "Text", CellChangeTimes->{{3.4032756346589823`*^9, 3.403275665729513*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Traj", "[", RowBox[{ RowBox[{"Steps_Integer", "?", "Positive"}], ",", "\[Alpha]_", ",", " ", "InitVal_"}], "]"}], " ", ":=", RowBox[{ RowBox[{"Traj", "[", RowBox[{"Steps", ",", "\[Alpha]", ",", "InitVal"}], "]"}], "=", " ", RowBox[{"AppendTo", "[", RowBox[{ RowBox[{"Traj", "[", RowBox[{ RowBox[{"Steps", "-", "1"}], ",", "\[Alpha]", ",", "InitVal"}], "]"}], ",", RowBox[{"ExplFun", "[", RowBox[{"Steps", ",", "\[Alpha]", ",", "InitVal"}], "]"}]}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Traj", "[", RowBox[{"0", ",", "_", ",", "_"}], "]"}], " ", "=", " ", RowBox[{"{", "}"}]}], ";"}]}], "Input", CellChangeTimes->{{3.403174814839148*^9, 3.403174966936651*^9}, { 3.403175010198606*^9, 3.403175013196642*^9}, 3.403274696159953*^9, { 3.403274726243259*^9, 3.403274745739922*^9}, {3.403275096214697*^9, 3.403275103799019*^9}}], Cell[BoxData[ RowBox[{"Traj", "[", RowBox[{"12", ",", ".01", ",", ".001"}], "]"}]], "Input", CellChangeTimes->{{3.403174977768092*^9, 3.403175000409972*^9}, { 3.403181847056963*^9, 3.403181853409884*^9}, {3.403186724403109*^9, 3.4031867244700603`*^9}, 3.403274745802433*^9}], Cell[CellGroupData[{ Cell["\<\ We define a function, Evolve, producing an interactive tool with input : \ Initial values and \[Alpha].\ \>", "Section", CellChangeTimes->{{3.403262045667363*^9, 3.403262112103406*^9}, { 3.403262164375527*^9, 3.403262195392661*^9}, {3.4032627458100863`*^9, 3.4032627500078793`*^9}, {3.403262940601548*^9, 3.403263075312104*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"Evolve", "[", RowBox[{"NumSteps_Integer", "/;", RowBox[{"(", RowBox[{ RowBox[{"NumSteps", ">", "0"}], " ", "&&", " ", RowBox[{"NumSteps", " ", "<", " ", "10000"}]}], ")"}]}], "]"}], " ", ":=", " ", "\[IndentingNewLine]", RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"Block", "[", RowBox[{ RowBox[{"{", RowBox[{"$RecursionLimit", "=", RowBox[{"4", "*", "NumSteps"}]}], "}"}], ",", RowBox[{ RowBox[{"UpBound", "=", "\[IndentingNewLine]", RowBox[{"N", "[", RowBox[{"Last", "[", RowBox[{"Traj", "[", RowBox[{"NumSteps", ",", "\[Alpha]", ",", "InitVal"}], "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"yrange", "=", RowBox[{"{", RowBox[{ RowBox[{"Min", "[", RowBox[{"{", RowBox[{"0", ",", "InitVal", ",", RowBox[{"1.05", "UpBound"}]}], "}"}], "]"}], ",", RowBox[{"Max", "[", RowBox[{"{", RowBox[{"0", ",", "InitVal", ",", RowBox[{"1.05", "UpBound"}]}], "}"}], "]"}]}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Traj", "[", RowBox[{"step", ",", "\[Alpha]", ",", " ", "InitVal"}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "NumSteps"}], "}"}], ",", "yrange"}], "}"}]}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Red", ",", RowBox[{"PointSize", "[", "0.025", "]"}]}], "}"}]}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"{", "Large", "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", "Full"}]}], "]"}]}]}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"step", ",", RowBox[{"Quotient", "[", RowBox[{"NumSteps", ",", "10"}], "]"}]}], "}"}], ",", "1", ",", "NumSteps", ",", "1", ",", RowBox[{"Appearance", "\[Rule]", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"\[Alpha]", ",", "0.001"}], "}"}], ",", RowBox[{"-", "1"}], ",", "1", ",", RowBox[{"Appearance", "\[Rule]", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"InitVal", ",", ".01"}], "}"}], ",", RowBox[{"-", "1"}], ",", "1", ",", RowBox[{"Appearance", "\[Rule]", "\"\\""}]}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4031750283405933`*^9, 3.403175164705764*^9}, { 3.4031752077736197`*^9, 3.403175331172785*^9}, {3.4031754217598133`*^9, 3.403175435687518*^9}, {3.403175502129835*^9, 3.4031755199493*^9}, { 3.403175561695414*^9, 3.4031756382219687`*^9}, 3.403175673326358*^9, { 3.403175767549919*^9, 3.403175771158354*^9}, {3.403175817431535*^9, 3.403175852878125*^9}, {3.403175884166383*^9, 3.403175943230555*^9}, { 3.40317597860921*^9, 3.403175985158554*^9}, {3.403176072642688*^9, 3.403176078363707*^9}, {3.403176133322105*^9, 3.403176219011693*^9}, { 3.403176310441373*^9, 3.403176351199383*^9}, {3.403176388831101*^9, 3.4031764003907948`*^9}, {3.403176435719083*^9, 3.403176508698807*^9}, { 3.403176572592236*^9, 3.403176684807819*^9}, {3.40317686347318*^9, 3.403176867631825*^9}, {3.403177110354437*^9, 3.403177265367358*^9}, { 3.403177309032722*^9, 3.403177388432007*^9}, {3.403177474441968*^9, 3.403177544918687*^9}, {3.40317758478503*^9, 3.403177617919139*^9}, { 3.4031786609639177`*^9, 3.403178688872538*^9}, {3.403178741725286*^9, 3.4031788928964777`*^9}, {3.40317894854813*^9, 3.403178991284039*^9}, { 3.403181629044593*^9, 3.403181684008964*^9}, {3.403184226010421*^9, 3.403184257784274*^9}, {3.403184310242488*^9, 3.4031843170679083`*^9}, { 3.4031843674347973`*^9, 3.403184371960998*^9}, 3.403184408762035*^9, { 3.403184555281157*^9, 3.4031846138736143`*^9}, {3.403184668185526*^9, 3.403184668616168*^9}, 3.403194508117491*^9, {3.40319453990311*^9, 3.403194570779512*^9}, {3.4031946138062067`*^9, 3.4031946452699337`*^9}, { 3.403194691645056*^9, 3.403194719198368*^9}, {3.403194817681953*^9, 3.403194871375824*^9}, {3.403194928070528*^9, 3.403195119615567*^9}, { 3.4031951924468307`*^9, 3.403195203403051*^9}, {3.4032747266217213`*^9, 3.403274745889099*^9}}] }, Open ]], Cell[BoxData[ RowBox[{"Evolve", "[", "300", "]"}]], "Input", CellChangeTimes->{{3.403175338375745*^9, 3.403175344129178*^9}, { 3.40317626854675*^9, 3.403176269001976*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Visualizing Trajectories: Initial Conditions Define a Set of Curves that \ \"Cover\" the Plane.\ \>", "Subtitle", CellChangeTimes->{{3.4032753485708513`*^9, 3.403275380433255*^9}, { 3.4032760379239063`*^9, 3.4032760860261927`*^9}}, CellTags->"mmtag:19:simple_forward_time_interation"], Cell["\<\ Plotting a bunch of curves for the same positive \[Alpha] value, but each \ corresponding to a different initial value, demonstrates that a point in \ space \"belongs\" to a curve. Here we make a function to demonstrate for a \ range of inital values and a function of \[Alpha]\ \>", "Text", CellChangeTimes->{{3.403276128876009*^9, 3.4032761546897984`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PlotTrajs", "[", "\[Alpha]_", "]"}], " ", ":=", " ", RowBox[{"Block", "[", RowBox[{ RowBox[{"{", RowBox[{"$RecursionLimit", "=", RowBox[{"10", "^", "4"}]}], "}"}], ",", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Traj", "[", RowBox[{"300", ",", "\[Alpha]", ",", "iv"}], "]"}], ",", RowBox[{"{", RowBox[{"iv", ",", RowBox[{"-", "1"}], ",", "1", ",", "0.25"}], "}"}]}], "]"}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"Joined", "\[Rule]", "True"}], ",", RowBox[{"PlotStyle", "\[Rule]", "Thick"}]}], "]"}]}], "]"}]}]], "Input",\ CellChangeTimes->{{3.4031867505767307`*^9, 3.403187042717093*^9}, { 3.403187080440357*^9, 3.4031871342209997`*^9}, {3.403187167368017*^9, 3.4031871764779863`*^9}, {3.403187218638836*^9, 3.403187291645355*^9}, 3.403274745955571*^9, {3.403276172179634*^9, 3.403276204149735*^9}, { 3.403276239661459*^9, 3.403276250883306*^9}}, CellTags->"mmtag:19:MultipleListPlot[]"], Cell[BoxData[ RowBox[{"PlotTrajs", "[", "0.02", "]"}]], "Input", CellChangeTimes->{{3.4032762158118467`*^9, 3.4032762237618856`*^9}, { 3.4032762555143423`*^9, 3.4032762743542213`*^9}}], Cell["\<\ Making a similar plot for a family of curves corresponding to a negative \ \[Alpha] value \ \>", "Text"], Cell[BoxData[ RowBox[{"PlotTrajs", "[", RowBox[{"-", "0.02"}], "]"}]], "Input", CellChangeTimes->{{3.403187258609851*^9, 3.403187318526911*^9}, 3.403274746003443*^9, {3.4032762962970057`*^9, 3.403276301579832*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Finite Differencing Methods (Method 1): Explicit Forward Differences\ \>", "Subtitle", CellChangeTimes->{{3.403187451860015*^9, 3.4031874577466793`*^9}, { 3.403276699458877*^9, 3.4032767171454353`*^9}}], Cell[TextData[{ "Approximation to ", Cell[BoxData[ FormBox[ FractionBox["dy", "dt"], TraditionalForm]]], "= f(y)\n", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{"Approximate", " ", FractionBox["dy", "dt"]}], "=", " ", RowBox[{ RowBox[{ RowBox[{"f", "(", "y", ")"}], " ", "with", " ", "a", " ", "finite", " ", "difference", " ", FractionBox[ RowBox[{ RowBox[{"y", RowBox[{"(", RowBox[{"t", " ", "+", " ", "\[CapitalDelta]t"}], ")"}]}], " ", "-", " ", RowBox[{"y", "(", "t", ")"}]}], RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"t", " ", "+", " ", "\[CapitalDelta]t"}], ")"}], ")"}], " ", "-", " ", "t"}]]}], "=", " ", RowBox[{"f", "(", RowBox[{"y", "(", "t", ")"}], ")"}]}]}], TraditionalForm]]], "\nIf all the time steps are the same size, \[CapitalDelta]t, then use the \ short-hand ", Cell[BoxData[ FormBox[ SubscriptBox["y", "n"], TraditionalForm]]], " = y(n \[Cross] ", "\[CapitalDelta]t)" }], "Text", CellChangeTimes->{{3.403187366780608*^9, 3.403187408475081*^9}, { 3.4031903908213987`*^9, 3.403190391357399*^9}, {3.403190431777817*^9, 3.403190432915635*^9}, {3.403190653846656*^9, 3.403190654395008*^9}, { 3.403190732459887*^9, 3.4031908379714603`*^9}, {3.403190894868059*^9, 3.403190903766671*^9}, {3.40325803157506*^9, 3.403258032606896*^9}}], Cell[TextData[{ "Approximate f(y) with f(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], "); then solving the finite difference equation above,\n", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], "= ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1", " "}]], TraditionalForm]]], "+ \[CapitalDelta]t f(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], "): the right-hand side depends only on ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ", and therefore we can apply a recursion method to find any ", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]] }], "Text", CellChangeTimes->{{3.403190476244546*^9, 3.403190480779117*^9}, { 3.403190599867593*^9, 3.403190631283914*^9}, {3.403190852491886*^9, 3.403191093467228*^9}, {3.403191130411516*^9, 3.403191141568768*^9}}], Cell["\<\ PushMethod1 takes an arbitrary f for the right-hand-side, the current point \ and the size of the time step \[CapitalDelta]t\ \>", "Text", CellChangeTimes->{{3.403276985885817*^9, 3.40327703275344*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PushMethod1", "[", RowBox[{"f_", ",", " ", RowBox[{"{", RowBox[{"ti_", ",", "yi_"}], "}"}], ",", " ", "\[CapitalDelta]t_"}], "]"}], ":=", RowBox[{"{", RowBox[{ RowBox[{"ti", " ", "+", " ", "\[CapitalDelta]t"}], ",", " ", RowBox[{"yi", " ", "+", RowBox[{"\[CapitalDelta]t", " ", RowBox[{"f", "[", "yi", "]"}]}]}]}], "}"}]}]], "Input", CellChangeTimes->{{3.403191162412652*^9, 3.4031912536922092`*^9}, { 3.4031912866204157`*^9, 3.4031912883802423`*^9}, {3.403191346380714*^9, 3.403191395126889*^9}}, CellTags->"mmtag:19:Module[]"], Cell["Here is an example right-hand-side function:", "Text", CellChangeTimes->{{3.40327704091914*^9, 3.403277062049369*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"FuncEx", "[", "y_", "]"}], " ", ":=", " ", RowBox[{"-", RowBox[{"Sin", "[", "y", "]"}]}]}]], "Input", CellChangeTimes->{{3.403191410540316*^9, 3.4031915871481524`*^9}, 3.403199034426194*^9}], Cell["\<\ Applying it once \"pushes\" the current point (the second argument) forward \ one increment in time.\ \>", "Text", CellChangeTimes->{{3.403276926417704*^9, 3.403276970935679*^9}}], Cell[BoxData[ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", ".01"}], "]"}]], "Input", CellChangeTimes->{{3.4031989384955387`*^9, 3.403198989175926*^9}}], Cell["\<\ Applying it twice \"pushes\" the current point (the second argument) forward \ two increments in time. We have \"nested\" one function call inside the \ other.\ \>", "Text", CellChangeTimes->{{3.403277085731633*^9, 3.403277097041648*^9}, { 3.4032771396334343`*^9, 3.403277151697304*^9}}], Cell[BoxData[ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", ".01"}], "]"}], ",", ".01"}], "]"}]], "Input", CellChangeTimes->{{3.4031989384955387`*^9, 3.403198989175926*^9}, { 3.403199646160087*^9, 3.403199682910522*^9}}], Cell["\<\ Nest is a useful function for these kinds of operatons: Nest[g,x,3] is \ g[g[g[x]]]. However, in our case, PushMethod1 takes three arguments, we need \ to use a Pure Function methods to specify that the PushMethod1 operates only \ on the point represented by the second argument. This should provide a \ useful example of what Nest does: # plays the role of the functions argument \ and the & indicates that the function is to interpreted as a pure function.\ \>", "Text", CellChangeTimes->{{3.403277102709392*^9, 3.403277326065439*^9}}], Cell[BoxData[ RowBox[{"Nest", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", "#", ",", ".01"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", "2"}], "]"}]], "Input", CellChangeTimes->{{3.4031997002089376`*^9, 3.4031998466271877`*^9}}], Cell["\<\ We can use NestList to build up the trajectory,very similar to our method \ above that used AppendTo, but this is more efficient.\ \>", "Text", CellChangeTimes->{{3.403277333922514*^9, 3.4032773802494698`*^9}}], Cell[BoxData[ RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", "#", ",", ".01"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", "2"}], "]"}]], "Input", CellChangeTimes->{{3.4031997002089376`*^9, 3.4031998466271877`*^9}, { 3.40319988159676*^9, 3.403199882443688*^9}}], Cell["\<\ NestListWhile to build up the trajectory while a \"test\" evaluates to True. \ We have to use a pure function for the test, which operates on the current \ point (or the last point entered into the list).\ \>", "Text", CellChangeTimes->{{3.403277333922514*^9, 3.4032774631296177`*^9}}], Cell[BoxData[ RowBox[{"NestWhileList", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", "#", ",", ".01"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"First", "[", "#", "]"}], "<", " ", "0.03"}], ")"}], "&"}]}], "]"}]], "Input", CellChangeTimes->{{3.403199997693364*^9, 3.403199999601717*^9}, { 3.4032000700459013`*^9, 3.403200152412533*^9}, {3.4032001843513727`*^9, 3.4032001878779593`*^9}, {3.403200319015667*^9, 3.403200323220199*^9}, { 3.403200361406909*^9, 3.403200406789937*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Visualizing Trajectories from the Explicit Forward Differences Method\ \>", "Subtitle", CellChangeTimes->{{3.403187451860015*^9, 3.4031874577466793`*^9}, { 3.403276699458877*^9, 3.4032767171454353`*^9}, {3.403277666075876*^9, 3.4032776806894827`*^9}}], Cell[CellGroupData[{ Cell["\<\ A Function PlotM1, taking arguments for \[Alpha] and initial condition is \ used with NestListWhile and ListPlot to produce graphics with a red line and \ green points.\ \>", "Section", CellChangeTimes->{{3.4031874336759443`*^9, 3.4031874652509336`*^9}, { 3.403187678635275*^9, 3.403187682242896*^9}, 3.4032012479615173`*^9, 3.403204979573526*^9, {3.403252721677043*^9, 3.403252731692047*^9}, 3.403252779548194*^9, {3.403260176123034*^9, 3.4032601881205378`*^9}, { 3.403278033692107*^9, 3.40327808692142*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"\[Alpha]_", ",", "InitCond_"}], "]"}], ":=", RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"\[Alpha]", ",", "InitCond"}], "]"}], "=", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"NestWhileList", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod1", "[", RowBox[{"FuncEx", ",", "#", ",", "\[Alpha]"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "InitCond"}], "}"}], ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"First", "[", "#", "]"}], "<", "20"}], ")"}], "&"}]}], "]"}], ",", RowBox[{"Joined", "\[Rule]", "True"}], ",", RowBox[{"PlotStyle", "\[Rule]", " ", RowBox[{"{", RowBox[{ RowBox[{"Thickness", "[", "0.01", "]"}], ",", "Red"}], "}"}]}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"Mesh", "\[Rule]", "Full"}], ",", RowBox[{"MeshStyle", "\[Rule]", " ", RowBox[{"{", RowBox[{"Green", ",", RowBox[{"PointSize", "[", "0.01", "]"}], ",", RowBox[{"Opacity", "[", "0.5", "]"}]}], "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", " ", "Full"}]}], "]"}]}]}]], "Input", CellChangeTimes->{{3.4032778064623423`*^9, 3.403277881077466*^9}, { 3.403278455389357*^9, 3.403278455596676*^9}}] }, Open ]], Cell[BoxData[ RowBox[{"PlotM1", "[", RowBox[{"0.1", ",", " ", "1"}], "]"}]], "Input", CellChangeTimes->{{3.403200469851972*^9, 3.403200590179261*^9}, { 3.4032006204433823`*^9, 3.4032006272495127`*^9}, {3.4032006786806498`*^9, 3.403200705163278*^9}, {3.4032009241932087`*^9, 3.4032010340019836`*^9}, { 3.403257270812997*^9, 3.403257288755719*^9}, {3.4032575214779*^9, 3.403257532931761*^9}, 3.403257721342778*^9, {3.403277893862049*^9, 3.403277899780087*^9}}], Cell[BoxData[ RowBox[{"PlotM1", "[", RowBox[{"1.5", ",", "1"}], "]"}]], "Input", CellChangeTimes->{{3.403200718579453*^9, 3.403200797811775*^9}, { 3.40320084280103*^9, 3.403200857039699*^9}, 3.403201090702104*^9, { 3.403202643364635*^9, 3.4032026884424133`*^9}, 3.403203627340307*^9, { 3.403257294996726*^9, 3.403257304051485*^9}, {3.403257403853121*^9, 3.403257407859931*^9}, {3.403257504883663*^9, 3.403257511483615*^9}, { 3.40325758251725*^9, 3.4032575870277567`*^9}, 3.403257696110866*^9, { 3.403277914807283*^9, 3.403277923471532*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Finite Differencing Methods (Method 2): Implicit Forward Differences\ \>", "Subtitle", CellChangeTimes->{{3.403187451860015*^9, 3.4031874577466793`*^9}, { 3.403276699458877*^9, 3.4032767171454353`*^9}, {3.403278274173345*^9, 3.403278281049814*^9}}], Cell[TextData[{ "Approximate f(y) with f(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "\.10"}]], TraditionalForm]]], "); then solving the finite difference equation above,\n", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], "= ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1", " "}]], TraditionalForm]]], "+ ", Cell[BoxData[ FormBox["\[CapitalDelta]t", TraditionalForm]]], " [f(", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], ") ]. So, ", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], "= ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], " + ", Cell[BoxData[ FormBox["\[CapitalDelta]t", TraditionalForm]]], " (f(", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], ") + f'(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ")dy)\n ", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], "= ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], " + ", Cell[BoxData[ FormBox["\[CapitalDelta]t", TraditionalForm]]], " (f(", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], ") + f'(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ")(", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], " - ", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ") )\n", Cell[BoxData[ FormBox[ SubscriptBox["y", "i"], TraditionalForm]]], " = ", Cell[BoxData[ FormBox[ RowBox[{"(", SubscriptBox["y", RowBox[{"i", "-", "1"}]]}], TraditionalForm]]], " - ", Cell[BoxData[ FormBox["\[CapitalDelta]t", TraditionalForm]]], " [f(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ") - f'(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ")", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], "])/(1 - ", Cell[BoxData[ FormBox[ RowBox[{"\[CapitalDelta]t", " "}], TraditionalForm]]], "f'(", Cell[BoxData[ FormBox[ SubscriptBox["y", RowBox[{"i", "-", "1"}]], TraditionalForm]]], ") )" }], "Text", CellChangeTimes->{{3.403190476244546*^9, 3.403190480779117*^9}, { 3.403190599867593*^9, 3.403190631283914*^9}, {3.403190852491886*^9, 3.403191093467228*^9}, {3.403191130411516*^9, 3.403191141568768*^9}, { 3.403201257472136*^9, 3.403201259162171*^9}, {3.403201358579496*^9, 3.403201373447661*^9}, 3.4032014522913218`*^9, {3.403201482797254*^9, 3.403201489299288*^9}, {3.4032015286027*^9, 3.403201585251893*^9}, { 3.40320170283475*^9, 3.403201739316948*^9}, {3.403201786827407*^9, 3.403201790299285*^9}, {3.4032019633614397`*^9, 3.403201992786119*^9}, { 3.4032020270704308`*^9, 3.403202055224841*^9}, 3.4032027968085327`*^9, { 3.403202845424107*^9, 3.4032030472488613`*^9}, {3.403203080544199*^9, 3.403203173337225*^9}, {3.40320320627711*^9, 3.403203217632349*^9}, { 3.403203278861904*^9, 3.4032033233531427`*^9}, {3.403204993181739*^9, 3.403205034373501*^9}, {3.4032050737970343`*^9, 3.403205138805653*^9}, { 3.403205333444849*^9, 3.403205418805533*^9}, {3.4032054868178177`*^9, 3.40320549623715*^9}, {3.403205545077937*^9, 3.403205567165654*^9}, { 3.403252816375252*^9, 3.403252848437193*^9}, 3.403252978948182*^9, { 3.403253063984182*^9, 3.4032530894773417`*^9}, 3.4032531200744*^9, { 3.403256825954529*^9, 3.403256869135971*^9}, {3.403256907042158*^9, 3.403256950550344*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PushMethod2", "[", RowBox[{"f_", ",", "df_", ",", " ", RowBox[{"{", RowBox[{"ti_", ",", "yi_"}], "}"}], ",", " ", "\[CapitalDelta]t_"}], "]"}], ":=", RowBox[{"{", RowBox[{ RowBox[{"ti", " ", "+", " ", "\[CapitalDelta]t"}], ",", " ", RowBox[{ RowBox[{"(", RowBox[{"yi", " ", "+", RowBox[{"(", RowBox[{"\[CapitalDelta]t", " ", RowBox[{"(", RowBox[{ RowBox[{"f", "[", "yi", "]"}], " ", "-", " ", RowBox[{ RowBox[{"df", "[", "yi", "]"}], " ", "yi"}]}], ")"}]}], ")"}]}], ")"}], "/", RowBox[{"(", RowBox[{"1", " ", "-", " ", RowBox[{"\[CapitalDelta]t", " ", RowBox[{"df", "[", "yi", "]"}]}]}], ")"}]}]}], "}"}]}]], "Input", CellChangeTimes->{{3.403191162412652*^9, 3.4031912536922092`*^9}, { 3.4031912866204157`*^9, 3.4031912883802423`*^9}, {3.403191346380714*^9, 3.403191395126889*^9}, 3.4032019513333282`*^9, {3.4032021101009502`*^9, 3.4032021467453747`*^9}, {3.403203435928697*^9, 3.403203481860881*^9}, { 3.403203512461975*^9, 3.403203521625983*^9}, {3.4032048732229033`*^9, 3.4032048762938623`*^9}, {3.4032056199498577`*^9, 3.403205668991247*^9}, 3.403252983216427*^9, {3.403256968827715*^9, 3.4032569980591383`*^9}, { 3.4032570375323877`*^9, 3.403257049411208*^9}, 3.403257313596336*^9}, CellTags->"mmtag:19:Module[]"], Cell[BoxData[ RowBox[{ RowBox[{"dFuncEx", "[", "y_", "]"}], " ", ":=", RowBox[{"Evaluate", "[", RowBox[{"D", "[", RowBox[{ RowBox[{"FuncEx", "[", "y", "]"}], ",", "y"}], "]"}], "]"}]}]], "Input", CellChangeTimes->{{3.4032021783847218`*^9, 3.403202203241425*^9}, { 3.40320241411302*^9, 3.403202457742957*^9}, {3.403204631212748*^9, 3.403204648242969*^9}}], Cell[BoxData[ RowBox[{"NestList", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod2", "[", RowBox[{"FuncEx", ",", "dFuncEx", ",", "#", ",", "0.1"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}], ",", "3"}], "]"}]], "Input", CellChangeTimes->{{3.4032023072606697`*^9, 3.403202372331348*^9}, { 3.4032024983317127`*^9, 3.403202520050356*^9}, 3.4032056879491167`*^9, 3.403257318697824*^9}], Cell[CellGroupData[{ Cell["\<\ We define a function, PlotM2, which takes arguments \[CapitalDelta]t and \ InitialCondition and then uses ListPlot with Blue lines and Gray points.\ \>", "Section", CellChangeTimes->{{3.403262045667363*^9, 3.403262112103406*^9}, { 3.403262164375527*^9, 3.403262195392661*^9}, {3.403272230381174*^9, 3.403272342552885*^9}, {3.4032728895150757`*^9, 3.403272902689054*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PlotM2", "[", RowBox[{"\[Alpha]_", ",", "InitCond_"}], "]"}], ":=", RowBox[{ RowBox[{"PlotM2", "[", RowBox[{"\[Alpha]", ",", "InitCond"}], "]"}], "=", RowBox[{"ListPlot", "[", RowBox[{ RowBox[{"NestWhileList", "[", RowBox[{ RowBox[{ RowBox[{"PushMethod2", "[", RowBox[{"FuncEx", ",", "dFuncEx", ",", "#", ",", "\[Alpha]"}], "]"}], "&"}], ",", RowBox[{"{", RowBox[{"0", ",", "InitCond"}], "}"}], ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"First", "[", "#", "]"}], "<", " ", "20"}], ")"}], "&"}]}], "]"}], ",", RowBox[{"Joined", "\[Rule]", "True"}], ",", RowBox[{"PlotStyle", "\[Rule]", " ", RowBox[{"{", RowBox[{"Thick", ",", "Blue"}], "}"}]}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}], ",", RowBox[{"Mesh", "\[Rule]", "Full"}], ",", RowBox[{"MeshStyle", "\[Rule]", " ", RowBox[{"{", RowBox[{"Black", ",", RowBox[{"PointSize", "[", "0.01", "]"}], ",", RowBox[{"Opacity", "[", "0.5", "]"}]}], "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", " ", "Full"}]}], "]"}]}]}]], "Input", CellChangeTimes->{{3.403200469851972*^9, 3.403200590179261*^9}, { 3.4032006204433823`*^9, 3.4032006272495127`*^9}, {3.4032006786806498`*^9, 3.403200705163278*^9}, {3.4032009241932087`*^9, 3.4032010340019836`*^9}, { 3.4032022303315077`*^9, 3.403202260123616*^9}, 3.403205708063888*^9, { 3.403257322667644*^9, 3.403257341251869*^9}, {3.403257564989403*^9, 3.403257574003996*^9}, {3.403278399286873*^9, 3.403278435036832*^9}, { 3.403278491735824*^9, 3.403278494620864*^9}}] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Visual Comparison of Trajectories from the Explicit and Implicit Methods\ \>", "Subtitle", CellChangeTimes->{{3.403187451860015*^9, 3.4031874577466793`*^9}, { 3.403276699458877*^9, 3.4032767171454353`*^9}, {3.403277666075876*^9, 3.4032776806894827`*^9}, {3.403278875492322*^9, 3.403278897041861*^9}}], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"0.1", ",", "1"}], "]"}], ",", RowBox[{"PlotM2", "[", RowBox[{"0.1", ",", "1"}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.4032573643619747`*^9, 3.4032573816049747`*^9}, { 3.403257451312459*^9, 3.4032574945882063`*^9}, {3.403257605618466*^9, 3.403257628400093*^9}, {3.403278535788974*^9, 3.4032785420587807`*^9}}], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"1.5", ",", "1.0"}], "]"}], ",", RowBox[{"PlotM2", "[", RowBox[{"1.5", ",", "1.0"}], "]"}], ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.5"}], ",", "1"}], "}"}]}], "}"}]}]}], "]"}]], "Input",\ CellChangeTimes->{{3.403257889595454*^9, 3.403257895241869*^9}, { 3.4032579587952137`*^9, 3.403257959713613*^9}, {3.403278559987936*^9, 3.40327859747507*^9}}], Cell["Method 2 will fail if the step size is increased to 2", "Text", CellChangeTimes->{{3.4032581115880213`*^9, 3.4032581231921797`*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Intuitive Understanding of First-Order ODEs", "Subtitle", CellChangeTimes->{{3.403279778875876*^9, 3.403279789649983*^9}}, CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[TextData[{ "Newton's law of cooling ", Cell[BoxData[ FormBox[ FractionBox["dT", "dt"], TraditionalForm]]], "= -k(T - ", Cell[BoxData[ FormBox[ SubscriptBox["T", "o"], TraditionalForm]]], ") can be written in the non-dimensional form ", Cell[BoxData[ FormBox[ FractionBox["d\[CapitalTheta]", "d\[Tau]"], TraditionalForm]]], "= 1-\[CapitalTheta] (i.e, defining \[CapitalTheta] as T/", Cell[BoxData[ FormBox[ SubscriptBox["T", "o"], TraditionalForm]]], " and \[Tau] = k t)" }], "Text", CellChangeTimes->{{3.403258243114929*^9, 3.4032583068241987`*^9}, { 3.403258360349465*^9, 3.403258363576788*^9}, {3.403258442480503*^9, 3.4032584469285927`*^9}}], Cell[TextData[{ "In the general case, ", Cell[BoxData[ FormBox[ FractionBox["d\[CapitalTheta]", "d\[Tau]"], TraditionalForm]]], " will depend on both \[CapitalTheta] and t, i.e., ", Cell[BoxData[ FormBox[ FractionBox["d\[CapitalTheta]", "d\[Tau]"], TraditionalForm]]], " = ", Cell[BoxData[ FormBox[ FractionBox["d\[CapitalTheta]", "d\[Tau]"], TraditionalForm]]], "(\[CapitalTheta],t). This the equation of a surface in three dimensions, as \ shown in the following plot (in this specific case there is no t \ dependence):" }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"ZeroPlane", "[", RowBox[{"xmin_", ",", " ", "xmax_", ",", "ymin_", ",", "ymax_"}], "]"}], ":=", " ", RowBox[{"Graphics3D", "[", RowBox[{"{", RowBox[{"Gray", ",", RowBox[{"Opacity", "[", "0.25", "]"}], ",", RowBox[{"Cuboid", "[", RowBox[{ RowBox[{"{", RowBox[{"xmin", ",", "ymin", ",", RowBox[{"-", ".001"}]}], "}"}], ",", RowBox[{"{", RowBox[{"xmax", ",", "ymax", ",", ".001"}], "}"}]}], "]"}]}], "}"}], "]"}]}]], "Input", CellChangeTimes->{{3.403258721459298*^9, 3.4032587604061947`*^9}}], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"Plot3D", "[", RowBox[{ RowBox[{"1", "-", "\[CapitalTheta]"}], ",", " ", RowBox[{"{", RowBox[{"tau", ",", "0", ",", "2"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"\[CapitalTheta]", ",", " ", "0", ",", "2"}], "}"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{ "\"\<\[Tau]\>\"", ",", "\"\<\[CapitalTheta]\>\"", ",", "\"\<\!\(\*FractionBox[\(d\[CapitalTheta]\), \(d\[Tau]\)]\)\>\""}], "}"}]}], ",", RowBox[{"DisplayFunction", "->", "Identity"}]}], "]"}], ",", RowBox[{"ZeroPlane", "[", RowBox[{"0", ",", "2", ",", "0", ",", "2"}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.4032587722527514`*^9, 3.403258779524252*^9}, { 3.403354454423736*^9, 3.403354499317279*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Geometry of Flows of First-Order ODEs: Vector Fields (Simple Example: \ Newton's Law of Cooling)\ \>", "Subtitle", CellChangeTimes->{{3.403279778875876*^9, 3.4032798167300043`*^9}, { 3.4032806927394857`*^9, 3.4032807024178133`*^9}, {3.403354929157462*^9, 3.403354941451804*^9}}, CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[TextData[{ "Plot the vector (d\[Tau],d\[CapitalTheta]) = d\[Tau](1, ", Cell[BoxData[ FractionBox["d\[CapitalTheta]", "d\[Tau]"]]], ") at each point:", "\n", "We want to make a plot of", Cell[BoxData[ FractionBox["d\[CapitalTheta]", "d\[Tau]"]]], "in the \[CapitalTheta]-\[Tau] plane. We can do so by plotting vectors of \ the form {d\[Tau], d\[CapitalTheta]} = d\[Tau]{1, ", Cell[BoxData[ FractionBox["d\[CapitalTheta]", "d\[Tau]"]]], "} which will be proportional to the vector {1, 1-\[CapitalTheta]}. This is \ done as follows:" }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"Needs", "[", "\"\\"", "]"}], ";", RowBox[{"VectorFieldPlots`VectorFieldPlot", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", RowBox[{"1", "-", "\[CapitalTheta]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"tau", ",", "0", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"\[CapitalTheta]", ",", RowBox[{"-", "2"}], ",", "4"}], "}"}], ",", RowBox[{"Axes", "\[Rule]", "True"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\<\[Tau]\>\"", ",", "\"\<\[CapitalTheta]\>\""}], "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", " ", "Large"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4032797501733027`*^9, 3.403279763211563*^9}, { 3.403359721407921*^9, 3.403359722182108*^9}}], Cell[TextData[{ "Note in the equations and the plot that", Cell[BoxData[ FractionBox["d\[CapitalTheta]", "d\[Tau]"]]], "is independent of \[Tau]." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ Geometry of Flows of First-Order ODEs: Vector Fields (More Complex Example)\ \>", "Subtitle", CellChangeTimes->{{3.403279778875876*^9, 3.4032798167300043`*^9}, { 3.4032806927394857`*^9, 3.4032807024178133`*^9}, {3.403354948019534*^9, 3.403354956851575*^9}}, CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[TextData[{ "Slightly more complicated example: ", Cell[BoxData[ FormBox[ FractionBox["dy", "dt"], TraditionalForm]]], "= y sin(", Cell[BoxData[ FormBox[ FractionBox["yt", RowBox[{"1", " ", "+", " ", "t", " ", "+", "y"}]], TraditionalForm]]], "),\n(dt,dy) = dt(1,ysin", Cell[BoxData[ FormBox[ FractionBox["yt", RowBox[{"1", " ", "+", " ", "t", " ", "+", "y"}]], TraditionalForm]]], "))" }], "Text"], Cell["\<\ As in the simpler example above we first plot the derivative's value as a \ surface using Plot3D, then we represent the behavior as a vector field\ \>", "Text"], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"Plot3D", "[", RowBox[{ RowBox[{"y", " ", RowBox[{"Sin", "[", " ", FractionBox[ RowBox[{"y", " ", "t"}], RowBox[{"t", "+", "y", "+", "1"}]], "]"}]}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\"", ",", "\"\<\!\(\*FractionBox[\(dy\), \(dt\)]\)\>\""}], "}"}]}], ",", RowBox[{"PlotPoints", "\[Rule]", "40"}]}], "]"}], ",", RowBox[{"ZeroPlane", "[", RowBox[{"0", ",", "10", ",", "0", ",", "10"}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.403258996357955*^9, 3.403259005232738*^9}}], Cell[BoxData[ RowBox[{"VectorFieldPlot", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", RowBox[{"y", " ", RowBox[{"Sin", "[", FractionBox[ RowBox[{"y", " ", "t"}], RowBox[{"t", "+", "y", "+", "1"}]], "]"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"Axes", "\[Rule]", "True"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.403259072590465*^9, 3.4032591061625767`*^9}}], Cell["\<\ To summarize this part, we have seen how first-order differential equations \ have associated trajectories in the plane of the dependent variables, \ analogous to what we simulated above by incrementing a certain functional \ relationship. Numerical differential equation solvers use similar techniques.\ \ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Using ", StyleBox["Mathematica", FontSlant->"Italic"], "'s DSolve function on Example used for Finite Differencing Examples" }], "Subtitle", CellChangeTimes->{{3.40335560594121*^9, 3.4033556290196543`*^9}}], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], "'s ", StyleBox["DSolve", FontWeight->"Bold"], " function finds closed-form expressions for solutions to differential \ equations, when possible. There is a related function called ", StyleBox["NDSolve", FontWeight->"Bold"], " that finds numerical solutions that can be used when ", StyleBox["DSolve", FontWeight->"Bold"], " gives up. Here are some examples of using ", StyleBox["DSolve", FontWeight->"Bold"], ":" }], "Text"], Cell[BoxData[ RowBox[{"dsol", " ", "=", " ", RowBox[{"DSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "t", "]"}], "==", RowBox[{"FuncEx", "[", RowBox[{"y", "[", "t", "]"}], "]"}]}], "}"}], ",", RowBox[{"y", "[", "t", "]"}], ",", "t"}], "]"}]}]], "Input", CellChangeTimes->{3.403259870104083*^9}], Cell["\<\ Note that the solution is given as a rule, just like for the function Solve. \ Because no initial condition was specified, the solution involves an unknown \ constant, C[1]. In the next case an initial condition was specified for \ the differential equation, so there is no undetermined constant in the \ solution.\ \>", "Text", CellChangeTimes->{{3.403259931667605*^9, 3.40325995742663*^9}}], Cell[BoxData[ RowBox[{"dsol", " ", "=", " ", RowBox[{"DSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "t", "]"}], "==", RowBox[{"FuncEx", "[", RowBox[{"y", "[", "t", "]"}], "]"}]}], ",", RowBox[{ RowBox[{"y", "[", "0", "]"}], "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"y", "[", "t", "]"}], ",", "t"}], "]"}]}]], "Input", CellChangeTimes->{{3.403259468058898*^9, 3.4032595488673077`*^9}}], Cell[" The next statement extracts y (x) for plotting ...", "Text"], Cell[BoxData[ RowBox[{"ExactPlot", " ", "=", RowBox[{"Plot", "[", " ", RowBox[{ RowBox[{ RowBox[{"y", "[", "t", "]"}], "/.", "dsol"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{"Thick", ",", RowBox[{"Darker", "[", "Cyan", "]"}]}], "}"}]}], ",", RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.403259570853333*^9, 3.403259656042283*^9}, { 3.403259785187752*^9, 3.403259815170463*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Comparison of Exact Solution to Finite Differencing Methods", "Subtitle", CellChangeTimes->{{3.403355389197206*^9, 3.403355405587493*^9}}], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"0.1", ",", "1"}], "]"}], ",", RowBox[{"PlotM2", "[", RowBox[{"0.1", ",", "1"}], "]"}], ",", "ExactPlot", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.403259686187899*^9, 3.4032596910982647`*^9}, { 3.4033555053113403`*^9, 3.403355508764626*^9}}], Cell[BoxData[ RowBox[{"Show", "[", RowBox[{ RowBox[{"PlotM1", "[", RowBox[{"1.5", ",", "1"}], "]"}], ",", RowBox[{"PlotM2", "[", RowBox[{"1.5", ",", "1"}], "]"}], ",", "ExactPlot", ",", RowBox[{"PlotRange", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.25"}], ",", "1"}], "}"}]}], "}"}]}]}], "]"}]], "Input",\ CellChangeTimes->{{3.403259712731741*^9, 3.403259723338076*^9}, { 3.4033555357427464`*^9, 3.403355539965053*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["DSolve on a First-Order ODE: More Complex Example", "Subtitle", CellChangeTimes->{{3.403355389197206*^9, 3.403355405587493*^9}, { 3.403356281565518*^9, 3.403356322027639*^9}}], Cell["Here is another example:", "Text", CellChangeTimes->{{3.4032600535824337`*^9, 3.403260059584552*^9}}], Cell[BoxData[ RowBox[{"dsol", " ", "=", " ", RowBox[{"DSolve", "[", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "+", RowBox[{"x", " ", "*", RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", "0"}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]}]], "Input", CellTags->"mmtag:19:DSolve[]"], Cell["We can insert boundary conditions other than y[0]", "Text", CellChangeTimes->{{3.4032604642188063`*^9, 3.403260484209347*^9}}], Cell[BoxData[ RowBox[{"dsol", " ", "=", " ", RowBox[{"DSolve", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "+", " ", RowBox[{ RowBox[{"Sin", "[", "x", "]"}], " ", "*", RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", "0"}], ",", RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "5", "]"}], "\[Equal]", "1"}]}], "}"}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]}]], "Input", CellChangeTimes->{{3.4032603732587233`*^9, 3.403260429076013*^9}, { 3.403260522874613*^9, 3.40326060209978*^9}}], Cell[BoxData[ RowBox[{"GraphicsRow", "[", RowBox[{"{", RowBox[{ RowBox[{"p", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"y", "[", "x", "]"}], "/.", "dsol"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", "Thick"}]}], "]"}]}], ",", RowBox[{"Show", "[", RowBox[{"p", ",", RowBox[{"PlotRange", "\[Rule]", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "6"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"0", ",", "6"}], "}"}]}], "}"}]}], ",", RowBox[{"AspectRatio", "\[Rule]", "1"}]}], "]"}]}], "}"}], "]"}]], "Input", CellChangeTimes->{{3.403260693963097*^9, 3.403260694497423*^9}, { 3.403354284866354*^9, 3.40335434668458*^9}, {3.40335437941396*^9, 3.403354395725547*^9}}] }, Closed]] }, CellGrouping->Manual, WindowSize->{911, 999}, WindowMargins->{{Automatic, 230}, {Automatic, 12}}, WindowTitle->"Lecture 19 MIT 3.016 (Fall 2007) \[Copyright] W. Craig Carter \ 2003-2007", PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrintingOptions->{"PaperOrientation"->"Portrait"}, ShowCellLabel->False, CellLabelAutoDelete->True, IndexCreationOptions -> {"Format" -> "Text"}, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (June 19, 2007)", StyleDefinitions->"3016-Carter.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "mmtag:19:simple_forward_time_interation"->{ Cell[653, 25, 204, 3, 107, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"], Cell[2288, 76, 214, 4, 93, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"], Cell[10784, 282, 298, 6, 130, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"]}, "mmtag:19:MultipleListPlot[]"->{ Cell[11457, 298, 1162, 28, 68, "Input", CellTags->"mmtag:19:MultipleListPlot[]"]}, "mmtag:19:Module[]"->{ Cell[16069, 436, 618, 16, 37, "Input", CellTags->"mmtag:19:Module[]"], Cell[27926, 783, 1438, 33, 37, "Input", CellTags->"mmtag:19:Module[]"]}, "mmtag:19:first-order_ODES__visualizing"->{ Cell[34110, 949, 216, 3, 56, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[37067, 1039, 381, 8, 130, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[39033, 1098, 360, 7, 93, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}]}, "mmtag:19:first-order_ODES"->{ Cell[34110, 949, 216, 3, 56, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[37067, 1039, 381, 8, 130, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[39033, 1098, 360, 7, 93, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}]}, "mmtag:19:DSolve[]"->{ Cell[46172, 1320, 385, 11, 37, "Input", CellTags->"mmtag:19:DSolve[]"]} } *) (*CellTagsIndex CellTagsIndex->{ {"mmtag:19:simple_forward_time_interation", 48915, 1404}, {"mmtag:19:MultipleListPlot[]", 49247, 1411}, {"mmtag:19:Module[]", 49359, 1414}, {"mmtag:19:first-order_ODES__visualizing", 49558, 1419}, {"mmtag:19:first-order_ODES", 49999, 1429}, {"mmtag:19:DSolve[]", 50432, 1439} } *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 60, 0, 64, "Title"], Cell[CellGroupData[{ Cell[653, 25, 204, 3, 107, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"], Cell[860, 30, 130, 3, 26, "Text"], Cell[993, 35, 602, 16, 37, "Input"], Cell[1598, 53, 327, 6, 41, "Text"], Cell[1928, 61, 189, 5, 37, "Input"], Cell[2120, 68, 131, 3, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[2288, 76, 214, 4, 93, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"], Cell[2505, 82, 434, 8, 41, "Text"], Cell[2942, 92, 1034, 25, 68, "Input"], Cell[3979, 119, 370, 6, 41, "Text"], Cell[4352, 127, 984, 26, 68, "Input"], Cell[5339, 155, 286, 5, 37, "Input"], Cell[CellGroupData[{ Cell[5650, 164, 345, 6, 34, "Section"], Cell[5998, 172, 4559, 99, 143, "Input"] }, Open ]], Cell[10572, 274, 175, 3, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[10784, 282, 298, 6, 130, "Subtitle", CellTags->"mmtag:19:simple_forward_time_interation"], Cell[11085, 290, 369, 6, 41, "Text"], Cell[11457, 298, 1162, 28, 68, "Input", CellTags->"mmtag:19:MultipleListPlot[]"], Cell[12622, 328, 188, 3, 37, "Input"], Cell[12813, 333, 114, 3, 26, "Text"], Cell[12930, 338, 223, 4, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[13190, 347, 215, 4, 93, "Subtitle"], Cell[13408, 353, 1429, 41, 79, "Text"], Cell[14840, 396, 1010, 32, 41, "Text"], Cell[15853, 430, 213, 4, 26, "Text"], Cell[16069, 436, 618, 16, 37, "Input", CellTags->"mmtag:19:Module[]"], Cell[16690, 454, 125, 1, 26, "Text"], Cell[16818, 457, 237, 6, 37, "Input"], Cell[17058, 465, 190, 4, 26, "Text"], Cell[17251, 471, 221, 5, 37, "Input"], Cell[17475, 478, 300, 6, 26, "Text"], Cell[17778, 486, 358, 9, 37, "Input"], Cell[18139, 497, 549, 8, 56, "Text"], Cell[18691, 507, 311, 8, 37, "Input"], Cell[19005, 517, 221, 4, 26, "Text"], Cell[19229, 523, 363, 9, 37, "Input"], Cell[19595, 534, 297, 5, 41, "Text"], Cell[19895, 541, 632, 16, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[20564, 562, 268, 5, 93, "Subtitle"], Cell[CellGroupData[{ Cell[20857, 571, 534, 9, 54, "Section"], Cell[21394, 582, 1356, 35, 83, "Input"] }, Open ]], Cell[22765, 620, 481, 8, 37, "Input"], Cell[23249, 630, 564, 9, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[23850, 644, 264, 5, 93, "Subtitle"], Cell[24117, 651, 3806, 130, 71, "Text"], Cell[27926, 783, 1438, 33, 37, "Input", CellTags->"mmtag:19:Module[]"], Cell[29367, 818, 380, 9, 37, "Input"], Cell[29750, 829, 435, 11, 37, "Input"], Cell[CellGroupData[{ Cell[30210, 844, 386, 6, 54, "Section"], Cell[30599, 852, 1721, 40, 98, "Input"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[32369, 898, 317, 5, 93, "Subtitle"], Cell[32689, 905, 630, 16, 37, "Input"], Cell[33322, 923, 609, 18, 37, "Input"], Cell[33934, 943, 139, 1, 26, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[34110, 949, 216, 3, 56, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[34329, 954, 687, 21, 38, "Text"], Cell[35019, 977, 556, 16, 53, "Text"], Cell[35578, 995, 610, 17, 53, "Input"], Cell[36191, 1014, 839, 20, 83, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[37067, 1039, 381, 8, 130, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[37451, 1049, 562, 15, 78, "Text"], Cell[38016, 1066, 814, 20, 53, "Input"], Cell[38833, 1088, 163, 5, 37, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[39033, 1098, 360, 7, 93, "Subtitle", CellTags->{ "mmtag:19:first-order_ODES__visualizing", "mmtag:19:first-order_ODES"}], Cell[39396, 1107, 434, 16, 68, "Text"], Cell[39833, 1125, 170, 3, 26, "Text"], Cell[40006, 1130, 829, 22, 86, "Input"], Cell[40838, 1154, 653, 18, 59, "Input"], Cell[41494, 1174, 329, 6, 41, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[41860, 1185, 229, 6, 130, "Subtitle"], Cell[42092, 1193, 507, 17, 41, "Text"], Cell[42602, 1212, 378, 11, 37, "Input"], Cell[42983, 1225, 406, 7, 41, "Text"], Cell[43392, 1234, 502, 14, 37, "Input"], Cell[43897, 1250, 67, 0, 26, "Text"], Cell[43967, 1252, 557, 14, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[44561, 1271, 145, 1, 93, "Subtitle"], Cell[44709, 1274, 549, 15, 37, "Input"], Cell[45261, 1291, 576, 17, 37, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[45874, 1313, 184, 2, 93, "Subtitle"], Cell[46061, 1317, 108, 1, 26, "Text"], Cell[46172, 1320, 385, 11, 37, "Input", CellTags->"mmtag:19:DSolve[]"], Cell[46560, 1333, 133, 1, 26, "Text"], Cell[46696, 1336, 670, 19, 37, "Input"], Cell[47369, 1357, 894, 25, 53, "Input"] }, Closed]] } ] *) (* End of internal cache information *)