(* 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[ 18638, 618] NotebookOptionsPosition[ 15686, 529] NotebookOutlinePosition[ 16586, 557] CellTagsIndexPosition[ 16543, 554] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Nonlinear Differential Equations", "Subtitle", TextAlignment->Center, TextJustification->0], Cell["\<\ In this notebook, we solve nonlinear differential equations, looking at the \ time dependence, phase space plots, Poincare sections, and the power \ spectrum. The notebook starts with the Duffing equation. Your job is to modify it to \ the damped, driven pendulum, then to reproduce and extend the results from \ session 8 (which used diffeq_pendulum.cpp).\ \>", "Text"], Cell[CellGroupData[{ Cell["Define the Differential Equation", "Section"], Cell["\<\ Name the equation \"diffeq\". Note the \"==\" in defining the equation. \ \>", "Text"], Cell[BoxData[ RowBox[{"diffeq", " ", ":=", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"x", "''"}], "[", "t", "]"}], "+", RowBox[{"2", " ", "\[Gamma]", " ", RowBox[{ RowBox[{"x", "'"}], "[", "t", "]"}]}], "+", RowBox[{"\[Alpha]", " ", RowBox[{"x", "[", "t", "]"}]}], "+", RowBox[{"\[Beta]", " ", RowBox[{ RowBox[{"x", "[", "t", "]"}], "^", "3"}]}]}], "\[Equal]", RowBox[{"fext", " ", RowBox[{"Cos", "[", RowBox[{"\[Omega]ext", " ", "t"}], "]"}], " "}]}]}]], "Input", CellLabel->"In[1]:="], Cell["Choose among the parameters:", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"p1", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", " ", "=", RowBox[{"-", "1"}]}], ",", RowBox[{"\[Beta]", "=", "1"}], ",", RowBox[{"\[Omega]ext", "=", "1"}], ",", " ", RowBox[{"\[Gamma]", "=", "0.25"}], ",", RowBox[{"fext", "=", "0.34875"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[2]:="], Cell[BoxData["p1"], "Input", CellLabel->"In[3]:="], Cell["Choose among the initial conditions:", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"ic1", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"x0", "=", "1"}], ",", RowBox[{"v0", "=", "0."}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[4]:="], Cell[BoxData["ic1"], "Input", CellLabel->"In[5]:="] }, Open ]], Cell[CellGroupData[{ Cell["Solve the Differential Equation", "Section"], Cell["\<\ Specify the range in time over which we will solve the differential equation. \ We won't be able to use the solution outside of this range. (I.e., we'll \ have to extend this range if we get an \"outside of range\" error later.)\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"tmin", "=", "0"}], ";", " ", RowBox[{"tmax", "=", "1000"}], ";"}]], "Input", CellLabel->"In[6]:="], Cell["\<\ Numerically solve the differential equaiton using NDSolve, specifying the \ initial conditions. Setting MaxSteps to a large number is needed if tmax is \ large.\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"solution", " ", "=", " ", RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{"diffeq", ",", RowBox[{ RowBox[{"x", "[", "0", "]"}], "\[Equal]", "x0"}], ",", " ", RowBox[{ RowBox[{ RowBox[{"x", "'"}], "[", "0", "]"}], "\[Equal]", "v0"}]}], "}"}], ",", "x", ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax"}], "}"}], ",", RowBox[{"MaxSteps", "\[Rule]", "20000"}]}], "]"}]}], ";"}]], "Input", CellLabel->"In[7]:="], Cell["\<\ NDSolve returns an \"interpolating function\", which can be evaluated later \ at any time t in tmin < t < tmax.\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Plot the Time Dependence and Phase Space", "Section"], Cell["\<\ We can just use \"Plot\" with Evaluate and the \"interpolating function\" \ defined by \"solution\".\ \>", "Text"], Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{ RowBox[{"x", "[", "t", "]"}], "/.", "solution"}], "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "100"}], "}"}]}], "]"}]], "Input", CellLabel->"In[8]:="], Cell["\<\ Or we can do a parametric plot (\"ParametricPlot\") with the same solution. \ We've added various options here to (try to) make a nicer plot.\ \>", "Text"], Cell[BoxData[ RowBox[{"ParametricPlot", "[", RowBox[{ RowBox[{"Evaluate", "[", RowBox[{ RowBox[{"{", RowBox[{"t", ",", RowBox[{"x", "[", "t", "]"}]}], "}"}], "/.", "\[InvisibleSpace]", "solution"}], "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "100"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Hue", "[", "0.6`", "]"}]}], ",", RowBox[{"BaseStyle", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"FontFamily", "\[Rule]", "\"\\""}], ",", RowBox[{"FontSize", "\[Rule]", "14"}]}], "}"}]}], ",", RowBox[{"ImageSize", "\[Rule]", RowBox[{"{", RowBox[{"350", ",", "200"}], "}"}]}], ",", RowBox[{"PlotLabel", "\[Rule]", RowBox[{"Style", "[", "\"\