(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. 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[ 7393, 212]*) (*NotebookOutlinePosition[ 8046, 235]*) (* CellTagsIndexPosition[ 8002, 231]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Elastic Collision of Two Balls Along a Line", "Title"], Cell["\<\ David Park djmp@earthlink.net http://home.earthlink.net/~djmp/\ \>", "Subtitle"], Cell["\<\ Use as initial data m1, m2, v1, v2 to solve for the velocities of the balls \ after the collision.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(eqns = {m1\ v1 + m2\ v2 \[Equal] m1\ v3 + m2\ v4, m1\ v1\^2 + m2\ v2\^2 \[Equal] m1\ v3\^2 + m2\ v4\^2}\)], "Input"], Cell[BoxData[ \({m1\ v1 + m2\ v2 == m1\ v3 + m2\ v4, m1\ v1\^2 + m2\ v2\^2 == m1\ v3\^2 + m2\ v4\^2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(sols = Solve[eqns, {v3, v4}]\)], "Input"], Cell[BoxData[ \({{v3 \[Rule] v1, v4 \[Rule] v2}, {v3 \[Rule] \(m1\ v1 - m2\ v1 + 2\ m2\ v2\)\/\(m1 + m2\), v4 \[Rule] \(2\ m1\ v1 - m1\ v2 + m2\ v2\)\/\(m1 + m2\)}}\)], "Output"] }, Open ]], Cell["\<\ The first solution is for when the two balls don't collide at all so take the \ second solution.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(vsol = sols\[LeftDoubleBracket]2\[RightDoubleBracket]\)], "Input"], Cell[BoxData[ \({v3 \[Rule] \(m1\ v1 - m2\ v1 + 2\ m2\ v2\)\/\(m1 + m2\), v4 \[Rule] \(2\ m1\ v1 - m1\ v2 + m2\ v2\)\/\(m1 + m2\)}\)], "Output"] }, Open ]], Cell["\<\ Now we need to find out when, tc, and where, x1c and x2c, the balls collide. \ If we want the animation to look nice we should take into account the radii \ of the two balls. Let's make the first ball move from the left with a \ positive velocity, and the second ball move from the right with a negative \ velocity.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(eqns2 = {xc1 == x10 + v1\ tc, xc2 \[Equal] x20 + v2\ tc, xc1 + r1 \[Equal] xc2 - r2}\)], "Input"], Cell[BoxData[ \({xc1 == tc\ v1 + x10, xc2 == tc\ v2 + x20, r1 + xc1 == \(-r2\) + xc2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(xtsol = \(Solve[ eqns2, {xc1, xc2, tc}]\)\[LeftDoubleBracket]1\[RightDoubleBracket]\)], "Input"], Cell[BoxData[ \({xc1 \[Rule] \(-\(\(r1\ v1 + r2\ v1 + v2\ x10 - v1\ x20\)\/\(v1 - v2\)\)\), xc2 \[Rule] \(-\(\(r1\ v2 + r2\ v2 + v2\ x10 - v1\ x20\)\/\(v1 - v2\)\)\), tc \[Rule] \(-\(\(r1 + r2 + x10 - x20\)\/\(v1 - v2\)\)\)}\)], "Output"] }, Open ]], Cell["Now we have the equations we need to make an animation.", "Text"], Cell[BoxData[{ \(Needs["\"]\), "\[IndentingNewLine]", \(Needs["\"]\)}], "Input"], Cell["\<\ The following routine will draw an individual frame of the animation. We want \ all of the frames to have the same PlotRange so we need to calculate the \ maximum and minimum positions of the balls. We calculate everything that is \ fixed when initializing the module. The positions function gives the the \ positions of the two balls as a function of time. We assume that the initial \ time is at t = 0, and calculate the minimum and maximum positions of the two \ balls, with allowance for their radii to obtain the plot range.\ \>", "Text"], Cell[BoxData[ \(picture[t_, tmax_, data : {{m1_, x10_, v1_ /; v1 \[GreaterEqual] 0, r1_}, {m2_, x20_, v2_ /; v2 \[LessEqual] 0, r2_}}] := \[IndentingNewLine]Module[{x1, x2, xc1 = \(-\(\(r1\ v1 + r2\ v1 + v2\ x10 - v1\ x20\)\/\(v1 - v2\)\)\), xc2 = \(-\(\(r1\ v2 + r2\ v2 + v2\ x10 - v1\ x20\)\/\(v1 - v2\)\)\), tc = \(-\(\(r1 + r2 + x10 - x20\)\/\(v1 - v2\)\)\), v3 = \(m1\ v1 - m2\ v1 + 2\ m2\ v2\)\/\(m1 + m2\), v4 = \(2\ m1\ v1 - m1\ v2 + m2\ v2\)\/\(m1 + m2\), positions, s, xmin, xmax, ymax}, \[IndentingNewLine]positions[s_] := If[s \[LessEqual] tc, {x10 + v1\ s, x20 + v2\ s}, {xc1 + v3 \((s - tc)\), xc2 + v4 \((s - tc)\)}]; \[IndentingNewLine]s = Flatten[{positions[0], positions[tmax]}]; \[IndentingNewLine]ymax = Max[r1, r2]; xmin = Min[s] - ymax; xmax = Max[s] + ymax; \[IndentingNewLine]{x1, x2} = positions[t]; \[IndentingNewLine]Show[ Graphics[{\[IndentingNewLine]Line[{{xmin, 0}, {xmax, 0}}], \[IndentingNewLine]Red, Disk[{x1, 0}, r1], \[IndentingNewLine]Blue, Disk[{x2, 0}, r2]}], \[IndentingNewLine]Background \[Rule] Linen, AspectRatio \[Rule] Automatic, PlotRange \[Rule] {{xmin, xmax}, {\(-ymax\), ymax}} 1.2]\[IndentingNewLine]]\)], "Input"], Cell["We can look at individual frames to see if thing look OK.", "Text"], Cell[BoxData[ \(\(picture[10, 10, {{9, \(-5\), 1, 9\^\(1/3\)}, {1, 5, \(-1\), 1}}];\)\)], "Input"], Cell[TextData[{ "So here is a particular animation with ", Cell[BoxData[ \({{m1 \[Equal] 2, x10 \[Equal] \(-5\), v1 \[Equal] 1, r1 == \@2\%3}, {m2 \[Equal] 1, x20 \[Equal] 5, v2 \[Equal] \(-1\), r2 \[Equal] 1}}\)]], ".\n(Everything is in SI units. If you want to develop expressions for more \ general units, and Plot, see the Deunitize routines in my ExtendUnits package \ at my web site.)" }], "Text"], Cell[BoxData[ \(Animate[ picture[t, 10, {{2, \(-5\), 1, 2\^\(1/3\)}, {1, 5, \(-1\), 1}}], {t, 0, 10}]\)], "Input"], Cell["\<\ Here we have two equal masses with the second ball initially at rest.\ \>", "Text"], Cell[BoxData[ \(Animate[ picture[t, 10, {{1, \(-7\), 1, 1}, {1, 0, 0, 1}}], {t, 0, 10}]\)], "Input"] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 683}}, WindowSize->{692, 526}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 60, 0, 150, "Title"], Cell[1802, 53, 90, 4, 122, "Subtitle"], Cell[1895, 59, 122, 3, 33, "Text"], Cell[CellGroupData[{ Cell[2042, 66, 145, 2, 31, "Input"], Cell[2190, 70, 125, 2, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2352, 77, 61, 1, 30, "Input"], Cell[2416, 80, 211, 4, 42, "Output"] }, Open ]], Cell[2642, 87, 120, 3, 33, "Text"], Cell[CellGroupData[{ Cell[2787, 94, 86, 1, 30, "Input"], Cell[2876, 97, 155, 2, 42, "Output"] }, Open ]], Cell[3046, 102, 339, 6, 71, "Text"], Cell[CellGroupData[{ Cell[3410, 112, 126, 2, 30, "Input"], Cell[3539, 116, 110, 2, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3686, 123, 139, 3, 30, "Input"], Cell[3828, 128, 290, 5, 76, "Output"] }, Open ]], Cell[4133, 136, 71, 0, 33, "Text"], Cell[4207, 138, 130, 2, 50, "Input"], Cell[4340, 142, 553, 8, 90, "Text"], Cell[4896, 152, 1497, 26, 360, "Input"], Cell[6396, 180, 73, 0, 33, "Text"], Cell[6472, 182, 111, 2, 31, "Input"], Cell[6586, 186, 437, 9, 96, "Text"], Cell[7026, 197, 133, 3, 31, "Input"], Cell[7162, 202, 93, 2, 33, "Text"], Cell[7258, 206, 119, 3, 30, "Input"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)