(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 8.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 157, 7] NotebookDataLength[ 10287, 310] NotebookOptionsPosition[ 8574, 249] NotebookOutlinePosition[ 9421, 280] CellTagsIndexPosition[ 9344, 275] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[StyleBox["\[OpenCurlyDoubleQuote]Animation\ \[CloseCurlyDoubleQuote] Sample Notebook", "Title"]], "Section", CellChangeTimes->{{3.523020851379966*^9, 3.523020861577718*^9}, { 3.5252135539567223`*^9, 3.525213554131114*^9}, {3.525213592853923*^9, 3.525213595955573*^9}, {3.5263090902292337`*^9, 3.526309091582081*^9}, { 3.526309124992982*^9, 3.52630914401475*^9}, {3.5263114013628063`*^9, 3.526311404919738*^9}, {3.5284834369911413`*^9, 3.5284834376448307`*^9}, { 3.5297442510968657`*^9, 3.5297442554779997`*^9}, {3.530301358825203*^9, 3.5303013592541*^9}, {3.553880044249653*^9, 3.553880050613377*^9}, { 3.553880947024061*^9, 3.5538809478289223`*^9}}], Cell[CellGroupData[{ Cell[TextData[{ "Animations (with graphics) in ", StyleBox["Mathematica", FontSlant->"Italic"], "." }], "Section", CellChangeTimes->{{3.5263126073521137`*^9, 3.526312649957903*^9}, { 3.52848356742717*^9, 3.528483574183846*^9}, {3.529744264545711*^9, 3.52974426712998*^9}, {3.529744324245282*^9, 3.5297443426595993`*^9}, { 3.5303013716744013`*^9, 3.5303013761000347`*^9}}], Cell[BoxData[ RowBox[{"Remove", "[", "\"\\"", "]"}]], "Input"], Cell["\<\ You know how to \[OpenCurlyDoubleQuote]animate\[CloseCurlyDoubleQuote] things \ already, but now I\[CloseCurlyQuote]ll show you how to do it with graphic \ elements.\ \>", "Subsection", CellChangeTimes->{{3.526312668905446*^9, 3.5263126842318287`*^9}, { 3.528483631675756*^9, 3.528483642521186*^9}, {3.529744351142601*^9, 3.5297443937566013`*^9}, {3.530301388240265*^9, 3.5303014062141314`*^9}}], Cell["\<\ You should know that you can so all this in Matlab as well, but it would look \ rather different.\ \>", "Subsection", CellChangeTimes->{{3.529744434147977*^9, 3.5297444481986103`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["", "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[CellGroupData[{ Cell["The simple pendulum", "Section", CellChangeTimes->{{3.529744480587397*^9, 3.529744485627013*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"\[Phi]0", "=", RowBox[{"99", " ", RowBox[{"Pi", "/", "100"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Phi]0", "=", RowBox[{"10", RowBox[{"Pi", "/", "100"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"tMax", "=", "10"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"eqn", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"\[Phi]", "''"}], "[", "t", "]"}], "+", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"2", " ", "Pi"}], ")"}], "^", "2"}], RowBox[{"Sin", "[", RowBox[{"\[Phi]", "[", "t", "]"}], "]"}]}]}], "\[Equal]", "0"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"sol", "=", RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{"eqn", ",", RowBox[{ RowBox[{"\[Phi]", "[", "0", "]"}], "\[Equal]", "\[Phi]0"}], ",", RowBox[{ RowBox[{ RowBox[{"\[Phi]", "'"}], "[", "0", "]"}], "\[Equal]", "0"}]}], "}"}], ",", "\[Phi]", ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "tMax"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{ RowBox[{"\[Phi]", "[", "t", "]"}], "/.", "sol"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "tMax"}], "}"}], ",", RowBox[{"PlotStyle", "\[Rule]", "Thick"}]}], "]"}]}], "Input", CellChangeTimes->{{3.529746434184004*^9, 3.529746435778345*^9}, { 3.529746469637396*^9, 3.5297466623004103`*^9}, {3.529746716772423*^9, 3.529746744044136*^9}, {3.5303014583577137`*^9, 3.530301490560017*^9}, { 3.530301669367552*^9, 3.530301687286324*^9}, {3.553880143032199*^9, 3.553880164149507*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["", "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[CellGroupData[{ Cell["Animating the pendulum", "Section", CellChangeTimes->{{3.529744480587397*^9, 3.529744485627013*^9}, { 3.530301526114362*^9, 3.5303015359953547`*^9}}], Cell["\<\ We will draw three things: (1) A line at zero, to set the scale and aspect ratio (2) A thick line that represents the pendulum \[OpenCurlyDoubleQuote]string\ \[CloseCurlyDoubleQuote] (3) A black disk that represents the pendulum \[OpenCurlyDoubleQuote]bob\ \[CloseCurlyDoubleQuote]\ \>", "Subsection", CellChangeTimes->{{3.530301775705722*^9, 3.530301895080489*^9}}], Cell[CellGroupData[{ Cell["\<\ Here we set the length of the pendulum, and the position of the bob.\ \>", "Subsection", CellChangeTimes->{{3.530301920899795*^9, 3.530301933277817*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"len", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"xBob", "=", RowBox[{ RowBox[{"len", " ", RowBox[{"Sin", "[", RowBox[{"\[Phi]", "[", "t", "]"}], "]"}]}], "/.", "sol"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"yBob", "=", RowBox[{ RowBox[{ RowBox[{"-", "len"}], " ", RowBox[{"Cos", "[", RowBox[{"\[Phi]", "[", "t", "]"}], "]"}]}], "/.", "sol"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"pBob", "=", RowBox[{"{", RowBox[{ RowBox[{"xBob", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"yBob", "[", RowBox[{"[", "1", "]"}], "]"}]}], "}"}]}], ";"}]}], "Input", CellChangeTimes->{{3.530301631914547*^9, 3.530301648125342*^9}}] }, Open ]], Cell["\<\ Then use \[OpenCurlyDoubleQuote]Show\[CloseCurlyDoubleQuote] to draw all \ three things at the same time...\ \>", "Subsection", CellChangeTimes->{{3.530301959927327*^9, 3.53030198915324*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["", "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[BoxData[ RowBox[{"Animate", "[", RowBox[{ RowBox[{"Show", "[", RowBox[{ RowBox[{"Plot", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"-", "len"}], ",", "len"}], "}"}], ",", RowBox[{"AspectRatio", "\[Rule]", "1"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Graphics", "[", RowBox[{"{", RowBox[{"Thick", ",", RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"pBob", "/.", RowBox[{"t", "\[Rule]", "time"}]}]}], "}"}], "]"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Graphics", "[", RowBox[{"{", RowBox[{"Black", ",", RowBox[{"Disk", "[", RowBox[{ RowBox[{"pBob", "/.", RowBox[{"t", "\[Rule]", "time"}]}], ",", RowBox[{"len", "/", "20"}]}], "]"}]}], "}"}], "]"}]}], "\[IndentingNewLine]", "]"}], ",", RowBox[{"{", RowBox[{"time", ",", "0", ",", "tMax"}], "}"}], ",", RowBox[{"AnimationRate", "\[Rule]", "0.5"}], ",", RowBox[{"AnimationRunning", "\[Rule]", "False"}]}], "]"}]], "Input", CellChangeTimes->{{3.529132212759223*^9, 3.529132231288855*^9}, { 3.5291322742195*^9, 3.529132299328965*^9}, {3.5291323781655283`*^9, 3.529132380475218*^9}, {3.529132415884068*^9, 3.52913243500518*^9}, { 3.5291324801847277`*^9, 3.529132536174953*^9}, {3.52913259793253*^9, 3.529132633557824*^9}, {3.529132732861721*^9, 3.529132858618557*^9}, { 3.529132893907618*^9, 3.529132897232687*^9}, {3.52913300831072*^9, 3.529133079158222*^9}, {3.5291331837872467`*^9, 3.5291332031325417`*^9}, { 3.529133277775585*^9, 3.529133287780199*^9}, {3.5291333785450697`*^9, 3.529133382358384*^9}, {3.5291335792225018`*^9, 3.5291336097165422`*^9}, 3.529133665759981*^9, {3.529133735883556*^9, 3.5291337744864273`*^9}, { 3.529307377215087*^9, 3.52930739418451*^9}, {3.5293074508595877`*^9, 3.5293074797844257`*^9}, {3.5293075870046*^9, 3.529307683382783*^9}, { 3.529349772446965*^9, 3.5293497838403397`*^9}, 3.5293498403198423`*^9, 3.5293966690964823`*^9, {3.529918534596697*^9, 3.5299185358274717`*^9}}] }, Open ]] }, ScreenStyleEnvironment->"Working", WindowSize->{945, 615}, WindowMargins->{{46, Automatic}, {Automatic, 19}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrintingOptions->{"PaperOrientation"->"Landscape", "PaperSize"->{787.56, 603.}}, FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (November 6, \ 2010)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "SlideShowHeader"->{ Cell[2374, 65, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[4340, 129, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[6221, 194, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"]} } *) (*CellTagsIndex CellTagsIndex->{ {"SlideShowHeader", 9057, 265} } *) (*NotebookFileOutline Notebook[{ Cell[557, 20, 682, 9, 83, "Section"], Cell[CellGroupData[{ Cell[1264, 33, 384, 9, 37, "Section"], Cell[1651, 44, 74, 1, 27, "Input"], Cell[1728, 47, 411, 7, 35, "Subsection"], Cell[2142, 56, 195, 4, 26, "Subsection"] }, Open ]], Cell[CellGroupData[{ Cell[2374, 65, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[CellGroupData[{ Cell[2463, 70, 104, 1, 67, "Section"], Cell[2570, 73, 1721, 50, 103, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[4340, 129, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[CellGroupData[{ Cell[4429, 134, 158, 2, 67, "Section"], Cell[4590, 138, 377, 8, 80, "Subsection"], Cell[CellGroupData[{ Cell[4992, 150, 164, 3, 26, "Subsection"], Cell[5159, 155, 796, 26, 73, "Input"] }, Open ]], Cell[5970, 184, 202, 4, 35, "Subsection"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[6221, 194, 64, 1, 63, "SlideShowNavigationBar", CellTags->"SlideShowHeader"], Cell[6288, 197, 2270, 49, 73, "Input"] }, Open ]] } ] *) (* End of internal cache information *)