(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of 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[ 10958, 399]*) (*NotebookOutlinePosition[ 12037, 433]*) (* CellTagsIndexPosition[ 11993, 429]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[StyleBox["Demo 2.1", FontSize->20, FontWeight->"Bold", FontSlant->"Plain", FontTracking->"Extended", FontVariations->{"Underline"->True}]], "Subsubtitle"], Cell[CellGroupData[{ Cell["Using DSolve for first order ODE's and plotting solutions", "Section"], Cell[CellGroupData[{ Cell["Finding the general solution", "Subsection"], Cell["\<\ Buttons for the command DSolve can be found in the \ BasicCalculations Palette under Calculus/Differential Equations. Move the \ cursor to a new cell and press the first DSolve button.\ \>", "Text"], Cell[BoxData[ \(DSolve[\[Placeholder]\ \[Equal] \ \[Placeholder], \ \[Placeholder], \ \[Placeholder]]\)], "Input"], Cell["\<\ The part before the comma is for the equation. It must be expressed \ in terms of y'[t], y[t], and t. (Recall that the equals sign for equations is ==.) Then comes the function we \ are solving for, y[t], and finally the variable t.\ \>", "Text"], Cell[BoxData[ \(DSolve[\(y'\)[t] - 2 y[t]\ \[Equal] \ 4 t, \ y[t], \ t]\)], "Input"], Cell["\<\ This gives the general solution in terms of an arbitrary constant \ C[1]. Let's give this a name so that we can work with it. We should always \ clear y before solving.\ \>", "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(soln = DSolve[\(y'\)[t] - 2 y[t]\ \[Equal] \ 4 t, \ y[t], \ t]\ // \ Simplify\)], "Input"], Cell["\<\ The result is a list of lists. The first (and in this case only) \ list on the inside contains a rule that a solution should follow. We convert \ this to a function and replace C[1] by c.\ \>", "Text"], Cell[BoxData[ \(y[t_, c_] = \(y[t]\ /. \ First[soln]\)\ /. \ C[1]\ -> \ c\)], "Input"], Cell[BoxData[ \(y[1, 2]\)], "Input"], Cell[BoxData[ \(y[t, 2]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Solving initial value problems", "Subsection"], Cell["\<\ Move the cursor to a new cell and press the second DSolve button.\ \ \>", "Text"], Cell[BoxData[ \(DSolve[{\[SelectionPlaceholder] \[Equal] \[Placeholder], \[Placeholder] \[Equal] \[Placeholder]}, \[Placeholder], \[Placeholder]]\)], "Input"], Cell["\<\ The second equation is the initial condition, y[0]=c. (Of course 0 \ could be replaced by another number).\ \>", "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(soln = DSolve[{\(y'\)[t] - 2 y[t] \[Equal] 4 t, y[0] \[Equal] c}, y[t], t] \ // \ Simplify\)], "Input"], Cell[BoxData[ \(y[t_, c_] = y[t]\ /. \ First[soln]\)], "Input"], Cell[BoxData[ \(y[1, 2]\)], "Input"], Cell["Note that the two types of solutions give different answers.", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Plotting solutions", "Subsection"], Cell[TextData[{ "We want to plot on ", StyleBox["one", FontVariations->{"Underline"->True}], " graph ", StyleBox["several", FontVariations->{"Underline"->True}], " solutions of a given differential equation. To do so, we collect the \ solutions in a Table and then Plot the Table." }], "Text"], Cell[BoxData[ \(\(?Plot\)\)], "Input"], Cell[BoxData[ \(\(?Table\)\)], "Input"], Cell["\<\ For a Table the range {c,-5,5,2} will make c take the values \ -5,-3,-1,1,3, and 5, i.e., c goes from -5 to 5 in increments of 2.\ \>", "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(Table[y[t, c], {c, \(-5\), 5, 2}]\)], "Input"], Cell["\<\ We can take y[t,c] to be either the general solution or the \ solution in terms of an initial condition. The second command will put all \ the functions in the Table. Be sure to use a lower case \"c\", since the \ upper case \"C\" is protected and cannot be used. The range for t and the \ choices for c may be edited for each problem.\ \>", "Text"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], {c, \(-5\), 5, 2}]], {t, \(-5\), 5}, AspectRatio\ -> \ 1]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Example 1. ", StyleBox[" y' - 2 y = 4t", FontFamily->"Courier New"] }], "Subsection"], Cell[TextData[StyleBox["Let's apply this to the first example above. ", FontWeight->"Plain"]], "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(soln = DSolve[\(y'\)[t] - 2 y[t]\ \[Equal] \ 4 t, \ y[t], \ t]\ // \ Simplify\)], "Input"], Cell[BoxData[ \(y[t_, c_] = \(y[t]\ /. \ First[soln]\)\ /. \ C[1]\ -> \ c\)], "Input"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], {c, \(-5\), 5, 2}]], {t, \(-5\), 5}, AspectRatio\ -> \ 1]\)], "Input"], Cell["\<\ Plotting just a single function, say y(t,1), can be done simply by \ \ \>", "Text"], Cell[BoxData[ \(Plot[y[t, 1], {t, \(-5\), 5}, AspectRatio\ -> \ 1]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Example 2. ", StyleBox[" y' + 3 y = ", FontFamily->"Courier New"], Cell[BoxData[ \(TraditionalForm\`E\^\(-t\)\)], FontFamily->"Courier New"] }], "Subsection"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(\(soln = DSolve[\(y'\)[t] + 3 y[t]\ \[Equal] \ E^\((\(-t\))\), \ y[t], \ t] \ // \ Simplify\ \)\)], "Input"], Cell[BoxData[ \(y[t_, c_] = \(y[t]\ /. \ First[soln]\)\ /. \ C[1]\ -> \ c\)], "Input"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], {c, \(-5\), 5, 2}]], {t, \(-5\), 5}, \ AspectRatio\ -> \ 1]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Example 3. ", StyleBox[" y' +", FontFamily->"Courier New"], Cell[BoxData[ \(TraditionalForm\`\(\ \(\ 1\)\/t\)\)], FontFamily->"Courier New"], StyleBox[" y = -3 ", FontFamily->"Courier New"], Cell[BoxData[ \(TraditionalForm\`t\^2\)], FontFamily->"Courier New"] }], "Subsection"], Cell["\<\ Let's find and plot the solutions in terms of the initial values at \ t=1.\ \>", "Text"], Cell[BoxData[ \(Clear[y]\)], "Input"], Cell[BoxData[ \(soln = DSolve[{\(y'\)[t] + 1/t\ y[t] \[Equal] \(-3\)\ t^2, y[1] \[Equal] c}, y[t], t]\ // \ Simplify\)], "Input"], Cell[BoxData[ \(\(y[t_, c_] = y[t]\ /. \ First[soln]\ \)\)], "Input"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], {c, \(-5\), 5, 2}]], {t, 0.1, 3}, AspectRatio\ -> \ 1]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["A Palette", "Subsection"], Cell["\<\ Here is a Palette for the commands above. It was generated in the \ same way as the Palette for PlotVectorField in Demo 1.1. \ \>", "Text"], Cell[TextData[Cell[BoxData[GridBox[{ { ButtonBox[\(General\ Solution\)]}, { ButtonBox[\(Clear[y]; \n soln = DSolve[ \[SelectionPlaceholder]\ \[Equal] \ \[SelectionPlaceholder], \ y[t], \ t]\ // \ Simplify \)]}, { ButtonBox[ \(y[t_, c_] = \(y[t]\ /. \ First[soln]\)\ /. \ C[1]\ -> \ c\)]}, { ButtonBox[\(General\ Initial\ Value\ Problem\)]}, { ButtonBox[\(Clear[y]; \n soln = DSolve[{ \[SelectionPlaceholder] \[Equal] \[SelectionPlaceholder], y[\[SelectionPlaceholder]] \[Equal] c}, y[t], t]\ // \ Simplify\)]}, { ButtonBox[\(y[t_, c_] = y[t]\ /. \ First[soln]\)]}, { ButtonBox[ \(Plot[Evaluate[ Table[y[t, c], \ {c, \[SelectionPlaceholder], \[SelectionPlaceholder], \[SelectionPlaceholder]}]], \ \n \t{t, \ \[SelectionPlaceholder], \[SelectionPlaceholder]}, \ AspectRatio\ -> \ 1]\)]} }, RowSpacings->0, ColumnSpacings->0, GridFrame->True, RowLines->True, GridDefaultElement:>ButtonBox[ "\\[Placeholder]"]]]]], "Text"], Cell["The following two examples were done using the Palette.", "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Example 4. ", StyleBox["y' = y", FontFamily->"Courier New"] }], "Subsection"], Cell[BoxData[ \(Clear[y]; \n soln = DSolve[\(y'\)[t]\ \[Equal] \ y[t], \ y[t], \ t]\ // \ Simplify \)], "Input"], Cell[BoxData[ \(y[t_, c_] = \(y[t]\ /. \ First[soln]\)\ /. \ C[1]\ -> \ c\)], "Input"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], \ {c, \(-4\), 4, 2}]], \ \n \t{t, \ \(-1\), 5}, \ AspectRatio\ -> \ 1]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Example 5. ", StyleBox["y' = y, y[1]=c ", FontFamily->"Courier New"], " " }], "Subsection"], Cell[BoxData[ \(Clear[y]; \n soln = DSolve[{\(y'\)[t] \[Equal] y[t], y[1] \[Equal] c}, y[t], t]\ // \ Simplify\)], "Input"], Cell[BoxData[ \(y[t_, c_] = y[t]\ /. \ First[soln]\)], "Input"], Cell[BoxData[ \(y[2, 3]\)], "Input"], Cell[BoxData[ \(Plot[Evaluate[Table[y[t, c], \ {c, \(-4\), 4, 2}]], \ \n \t{t, \ \(-1\), 3}, \ AspectRatio\ -> \ 1]\)], "Input"] }, Open ]] }, Open ]] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 832}, {0, 604}}, WindowToolbars->"EditBar", WindowSize->{520, 509}, WindowMargins->{{4, Automatic}, {Automatic, 1}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrintingOptions->{"PrintingMargins"->{{54, 54}, {72, 72}}, "PrintCellBrackets"->False, "PrintRegistrationMarks"->False, "PrintMultipleHorizontalPages"->False}, MacintoshSystemPageSetup->"\<\ 00<0004/0B`000002n88o?mooh<" ] (*********************************************************************** 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[1731, 51, 178, 5, 57, "Subsubtitle"], Cell[CellGroupData[{ Cell[1934, 60, 76, 0, 50, "Section"], Cell[CellGroupData[{ Cell[2035, 64, 50, 0, 46, "Subsection"], Cell[2088, 66, 208, 4, 62, "Text"], Cell[2299, 72, 126, 2, 27, "Input"], Cell[2428, 76, 256, 5, 78, "Text"], Cell[2687, 83, 91, 1, 27, "Input"], Cell[2781, 86, 192, 4, 46, "Text"], Cell[2976, 92, 41, 1, 27, "Input"], Cell[3020, 95, 130, 3, 27, "Input"], Cell[3153, 100, 211, 4, 46, "Text"], Cell[3367, 106, 93, 1, 27, "Input"], Cell[3463, 109, 40, 1, 27, "Input"], Cell[3506, 112, 40, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3583, 118, 52, 0, 46, "Subsection"], Cell[3638, 120, 91, 3, 30, "Text"], Cell[3732, 125, 178, 3, 27, "Input"], Cell[3913, 130, 130, 3, 46, "Text"], Cell[4046, 135, 41, 1, 27, "Input"], Cell[4090, 138, 143, 3, 43, "Input"], Cell[4236, 143, 68, 1, 27, "Input"], Cell[4307, 146, 40, 1, 27, "Input"], Cell[4350, 149, 76, 0, 30, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[4463, 154, 40, 0, 46, "Subsection"], Cell[4506, 156, 311, 9, 46, "Text"], Cell[4820, 167, 42, 1, 27, "Input"], Cell[4865, 170, 43, 1, 27, "Input"], Cell[4911, 173, 156, 4, 46, "Text"], Cell[5070, 179, 41, 1, 27, "Input"], Cell[5114, 182, 66, 1, 27, "Input"], Cell[5183, 185, 362, 6, 78, "Text"], Cell[5548, 193, 127, 2, 43, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5712, 200, 128, 4, 46, "Subsection"], Cell[5843, 206, 104, 1, 30, "Text"], Cell[5950, 209, 41, 1, 27, "Input"], Cell[5994, 212, 130, 3, 27, "Input"], Cell[6127, 217, 93, 1, 27, "Input"], Cell[6223, 220, 127, 2, 43, "Input"], Cell[6353, 224, 94, 3, 30, "Text"], Cell[6450, 229, 84, 1, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6571, 235, 224, 7, 47, "Subsection"], Cell[6798, 244, 41, 1, 27, "Input"], Cell[6842, 247, 148, 3, 43, "Input"], Cell[6993, 252, 93, 1, 27, "Input"], Cell[7089, 255, 129, 2, 43, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7255, 262, 361, 12, 50, "Subsection"], Cell[7619, 276, 98, 3, 30, "Text"], Cell[7720, 281, 41, 1, 27, "Input"], Cell[7764, 284, 152, 3, 59, "Input"], Cell[7919, 289, 74, 1, 27, "Input"], Cell[7996, 292, 124, 2, 43, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8157, 299, 31, 0, 46, "Subsection"], Cell[8191, 301, 149, 3, 46, "Text"], Cell[8343, 306, 1395, 40, 192, "Text"], Cell[9741, 348, 71, 0, 30, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[9849, 353, 120, 4, 47, "Subsection"], Cell[9972, 359, 130, 3, 43, "Input"], Cell[10105, 364, 93, 1, 27, "Input"], Cell[10201, 367, 139, 2, 43, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10377, 374, 141, 5, 47, "Subsection"], Cell[10521, 381, 141, 3, 59, "Input"], Cell[10665, 386, 68, 1, 27, "Input"], Cell[10736, 389, 40, 1, 27, "Input"], Cell[10779, 392, 139, 2, 43, "Input"] }, Open ]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)