(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 18420, 614] NotebookOptionsPosition[ 15071, 516] NotebookOutlinePosition[ 16445, 557] CellTagsIndexPosition[ 16177, 549] WindowTitle->Lecture 20 MIT 3.016 (Fall 2009) \251 W. Craig Carter \ 2003--2009 WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell["First-Order Ordinary Differential Equations", "Title"], Cell[CellGroupData[{ Cell["\<\ Using DSolve to Find Symbolic Solutions to Differential Equations: General \ Homogeneous Case\ \>", "Subtitle", CellChangeTimes->{{3.4037061262674*^9, 3.4037061620907383`*^9}}], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " can solve the the general homogeneous first-order linear ODE:" }], "Text", CellChangeTimes->{{3.403703127547154*^9, 3.403703140776753*^9}}], Cell[BoxData[ RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "+", " ", RowBox[{ RowBox[{"p", "[", "x", "]"}], " ", RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", "0"}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]], "Input"], Cell[CellGroupData[{ Cell[TextData[{ "The dummy integration variables (K[1] in the above) and any integration \ constants (C[1] above) are picked by ", StyleBox["Mathematica", FontSlant->"Italic"], " . Note that we asked ", StyleBox["Mathematica", FontSlant->"Italic"], " to solve the most general form of homogeneous linear first-order ODE, and \ we got a solution in a very general form that is equivalent to that found in \ textbooks. Here is a more specific problem and the solution found by ", StyleBox["Mathematica", FontSlant->"Italic"], ":" }], "Text", CellChangeTimes->{{3.403703191746584*^9, 3.403703212833124*^9}}], Cell[BoxData[ RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], "+", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", " ", "x"}], "+", "1"}], ")"}], RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", "0"}], ",", " ", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]], "Input"] }, Open ]], Cell["\<\ There is an integration constant above, that will take on a specific value if \ an additional condition (such as an initial condition, or a boundary \ condition) is specified. Below, we stipulate that y[0] is 4; so we should get \ the result with C[1] specified; y[0] = C[1] = 4\ \>", "Text", CellChangeTimes->{{3.403703235434093*^9, 3.403703407296794*^9}}], Cell[BoxData[ RowBox[{"DSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], "+", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"2", " ", "x"}], "+", "1"}], ")"}], RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", "0"}], ",", RowBox[{ RowBox[{"y", "[", "0", "]"}], "==", "4"}]}], "}"}], ",", " ", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]], "Input", CellTags->"mmtag:20:DSolve[]__using_boundary_conditions"] }, Open ]], Cell[CellGroupData[{ Cell["DSolve and the General Linear Heterogeneous Case", "Subtitle", CellChangeTimes->{{3.4037061262674*^9, 3.403706207193479*^9}}], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " can solve the heterogeneous linear ODE:" }], "Text"], Cell[BoxData[ RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "+", " ", RowBox[{ RowBox[{"p", "[", "x", "]"}], " ", RowBox[{"y", "[", "x", "]"}]}]}], " ", "\[Equal]", RowBox[{"r", "[", "x", "]"}]}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]], "Input"], Cell[TextData[{ "Again, we asked ", StyleBox["Mathematica", FontSlant->"Italic"], " to solve the most general form of homogeneous linear first-order ODE, and \ we got a solution in a very general form\[LongDash]two dummy integration \ variables and one constant of integration. Below, we ask for a specific \ solution for the heterogeneous case: note that the homogeneous solution can \ always be added to the specific solution." }], "Text", CellChangeTimes->{{3.403704011756178*^9, 3.40370405068888*^9}, { 3.403704083146533*^9, 3.403704112936936*^9}}], Cell[BoxData[{ RowBox[{"homsol", " ", "=", " ", RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "-", " ", RowBox[{"y", "[", "x", "]"}]}], " ", "\[Equal]", "0"}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]}], "\[IndentingNewLine]", RowBox[{"hetsol", " ", "=", " ", RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "-", " ", RowBox[{"y", "[", "x", "]"}]}], " ", "\[Equal]", SuperscriptBox["\[ExponentialE]", RowBox[{"2", "x"}]]}], ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]}]}], "Input", CellChangeTimes->{{3.403704066259465*^9, 3.403704072540513*^9}, { 3.403704169123436*^9, 3.4037041784027843`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Example of Transformation of Variables in Symbolic Differential Equations:The \ Bernoulli Equation \ \>", "Subtitle", CellChangeTimes->{{3.403704560706653*^9, 3.40370461744258*^9}}, CellTags->"mmtag:20:Bernoulli_equation"], Cell["\<\ The Bernoulli equation is a first-order nonlinear ODE that has a form that \ can be reduced to a linear ODE as described in Kreyszig\ \>", "Text", CellChangeTimes->{{3.403704633026731*^9, 3.4037046672971497`*^9}}], Cell[BoxData[ RowBox[{"BernoulliEquation", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "+", " ", RowBox[{ RowBox[{"p", "[", "x", "]"}], " ", RowBox[{"y", "[", "x", "]"}]}]}], " ", "==", " ", RowBox[{ RowBox[{"r", "[", "x", "]"}], " ", RowBox[{ RowBox[{"(", RowBox[{"y", "[", "x", "]"}], ")"}], "^", RowBox[{"(", "a", ")"}]}]}]}]}]], "Input"], Cell[TextData[{ "The substitution ", "y(x) = ", Cell[BoxData[ FormBox[ SuperscriptBox[ RowBox[{"(", RowBox[{"u", "(", "x", ")"}], ")"}], RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "-", "a"}], ")"}]}]], TraditionalForm]]], "is made, resulting in a linear ODE that can be solved for ", StyleBox["u", FontSlant->"Italic"], "(", StyleBox["x", FontSlant->"Italic"], "):" }], "Text"], Cell["\<\ Here we define symbols that will be used in a subsequent rule-replacement \ method\ \>", "Text", CellChangeTimes->{{3.403704763782653*^9, 3.403704796353447*^9}}], Cell[BoxData[{ RowBox[{"yRep", " ", "=", " ", SuperscriptBox[ RowBox[{"u", "[", "x", "]"}], FractionBox["1", RowBox[{"1", "-", "a"}]]]}], "\[IndentingNewLine]", RowBox[{"DyRep", " ", "=", " ", RowBox[{"D", "[", RowBox[{"yRep", ",", "x"}], "]"}]}]}], "Input"], Cell[BoxData[ RowBox[{"step1", " ", "=", RowBox[{"BernoulliEquation", "/.", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"y", "[", "x", "]"}], "\[Rule]", "yRep"}], ",", RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], " ", "\[Rule]", " ", "DyRep"}]}], "}"}]}]}]], "Input"], Cell[BoxData[ RowBox[{"step2", " ", "=", RowBox[{"PowerExpand", "[", "step1", "]"}]}]], "Input"], Cell[BoxData[ RowBox[{"step3", " ", "=", RowBox[{"Simplify", "[", "step2", "]"}]}]], "Input"], Cell["\<\ This is the form of the linear homogeneous first-order ODE for which we found \ the general solution above.\ \>", "Text", CellChangeTimes->{{3.40370506233879*^9, 3.403705101777239*^9}}], Cell[BoxData[ RowBox[{"BE", "=", RowBox[{"Solve", "[", RowBox[{"step3", ",", RowBox[{ RowBox[{"u", "'"}], "[", "x", "]"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.403704874939353*^9, 3.403704882570125*^9}, 3.403708340800169*^9}], Cell[TextData[{ "This last result is the first-order ", StyleBox["linear", FontSlant->"Italic"], " ODE that results from the Bernoulli equation. Its solution gives the \ function ", StyleBox["u", FontSlant->"Italic"], "(", StyleBox["x", FontSlant->"Italic"], ") which can be converted back to ", StyleBox["y", FontSlant->"Italic"], "(", StyleBox["x", FontSlant->"Italic"], ") with the relation ", StyleBox["y", FontSlant->"Italic"], "(", StyleBox["x", FontSlant->"Italic"], ") = ", Cell[BoxData[ FormBox[ SuperscriptBox[ RowBox[{"(", RowBox[{"u", "(", "x", ")"}], ")"}], RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "-", "a"}], ")"}]}]], TraditionalForm]]], "." }], "Text"], Cell[BoxData[ RowBox[{"uprime", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"u", "'"}], "[", "x", "]"}], "/.", "BE"}]}]], "Input", CellChangeTimes->{{3.403704911537348*^9, 3.403704959457798*^9}, 3.403708336356925*^9}], Cell[BoxData[ RowBox[{"usol", "=", " ", RowBox[{ RowBox[{"u", "[", "x", "]"}], "/.", RowBox[{"DSolve", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"u", "'"}], "[", "x", "]"}], " ", "\[Equal]", " ", RowBox[{"uprime", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"u", "[", "x", "]"}], ",", "x"}], "]"}]}]}]], "Input", CellChangeTimes->{{3.403704972257616*^9, 3.4037050182808723`*^9}, { 3.403705159146137*^9, 3.4037051718262577`*^9}}], Cell[BoxData[ RowBox[{"ysol", " ", "=", " ", RowBox[{ RowBox[{"(", RowBox[{"usol", "[", RowBox[{"[", "1", "]"}], "]"}], ")"}], "^", RowBox[{"(", RowBox[{"1", "/", RowBox[{"(", RowBox[{"1", "-", "a"}], ")"}]}], ")"}]}]}]], "Input", CellChangeTimes->{{3.403705182001343*^9, 3.403705227233886*^9}}], Cell[BoxData[{"BernoulliEquation", "\[IndentingNewLine]", RowBox[{"Simplify", "[", RowBox[{ RowBox[{ RowBox[{"p", "[", "x", "]"}], " ", "ysol"}], " ", "+", " ", RowBox[{"D", "[", RowBox[{"ysol", ",", "x"}], "]"}]}], "]"}]}], "Input", CellChangeTimes->{{3.40370526371103*^9, 3.403705326930003*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Numerical Solutions to ODEs", "Subtitle"], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " cannot find a direct solution to the following nonlinear ODE" }], "Text", CellChangeTimes->{{3.403705402595022*^9, 3.4037054250973253`*^9}}], Cell[BoxData[ RowBox[{"eqn", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], "-", " ", RowBox[{"Exp", "[", RowBox[{"-", RowBox[{"Abs", "[", RowBox[{"y", "[", "x", "]"}], "]"}]}], "]"}]}], ")"}], "^", "2"}], " ", "==", " ", RowBox[{ RowBox[{ RowBox[{"y", "'"}], "[", "x", "]"}], RowBox[{"Exp", "[", RowBox[{"-", "x"}], "]"}]}]}]}]], "Input"], Cell[BoxData[ RowBox[{"DSolve", "[", " ", RowBox[{"eqn", ",", RowBox[{"y", "[", "x", "]"}], ",", "x"}], "]"}]], "Input"], Cell["\<\ NDSolve is a numerical method for finding a solution. An initial condition \ and the desired range of solution are required.\ \>", "Text"], Cell[BoxData[ RowBox[{"solution", " ", "=", RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{"eqn", ",", RowBox[{ RowBox[{"y", "[", "0", "]"}], "==", " ", RowBox[{"-", "2"}]}]}], "}"}], ",", "y", ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "25"}], "}"}]}], "]"}]}]], "Input", CellTags->"mmtag:20:NDSolve[]"], Cell[TextData[{ "The results look kind of strange, perhaps, but they are a set of rules that \ provide a function that interpolates between values. \n Here is how to \ find the approximate solution at three different values of ", StyleBox["x", FontSlant->"Italic"], " on the specified interval:" }], "Text", CellTags->"mmtag:20:numerical_solutions_to_ODEs__interpolation_results"], Cell[BoxData[ RowBox[{ RowBox[{"y", "[", "0.5", "]"}], " ", "/.", " ", "solution"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"y", "[", "1", "]"}], "/.", "solution"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"y", "[", "Pi", "]"}], "/.", "solution"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Exploring the Numerical Solution Behavior", "Subtitle", CellChangeTimes->{{3.403705664962841*^9, 3.403705677032681*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PlotVanilla", " ", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{ RowBox[{"y", "[", "x", "]"}], "/.", "solution"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "25"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Red", ",", "Thick"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Darker", "[", "Green", "]"}], ",", "Thick"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", " ", "\"\\""}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"PlotReal", " ", "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{"Re", "[", RowBox[{ RowBox[{"y", "[", "x", "]"}], "/.", "solution"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "25"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Red", ",", "Thick"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Darker", "[", "Green", "]"}], ",", "Thick"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", " ", "\"\\""}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{ RowBox[{"PlotIm", " ", "=", " ", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{"Im", "[", RowBox[{ RowBox[{"y", "[", "x", "]"}], "/.", "solution"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "25"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Red", ",", "Thick"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Darker", "[", "Green", "]"}], ",", "Thick"}], "}"}]}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", " ", "\"\\""}]}], "]"}]}], ";"}]], "Input"], Cell[BoxData[ RowBox[{"GraphicsRow", "[", RowBox[{ RowBox[{"{", RowBox[{"PlotVanilla", ",", "PlotReal", ",", "PlotIm"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Large"}]}], "]"}]], "Input", CellChangeTimes->{{3.403705786983861*^9, 3.403705833273817*^9}}] }, Open ]] }, CellGrouping->Manual, WindowSize->{1269, 1027}, WindowMargins->{{193, Automatic}, {Automatic, 23}}, WindowTitle->"Lecture 20 MIT 3.016 (Fall 2009) \[Copyright] W. Craig Carter \ 2003--2009", PrintingCopies->1, PrintingPageRange->{1, Automatic}, ShowCellLabel->False, CellLabelAutoDelete->True, Magnification->1.5, FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (November 11, 2008)", StyleDefinitions->"3016-Carter.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "mmtag:20:DSolve[]__using_boundary_conditions"->{ Cell[2863, 93, 562, 17, 55, "Input", CellTags->"mmtag:20:DSolve[]__using_boundary_conditions"]}, "mmtag:20:Bernoulli_equation"->{ Cell[5517, 178, 234, 5, 216, "Subtitle", CellTags->"mmtag:20:Bernoulli_equation"]}, "mmtag:20:NDSolve[]"->{ Cell[11490, 398, 366, 11, 55, "Input", CellTags->"mmtag:20:NDSolve[]"]}, "mmtag:20:numerical_solutions_to_ODEs__interpolation_results"->{ Cell[11859, 411, 391, 8, 62, "Text", CellTags->"mmtag:20:numerical_solutions_to_ODEs__interpolation_results"]} } *) (*CellTagsIndex CellTagsIndex->{ {"mmtag:20:DSolve[]__using_boundary_conditions", 15643, 534}, {"mmtag:20:Bernoulli_equation", 15779, 537}, {"mmtag:20:NDSolve[]", 15893, 540}, {"mmtag:20:numerical_solutions_to_ODEs__interpolation_results", 16037, 543} } *) (*NotebookFileOutline Notebook[{ Cell[628, 22, 60, 0, 167, "Title"], Cell[CellGroupData[{ Cell[713, 26, 188, 4, 216, "Subtitle"], Cell[904, 32, 208, 5, 39, "Text"], Cell[1115, 39, 335, 10, 55, "Input"], Cell[CellGroupData[{ Cell[1475, 53, 622, 15, 84, "Text"], Cell[2100, 70, 377, 12, 55, "Input"] }, Open ]], Cell[2492, 85, 368, 6, 62, "Text"], Cell[2863, 93, 562, 17, 55, "Input", CellTags->"mmtag:20:DSolve[]__using_boundary_conditions"] }, Open ]], Cell[CellGroupData[{ Cell[3462, 115, 132, 1, 161, "Subtitle"], Cell[3597, 118, 120, 4, 39, "Text"], Cell[3720, 124, 365, 11, 55, "Input"], Cell[4088, 137, 560, 11, 84, "Text"], Cell[4651, 150, 829, 23, 87, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[5517, 178, 234, 5, 216, "Subtitle", CellTags->"mmtag:20:Bernoulli_equation"], Cell[5754, 185, 224, 4, 39, "Text"], Cell[5981, 191, 444, 14, 55, "Input"], Cell[6428, 207, 423, 18, 44, "Text"], Cell[6854, 227, 172, 4, 39, "Text"], Cell[7029, 233, 283, 8, 95, "Input"], Cell[7315, 243, 320, 10, 55, "Input"], Cell[7638, 255, 100, 2, 55, "Input"], Cell[7741, 259, 97, 2, 55, "Input"], Cell[7841, 263, 196, 4, 39, "Text"], Cell[8040, 269, 253, 7, 55, "Input"], Cell[8296, 278, 736, 33, 67, "Text"], Cell[9035, 313, 230, 6, 55, "Input"], Cell[9268, 321, 492, 13, 55, "Input"], Cell[9763, 336, 336, 10, 55, "Input"], Cell[10102, 348, 319, 7, 79, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10458, 360, 47, 0, 105, "Subtitle"], Cell[10508, 362, 209, 5, 39, "Text"], Cell[10720, 369, 485, 17, 55, "Input"], Cell[11208, 388, 128, 3, 55, "Input"], Cell[11339, 393, 148, 3, 39, "Text"], Cell[11490, 398, 366, 11, 55, "Input", CellTags->"mmtag:20:NDSolve[]"], Cell[11859, 411, 391, 8, 62, "Text", CellTags->"mmtag:20:numerical_solutions_to_ODEs__interpolation_results"], Cell[12253, 421, 97, 2, 55, "Input"], Cell[12353, 425, 85, 2, 55, "Input"], Cell[12441, 429, 86, 2, 55, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[12564, 436, 127, 1, 105, "Subtitle"], Cell[12694, 439, 664, 20, 79, "Input"], Cell[13361, 461, 701, 21, 79, "Input"], Cell[14065, 484, 711, 21, 79, "Input"], Cell[14779, 507, 276, 6, 55, "Input"] }, Open ]] } ] *) (* End of internal cache information *)