(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 9474, 300]*) (*NotebookOutlinePosition[ 10172, 324]*) (* CellTagsIndexPosition[ 10128, 320]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Differential Equations", "Title", TextAlignment->Center, Background->RGBColor[0, 1, 1]], Cell["\<\ This notebook is by Steven Amgott, with sections by Rob Manning. \ Please send any questions or comments to samgott1@swarthmore.edu. Feel free \ to use and distribute this notebook,but keep this author information in any \ copy you use or distribute.\ \>", "SmallText"], Cell[TextData[{ "To open the closed group of cells for any of the sections or commands, you \ can ", StyleBox["double-click the bracket with a triangle at its bottom at the \ right edge of the cell", FontColor->RGBColor[1, 0, 1]], ".\n\nIf this is your first experience with ", StyleBox["Mathematica", FontSlant->"Italic"], ", or if you need a brief refresher before continuing, you might first go \ through the ", Cell[BoxData[ FormBox[ ButtonBox[\(Introduction\ to\ Mathematica\), ButtonData:>{"Introduction_to_Mathematica.nb", None}, ButtonStyle->"Hyperlink"], TraditionalForm]]], " notebook contained in the same folder as this notebook. In particular, \ remember that to evaluate a cell you need to press the ", StyleBox["enter", FontColor->RGBColor[0, 0, 1]], " key on the number pad at the lower right side of the keyboard and NOT the \ ", StyleBox["return", FontColor->RGBColor[0, 0, 1]], " key on a Macintosh or the ", StyleBox["Enter", FontColor->RGBColor[0, 0, 1]], " key next to the single and double quote marks on a Windows machine! ", "(The latter only produces a line break. You can, however, use the ", StyleBox["Shift", FontColor->RGBColor[0, 0, 1]], " and ", StyleBox["Enter", FontColor->RGBColor[0, 0, 1]], " keys on a Windows machine, or the ", StyleBox["shift", FontColor->RGBColor[0, 0, 1]], " and ", StyleBox["return", FontColor->RGBColor[0, 0, 1]], " keys on a Mac, simultaneously to evaluate a cell. In particular, that is \ how you evaluate a cell on a notebook computer without a number pad.)" }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData[{ "Symbolic solutions using ", StyleBox["DSolve", FontColor->RGBColor[1, 0, 0]] }], "Section"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has the ability to solve some differential equations symbolically. The \ command to do this is ", StyleBox["DSolve", FontColor->RGBColor[1, 0, 0]], ", and it is available on the ", StyleBox["DifferentialEquations", FontColor->RGBColor[0, 0, 1]], " palette. The syntax consists of the differential equation, followed by \ the function for which you are solving, followed by the independent variable. \ Here is an example." }], "Text"], Cell[BoxData[{ \(Clear[v, g, c, t]\), \(DSolve[\(v'\)[t] == g - c\ v[t], v[t], t]\)}], "Input"], Cell[TextData[{ "Notice that I used ", StyleBox["Mathematica", FontSlant->"Italic"], " function notation for the solution function and its derivatives (i.e. I \ used ", StyleBox["[t]", FontColor->RGBColor[1, 0, 0]], "). I also ", StyleBox["Clear", FontColor->RGBColor[1, 0, 0]], "ed any variable or function names I was using in case they had been \ defined previously. This is a good habit to form." }], "Text"], Cell[TextData[{ "We can also solve initial value problems using ", StyleBox["DSolve", FontColor->RGBColor[1, 0, 0]], ". To do so, we give a list of equations, one of which gives the initial \ condition, instead of a single equation." }], "Text"], Cell[BoxData[{ \(Clear[v, g, c, t]\), \(DSolve[{\(v'\)[t] == g - c\ v[t], v[0] == 0}, v[t], t]\)}], "Input"], Cell[TextData[{ "Notice the ", StyleBox["{ }", FontColor->RGBColor[1, 0, 0]], " around the list of equations; that is how we input lists into ", StyleBox["Mathematica.", FontSlant->"Italic"] }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Numerical solutions using ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]] }], "Section"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " has a built in numerical ODE solver called ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]], ". The syntax for its use is similar to ", StyleBox["DSolve", FontColor->RGBColor[1, 0, 0]], " (although ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]], " can only be used for initial value problems, while ", StyleBox["DSolve", FontColor->RGBColor[1, 0, 0]], " can generate general solutions as well): " }], "Text"], Cell[BoxData[{\(Clear[y, t]\), RowBox[{"ndsolvestep1", " ", "=", " ", RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{\(\(y'\)[t]\), "==", " ", StyleBox[\(\(-\ t\)\ *y[t]\), FontColor->RGBColor[1, 0, 1]]}], ",", RowBox[{ RowBox[{"y", "[", StyleBox["0", FontColor->RGBColor[1, 0, 1]], "]"}], "==", StyleBox["10", FontColor->RGBColor[1, 0, 1]]}]}], "}"}], ",", \(y[t]\), ",", RowBox[{"{", RowBox[{"t", ",", StyleBox["0.0", FontColor->RGBColor[1, 0, 1]], ",", StyleBox["1.0", FontColor->RGBColor[1, 0, 1]]}], "}"}]}], "]"}]}]}], "Input"], Cell[TextData[{ "Observe that ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]], " gives you its solution not as a formula, but rather as an \ \"InterpolatingFunction\"; that is, ", StyleBox["Mathematica", FontSlant->"Italic"], " is storing it as a list of numbers at specific intermediate times. ", StyleBox["Mathematica", FontSlant->"Italic"], "'s output is useless to us, so we do the following two steps to define a \ normal function that can be plotted or evaluated at specific t values:\n\n\ First, we do a \"y[t] /. ndsolvestep1\", which says \"evaluate y[t] subject \ to the rule in ndsolvestep1\". The output is just the interpolating function \ alone." }], "Text"], Cell[BoxData[ \(ndsolvestep2\ = \ y[t]\ /. \ ndsolvestep1\)], "Input"], Cell["\<\ Now, we define a function of a dummy variable \"s\" which plugs in \ s for t in the InterpolatingFunction. Notice that with the delayed \ evaluation :=, no output is produced when you type Enter.\ \>", "Text"], Cell[BoxData[ \(ndsolvesolution[s_]\ := \ N[ndsolvestep2 /. t \[Rule] s]\)], "Input"], Cell[BoxData[ \(ndsolvesolution[1]\)], "Input"], Cell[BoxData[ \(ndsolvesolution[1] - exact\)], "Input"], Cell[BoxData[ \(Plot[ndsolvesolution[s], {s, 0, 1}]\)], "Input"], Cell[TextData[{ "By default, ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]], " strives for 6 digits of absolute and relative error in its computations. \ You can request more or less accuracy by setting the ", StyleBox["AccuracyGoal", FontColor->RGBColor[1, 0, 0]], " and ", StyleBox["PrecisionGoal", FontColor->RGBColor[1, 0, 0]], " flags:" }], "Text"], Cell[BoxData[ \(ndsolvestep1\ = \ NDSolve[{\(y'\)[t] == \ \(-\ t\)\ *y[t], y[0] == 10}, y[t], {t, 0.0, 1.0}, AccuracyGoal -> 3, PrecisionGoal -> 3]\)], "Input"], Cell[TextData[{ "Here's the same song-and-dance to handle the output of ", StyleBox["NDSolve", FontColor->RGBColor[1, 0, 0]], ", this time combined into one step:" }], "Text"], Cell[BoxData[ \(ndsolvesolution[s_]\ := \ N[\((y[t] /. ndsolvestep1)\) /. t \[Rule] s]\)], "Input"], Cell[BoxData[ \(ndsolvesolution[1]\)], "Input"], Cell[BoxData[ \(ndsolvesolution[1] - exact\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 720}}, AutoGeneratedPackage->None, WindowToolbars->"EditBar", WindowSize->{521, 526}, WindowMargins->{{4, Automatic}, {Automatic, 0}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1727, 52, 97, 2, 131, "Title"], Cell[1827, 56, 281, 5, 60, "SmallText"], Cell[2111, 63, 1699, 44, 245, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[3835, 111, 116, 4, 59, "Section"], Cell[3954, 117, 524, 13, 90, "Text"], Cell[4481, 132, 104, 2, 50, "Input"], Cell[4588, 136, 440, 13, 71, "Text"], Cell[5031, 151, 256, 6, 52, "Text"], Cell[5290, 159, 117, 2, 50, "Input"], Cell[5410, 163, 218, 7, 33, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5665, 175, 118, 4, 39, "Section"], Cell[5786, 181, 523, 16, 64, "Text"], Cell[6312, 199, 844, 21, 75, "Input"], Cell[7159, 222, 705, 16, 130, "Text"], Cell[7867, 240, 76, 1, 27, "Input"], Cell[7946, 243, 220, 4, 62, "Text"], Cell[8169, 249, 90, 1, 27, "Input"], Cell[8262, 252, 51, 1, 27, "Input"], Cell[8316, 255, 59, 1, 27, "Input"], Cell[8378, 258, 68, 1, 27, "Input"], Cell[8449, 261, 386, 12, 46, "Text"], Cell[8838, 275, 190, 4, 59, "Input"], Cell[9031, 281, 185, 5, 46, "Text"], Cell[9219, 288, 111, 2, 27, "Input"], Cell[9333, 292, 51, 1, 27, "Input"], Cell[9387, 295, 59, 1, 27, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)