(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing 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[ 359778, 10260]*) (*NotebookOutlinePosition[ 360457, 10283]*) (* CellTagsIndexPosition[ 360413, 10279]*) (*WindowFrame->Normal*) Notebook[{ Cell["\<\ Physics The Art of Free Fall\ \>", "Subtitle", TextAlignment->Center], Cell[TextData[{ "\tThings fall. Most everyone is familiar with the legend of the apple that \ inspired Newton to formulate the classical laws of physics. Modern \ scientists, in physics and in other fields, get their inspiration not only \ from direct physical observation, as in the case of Newton and his apple, but \ also from the observations of 'virtual' systems, where computers are used to \ model the behaviour of physical systems. In this lesson we will use ", StyleBox["Mathematica", FontSlant->"Italic"], " to build ", StyleBox["computational", FontSlant->"Italic"], " models that will represent the falling of objects due to gravity, both \ with and without the influence of air resistance." }], "Text", FontSize->14], Cell[TextData[{ "\tWe can begin by setting some initial constant values, representing the \ initial ", StyleBox["state", FontSlant->"Italic"], " of some object, (in honor of Newton let's call it an apple), which will \ be initially under gravitational acceleration (", StyleBox["Grav=-9.81", "Input"], ", measured here in metric units: meters per second per second), have no \ initial velocity, (", StyleBox["Vel0=0.0", "Input"], "), and have an initial position of 6 meters 'above' some relative point \ (", StyleBox["Pos0=6.0", "Input"], "). All of these will be associated with an initial time,", StyleBox["Tim0", "Input"], ", set at zero. We ask ", StyleBox["Mathematica", FontSlant->"Italic"], " to confirm our output as a list of variables." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Grav = \ \(-9.81\);\)\), "\[IndentingNewLine]", \(\(Vel0 = \ 0.0;\)\), "\[IndentingNewLine]", \(\(Pos0 = \ 6.0;\)\), "\[IndentingNewLine]", \(\(Tim0 = \ 0.0;\)\), "\[IndentingNewLine]", \({Tim0, Pos0, Vel0, Grav}\)}], "Input"], Cell[BoxData[ \({0.`, 6.`, 0.`, \(-9.81`\)}\)], "Output"] }, Open ]], Cell["\<\ \tWhile the starting conditions (represented with the appended 'naught') will \ remain constant, as reminders of our starting point, we also establish state \ variables for time, position, velocity and acceleration that we will expect \ to change as we simulate the falling of the apple. These states all start out \ equal to the initial states.\ \>", "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Acc\ = \ Grav;\)\), "\[IndentingNewLine]", \(\(Vel\ = \ Vel0;\)\), "\[IndentingNewLine]", \(\(Pos\ = \ Pos0;\)\), "\[IndentingNewLine]", \(\(Tim\ = \ Tim0;\)\), "\[IndentingNewLine]", \({Tim, Pos, Vel, Acc}\)}], "Input"], Cell[BoxData[ \({0.`, 6.`, 0.`, \(-9.81`\)}\)], "Output"] }, Open ]], Cell[TextData[{ "\tIn order to observe an object moving, time must pass by. To represent \ the passage of time in our model, we choose a length of time, known as a ", StyleBox["time step", FontSlant->"Italic"], ", and then use the information from where the object was at the beginning \ of the time step to figure out where it will be at the end of the step. \n\t\ ", "In science, change is often represented by the greek letter delta, (\ \[CapitalDelta]), so we will refer to our small change in time as 'delta \ time' through the variable ", StyleBox["Deltime", "Input"], ", measure in seconds." }], "Text", FontSize->14], Cell[BoxData[ \(\(Deltime\ = \ 0.05;\)\)], "Input"], Cell[TextData[{ "\tNow it's time for a change! We anticipate adding some ", StyleBox["Drag", "Input"], " on the apple due to air resistance, but for now we will neglect the drag \ value by setting it to zero. First we adjust the acceleration to balance the \ effects of gravity and air resistance. Acceleration is the change in velocity \ over time, so we multiply by our change in time to determine the velocity \ change and add this value to the old ", StyleBox["Vel", "Input"], "ocity to get a new value. Velocity has a similar relationship and can be \ similarly added to the old ", StyleBox["Pos", "Input"], "ition value. We also add a change in time to adjust the current state in \ ", StyleBox["Tim", "Input"], "e." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Deltime\ = \ 0.05;\)\), "\[IndentingNewLine]", \(\(Drag\ = \ 0.0;\)\), "\[IndentingNewLine]", \(\(Acc\ = \ Grav + Drag;\)\), "\[IndentingNewLine]", \(\(Vel\ = \ Vel + Acc*Deltime;\)\), "\[IndentingNewLine]", \(\(Pos\ \ = \ Pos + Vel*Deltime;\)\), "\[IndentingNewLine]", \(\(Tim\ = \ Tim + Deltime;\)\), "\[IndentingNewLine]", \({Tim, Pos, Vel, Acc}\)}], "Input"], Cell[BoxData[ \({0.05`, 5.975475`, \(-0.49050000000000005`\), \(-9.81`\)}\)], "Output"] }, Open ]], Cell[TextData[{ "\tIn many programming languages there is a shorthand for adding a value to \ a running total, a process also known as ", StyleBox["incrementing", FontSlant->"Italic"], ". Assigning a value using ", StyleBox["+=", "Input"], " tells ", StyleBox["Mathematica", FontSlant->"Italic"], " to increment the value on the left with the value on the right. Using \ this notation, we can repeat the process above to see the state of our apple \ after two time steps, or at .1 seconds after it started falling. " }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Drag\ = \ 0.0;\)\), "\[IndentingNewLine]", \(\(Acc\ = \ Grav + Drag;\)\), "\[IndentingNewLine]", \(\(Vel\ += \ Acc*Deltime;\)\), "\[IndentingNewLine]", \(\(Pos\ += \ Vel*Deltime;\)\), "\[IndentingNewLine]", \(\(Tim\ += \ Deltime;\)\), "\[IndentingNewLine]", \({Tim, Pos, Vel, Acc}\)}], "Input"], Cell[BoxData[ \({0.1`, 5.926425`, \(-0.9810000000000001`\), \(-9.81`\)}\)], "Output"] }, Open ]], Cell[TextData[{ "\tIf", StyleBox[" want to see how the apple continues to fall, we should repeat \ this process a number of times. We let ", FontSize->14], StyleBox["Mathematica", FontSize->14, FontSlant->"Italic"], StyleBox[" do this work for us by using a ", FontSize->14], StyleBox["loop ", FontSize->14, FontSlant->"Italic"], StyleBox["function. One common loop function takes the form ", FontSize->14], StyleBox["Do[", "Input", FontSize->14], StyleBox["expr,", "Input", FontSize->14, FontSlant->"Italic"], StyleBox["{i,", "Input", FontSize->14], StyleBox["imin,imax", "Input", FontSize->14, FontSlant->"Italic"], StyleBox["}]", "Input", FontSize->14], StyleBox[". The loop uses a ", FontSize->14], StyleBox["counter", FontSize->14, FontSlant->"Italic"], StyleBox[", in this case represented by the variable ", FontSize->14], StyleBox["i", "Input", FontSize->14], StyleBox[", to count from ", FontSize->14], StyleBox["imin", "Input", FontSize->14, FontSlant->"Italic"], StyleBox[" to ", FontSize->14], StyleBox["imax", "Input", FontSize->14, FontSlant->"Italic"], StyleBox[", each time evaluating ", FontSize->14], StyleBox["expr", "Input", FontSize->14, FontSlant->"Italic"], StyleBox[". To repeat our time step procedure a set number of times we \ simply place the command inside a ", FontSize->14], StyleBox["Do", "Input", FontSize->14], StyleBox[" loop. We have already done the process twice, so eighteen more \ cycles should show where the apple is after one second.", FontSize->14] }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(Do[\[IndentingNewLine]\((Drag\ = \ 0.0; \[IndentingNewLine]Acc\ = \ Grav + Drag; \[IndentingNewLine]Vel\ += \ Acc*Deltime; \[IndentingNewLine]Pos\ += \ Vel*Deltime; \[IndentingNewLine]Tim\ += \ Deltime;)\), {i, 1, 18}]\), "\[IndentingNewLine]", \({Tim, Pos, Vel, Acc}\)}], "Input"], Cell[BoxData[ \({1.0000000000000002`, 0.8497499999999993`, \(-9.810000000000002`\), \(-9.81`\)}\)], "Output"] }, Open ]], Cell[TextData[{ "\tSo, after one second, the apple is about .85 meters above our measuring \ level (probably the ground). Want if we wanted to know how far the apple had \ fallen in half a second, or at another earlier time? We would need to repeat \ the calculation, because even though our procedure may have calculated the \ value, it has long since overwritten it with new values. One way to keep \ track of that information is to use the ", StyleBox["Table", "Input"], " command, which acts like the ", StyleBox["Do", "Input"], " command as far as repeating an expression, but actually stores the \ results in a list, which in this case we will name as ", StyleBox["StateList", "Input"], ". Notice we reset the state values before generating this list (Why?)." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Vel = \ Vel0;\)\), "\n", \(\(Pos\ = \ Pos0;\)\), "\[IndentingNewLine]", \(\(Tim\ = \ Tim0;\)\), "\[IndentingNewLine]", \(\(Deltime\ = \ 0.05;\)\), "\[IndentingNewLine]", \(\(Steps\ = \ 20;\)\), "\[IndentingNewLine]", \(StateList\ = Table[\((\[IndentingNewLine]Drag\ = \ 0.0; \[IndentingNewLine]Acc\ = \ Grav + Drag; \[IndentingNewLine]Vel\ += \ Acc*Deltime; \[IndentingNewLine]Pos\ += \ Vel*Deltime; \[IndentingNewLine]Tim\ += \ Deltime; \[IndentingNewLine]{Tim, Pos, Vel, Acc})\), {i, 1, Steps}]\)}], "Input"], Cell[BoxData[ \({{0.05`, 5.975475`, \(-0.49050000000000005`\), \(-9.81`\)}, {0.1`, 5.926425`, \(-0.9810000000000001`\), \(-9.81`\)}, \ {0.15000000000000002`, 5.85285`, \(-1.4715000000000003`\), \(-9.81`\)}, {0.2`, 5.7547500000000005`, \(-1.9620000000000002`\), \(-9.81`\)}, {0.25`, 5.632125`, \(-2.4525`\), \(-9.81`\)}, {0.3`, 5.484975`, \(-2.943`\), \(-9.81`\)}, {0.35`, 5.3133`, \(-3.4335`\), \(-9.81`\)}, {0.39999999999999997`, 5.1171`, \(-3.924`\), \(-9.81`\)}, {0.44999999999999996`, 4.896375`, \(-4.4145`\), \(-9.81`\)}, {0.49999999999999994`, 4.6511249999999995`, \(-4.905`\), \(-9.81`\)}, {0.5499999999999999`, 4.381349999999999`, \(-5.3955`\), \(-9.81`\)}, {0.6`, 4.08705`, \(-5.886`\), \(-9.81`\)}, {0.65`, 3.7682249999999997`, \(-6.3765`\), \(-9.81`\)}, {0.7000000000000001`, 3.4248749999999997`, \(-6.867`\), \(-9.81`\)}, {0.7500000000000001`, 3.0569999999999995`, \(-7.3575`\), \(-9.81`\)}, {0.8000000000000002`, 2.6645999999999996`, \(-7.848`\), \(-9.81`\)}, {0.8500000000000002`, 2.2476749999999996`, \(-8.3385`\), \(-9.81`\)}, {0.9000000000000002`, 1.8062249999999995`, \(-8.829`\), \(-9.81`\)}, {0.9500000000000003`, 1.3402499999999995`, \(-9.319500000000001`\), \(-9.81`\)}, \ {1.0000000000000002`, 0.8497499999999993`, \(-9.810000000000002`\), \(-9.81`\)}}\)], \ "Output"] }, Open ]], Cell[TextData[{ "\tHaving generated the list, we might notice that our list does not \ include our initial state, which might be useful. We use one of ", StyleBox["Mathematica", FontSlant->"Italic"], "'s list capabilities to ", StyleBox["Prepend", "Input"], " the initial state to our ", StyleBox["StateList", "Input"], ". Thinking ahead, we also see where it might be easier to set the end \ time of a simulation as opposed to setting the number of steps, which can be \ easily calculated from the start and endtimes and the ", StyleBox["Deltime", "Input"], " time change." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Vel = \ Vel0;\)\), "\n", \(\(Pos\ = \ Pos0;\)\), "\[IndentingNewLine]", \(\(Tim\ = \ Tim0;\)\), "\[IndentingNewLine]", \(\(Deltime\ = \ 0.05;\)\), "\[IndentingNewLine]", \(\(Endtime\ = \ 1.0;\)\), "\[IndentingNewLine]", \(\(Steps\ = \ \((Endtime - \ Tim0)\)/ Deltime;\)\), "\[IndentingNewLine]", \(\(StateList\ = Table[\((\[IndentingNewLine]Drag\ = \ 0.0; \[IndentingNewLine]Acc\ = \ Grav + Drag; \[IndentingNewLine]Vel\ += \ Acc*Deltime; \[IndentingNewLine]Pos\ += \ Vel*Deltime; \[IndentingNewLine]Tim\ += \ Deltime; \[IndentingNewLine]{Tim, Pos, Vel, Acc})\), {i, 1, Steps}];\)\), "\[IndentingNewLine]", \(StateList\ = \ Prepend[StateList, {Tim0, Pos0, Vel0, Grav}]\)}], "Input"], Cell[BoxData[ \({{0.`, 6.`, 0.`, \(-9.81`\)}, {0.05`, 5.975475`, \(-0.49050000000000005`\), \(-9.81`\)}, {0.1`, 5.926425`, \(-0.9810000000000001`\), \(-9.81`\)}, \ {0.15000000000000002`, 5.85285`, \(-1.4715000000000003`\), \(-9.81`\)}, {0.2`, 5.7547500000000005`, \(-1.9620000000000002`\), \(-9.81`\)}, {0.25`, 5.632125`, \(-2.4525`\), \(-9.81`\)}, {0.3`, 5.484975`, \(-2.943`\), \(-9.81`\)}, {0.35`, 5.3133`, \(-3.4335`\), \(-9.81`\)}, {0.39999999999999997`, 5.1171`, \(-3.924`\), \(-9.81`\)}, {0.44999999999999996`, 4.896375`, \(-4.4145`\), \(-9.81`\)}, {0.49999999999999994`, 4.6511249999999995`, \(-4.905`\), \(-9.81`\)}, {0.5499999999999999`, 4.381349999999999`, \(-5.3955`\), \(-9.81`\)}, {0.6`, 4.08705`, \(-5.886`\), \(-9.81`\)}, {0.65`, 3.7682249999999997`, \(-6.3765`\), \(-9.81`\)}, {0.7000000000000001`, 3.4248749999999997`, \(-6.867`\), \(-9.81`\)}, {0.7500000000000001`, 3.0569999999999995`, \(-7.3575`\), \(-9.81`\)}, {0.8000000000000002`, 2.6645999999999996`, \(-7.848`\), \(-9.81`\)}, {0.8500000000000002`, 2.2476749999999996`, \(-8.3385`\), \(-9.81`\)}, {0.9000000000000002`, 1.8062249999999995`, \(-8.829`\), \(-9.81`\)}, {0.9500000000000003`, 1.3402499999999995`, \(-9.319500000000001`\), \(-9.81`\)}, \ {1.0000000000000002`, 0.8497499999999993`, \(-9.810000000000002`\), \(-9.81`\)}}\)], \ "Output"] }, Open ]], Cell[TextData[{ "\tSo now we have a list of states corresponding to each time. We can look \ at individual parts of the list either using the ", StyleBox["Part", "Input"], " command, or the shorthand double-bracket form, both of which require an \ ", StyleBox["index", FontSlant->"Italic"], ", which is a number representing a location within the list. If we wish to \ access our initial state, f", "or example, we would index the first position in the list." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[ \(Part[StateList, 1]\)], "Input"], Cell[BoxData[ \({0.`, 6.`, 0.`, \(-9.81`\)}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(StateList[\([1]\)]\)], "Input"], Cell[BoxData[ \({0.`, 6.`, 0.`, \(-9.81`\)}\)], "Output"] }, Open ]], Cell["\<\ \tBecause each part of the list is also a list, we can use two indices to \ access particular parts. Noting that position is the second element in our \ list of states, we can determine the position at the beginning of the 5th \ time step via\ \>", "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[ \(StateList[\([5, 2]\)]\)], "Input"], Cell[BoxData[ \(5.7547500000000005`\)], "Output"] }, Open ]], Cell[TextData[{ "\tRequesting the positions for ", StyleBox["All", "Input"], " time steps is relatively straightforward:" }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[ \(StateList[\([All, 2]\)]\)], "Input"], Cell[BoxData[ \({6.`, 5.975475`, 5.926425`, 5.85285`, 5.7547500000000005`, 5.632125`, 5.484975`, 5.3133`, 5.1171`, 4.896375`, 4.6511249999999995`, 4.381349999999999`, 4.08705`, 3.7682249999999997`, 3.4248749999999997`, 3.0569999999999995`, 2.6645999999999996`, 2.2476749999999996`, 1.8062249999999995`, 1.3402499999999995`, 0.8497499999999993`}\)], "Output"] }, Open ]], Cell[TextData[{ "\t", StyleBox["ListPlot", "Input"], " provides the means for us to view the data graphically. If we supply a \ single list of numbers, ", StyleBox["Mathematica", FontSlant->"Italic"], " plots them on the y-axis, using their position in the list as the x-axis \ value. The option ", StyleBox["AxesLabel", "Input"], " provides the means for labelling each axis." }], "Text", FontSize->14], Cell[CellGroupData[{ Cell[BoxData[{ \(\(ListPlot[StateList[\([All, 2]\)], AxesLabel \[Rule] {"\