(* 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[ 21559, 722] NotebookOptionsPosition[ 18287, 625] NotebookOutlinePosition[ 19186, 653] CellTagsIndexPosition[ 19143, 650] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Nonlinear Differential Equations: Pendulum", "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 has specialized to a pendulum equation, with parameters used in \ session 8 of 780.20. \ \>", "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[{"\[Theta]", "''"}], "[", "t", "]"}], " ", "+", " ", RowBox[{"\[Alpha]", " ", RowBox[{ RowBox[{"\[Theta]", "'"}], "[", "t", "]"}]}], " ", "+", " ", RowBox[{ RowBox[{"\[Omega]0", "^", "2"}], " ", RowBox[{"Sin", "[", RowBox[{"\[Theta]", "[", "t", "]"}], "]"}]}]}], " ", "\[Equal]", " ", RowBox[{"fext", " ", RowBox[{"Cos", "[", RowBox[{ RowBox[{"\[Omega]ext", "*", "t"}], " ", "+", " ", "\[Phi]ext"}], "]"}]}]}]}]], "Input", CellLabel->"In[1]:="], Cell["Choose among the parameters:", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"p1", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", "=", "0."}], ",", RowBox[{"\[Omega]0", "=", "1"}], ",", RowBox[{"fext", "=", "0."}], ",", RowBox[{"\[Omega]ext", "=", "0.689"}], ",", RowBox[{"\[Phi]ext", "=", " ", "0.0"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[2]:="], Cell[BoxData[ RowBox[{ RowBox[{"p2", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", "=", "0.2"}], ",", RowBox[{"\[Omega]0", "=", "1"}], ",", RowBox[{"fext", "=", "0.52"}], ",", RowBox[{"\[Omega]ext", "=", "0.689"}], ",", RowBox[{"\[Phi]ext", "=", " ", "0.0"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[3]:="], Cell[BoxData[ RowBox[{ RowBox[{"p3", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", "=", "0.2"}], ",", RowBox[{"\[Omega]0", "=", "1"}], ",", RowBox[{"fext", "=", "0.52"}], ",", RowBox[{"\[Omega]ext", "=", "0.694"}], ",", RowBox[{"\[Phi]ext", "=", "0.0"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[4]:="], Cell[BoxData[ RowBox[{ RowBox[{"p4", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", "=", "0.2"}], ",", RowBox[{"\[Omega]0", "=", "1"}], ",", RowBox[{"fext", "=", "0.52"}], ",", RowBox[{"\[Omega]ext", "=", "0.689"}], ",", RowBox[{"\[Phi]ext", "=", "0.0"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[5]:="], Cell[BoxData[ RowBox[{ RowBox[{"p5", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]", "=", "0.2"}], ",", RowBox[{"\[Omega]0", "=", "1"}], ",", RowBox[{"fext", "=", "0.9"}], ",", RowBox[{"\[Omega]ext", "=", "0.54"}], ",", RowBox[{"\[Phi]ext", "=", "0.0"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[6]:="], Cell[BoxData["p2"], "Input", CellLabel->"In[7]:="], Cell["Choose among the initial conditions:", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"ic1", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Theta]0", "=", "0.8"}], ",", RowBox[{"\[Theta]dot0", "=", "0."}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[8]:="], Cell[BoxData[ RowBox[{ RowBox[{"ic2", " ", ":=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Theta]0", " ", "=", " ", RowBox[{"-", "0.8"}]}], ",", " ", RowBox[{"\[Theta]dot0", " ", "=", " ", "0.1234"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[9]:="], Cell[BoxData[ RowBox[{ RowBox[{"ic3", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Theta]0", "=", "0.8"}], ",", RowBox[{"\[Theta]dot0", "=", "0.8"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[10]:="], Cell[BoxData[ RowBox[{ RowBox[{"ic4", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Theta]0", "=", "0.8"}], ",", RowBox[{"\[Theta]dot0", "=", "0.8"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[11]:="], Cell[BoxData[ RowBox[{ RowBox[{"ic5", ":=", RowBox[{"{", RowBox[{ RowBox[{"\[Theta]0", "=", RowBox[{"-", "0.8"}]}], ",", RowBox[{"\[Theta]dot0", "=", "0.1234"}]}], "}"}]}], ";"}]], "Input", CellLabel->"In[12]:="], Cell[BoxData["ic2"], "Input", CellLabel->"In[13]:="] }, 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[14]:="], 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[{"\[Theta]", "[", "0", "]"}], "\[Equal]", "\[Theta]0"}], ",", " ", RowBox[{ RowBox[{ RowBox[{"\[Theta]", "'"}], "[", "0", "]"}], "\[Equal]", "\[Theta]dot0"}]}], "}"}], ",", "\[Theta]", ",", RowBox[{"{", RowBox[{"t", ",", "tmin", ",", "tmax"}], "}"}], ",", RowBox[{"MaxSteps", "\[Rule]", "20000"}]}], "]"}]}], ";"}]], "Input", CellLabel->"In[15]:="], 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[{"\[Theta]", "[", "t", "]"}], "/.", "solution"}], "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "100"}], "}"}]}], "]"}]], "Input", CellLabel->"In[16]:="], 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[{"\[Theta]", "[", "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", "[", "\"\