(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 36494, 799] NotebookOptionsPosition[ 35303, 757] NotebookOutlinePosition[ 35805, 778] CellTagsIndexPosition[ 35762, 775] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Leaking Bucket Equation and Reversibility", "Title", CellChangeTimes->{{3.47158560890625*^9, 3.471585639140625*^9}}], Cell["Ulrich Mutze ,www.ulrichmutze.de, 2010-01-11", "Subtitle", CellChangeTimes->{{3.4715857355625*^9, 3.4715857678125*^9}, { 3.47158590925*^9, 3.471585928984375*^9}, 3.472051425796875*^9, { 3.4721935681875*^9, 3.472193568375*^9}}], Cell[TextData[{ "There is a simple and powerful integrator (the 'asynchronous leap-frog \ integrator') for the general ordinary differential equation which is strictly \ reversible in the sense that each discrete trajectory can be reconstructed \ exactly if only the final state is known. It is an interesting question how \ such a behavior manifests itself in situations where the physical process \ represented by the differential equation is not reversible. We are going to \ study this now by considering a simple example.\n \nA well-known irreversible \ physical process is the emptying of a water-filled bucket due to a hole in \ the bottom. The water level ", StyleBox["h ", FontSlant->"Italic"], "above the bottom is a decreasing function of time, for which \ self-suggesting idealizations and considerations (including the choice of \ adjusted units of length and time) yield the differential equation defined \ within the following DSolve function call. Unfortunately ", StyleBox["Mathematica", FontSlant->"Italic"], " 7 does not find the solution, although it is straigtforward to find for a \ human calculator. The solution which satisfies the initial condition ", StyleBox["h", FontSlant->"Italic"], "(0) = ", Cell[BoxData[ FormBox[ SubscriptBox["h", "0"], TraditionalForm]]], " is given as a function definition in (1.3)." }], "Text", CellChangeTimes->{{3.472212580015625*^9, 3.472212603359375*^9}, { 3.47221263553125*^9, 3.47221303215625*^9}, {3.472213072078125*^9, 3.472213123984375*^9}, {3.47221336075*^9, 3.472213371640625*^9}, { 3.472213953640625*^9, 3.472214042328125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"f", "[", "h_", "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"h", "<", "0"}], ",", "0", ",", RowBox[{"-", RowBox[{"Sqrt", "[", "h", "]"}]}]}], "]"}]}], " ", RowBox[{"(*", " ", "1.1", " ", "*)"}]}], "\n", RowBox[{ RowBox[{"DSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"h", "'"}], "[", "t", "]"}], "\[Equal]", RowBox[{"f", "[", RowBox[{"h", "[", "t", "]"}], "]"}]}], ",", RowBox[{ RowBox[{"h", "[", "0", "]"}], "\[Equal]", "h0"}]}], "}"}], ",", RowBox[{"h", "[", "t", "]"}], ",", "t"}], "]"}], " ", RowBox[{"(*", " ", "1.2", " ", "*)"}]}], "\n", RowBox[{ RowBox[{"hExact", "[", RowBox[{"t_", ",", "h0_"}], "]"}], ":=", " ", RowBox[{"If", "[", RowBox[{ RowBox[{"t", ">", RowBox[{"2", " ", RowBox[{"Sqrt", "[", "h0", "]"}]}]}], " ", ",", "0", ",", " ", RowBox[{"h0", "-", RowBox[{"t", " ", RowBox[{"Sqrt", "[", "h0", "]"}]}], " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"t", "/", "2"}], ")"}], "^", "2"}]}]}], "]"}], " ", RowBox[{"(*", " ", "1.3", " ", "*)"}]}]}], "Input", CellChangeTimes->{{3.471586036234375*^9, 3.471586051921875*^9}, { 3.471586104078125*^9, 3.47158612084375*^9}, {3.471586255609375*^9, 3.471586327921875*^9}, 3.47158723040625*^9, 3.471587266609375*^9, { 3.471587348953125*^9, 3.47158739890625*^9}, {3.4715889634375*^9, 3.47158897921875*^9}, {3.471591371890625*^9, 3.471591384609375*^9}, 3.47212626184375*^9, {3.472126605*^9, 3.472126707796875*^9}, { 3.472126792796875*^9, 3.4721268215*^9}, {3.472126900359375*^9, 3.47212690640625*^9}, {3.472127062109375*^9, 3.47212712228125*^9}, 3.4721272193125*^9, {3.472127253890625*^9, 3.472127266140625*^9}, 3.4721273089375*^9, {3.47212738440625*^9, 3.472127394*^9}, { 3.472127633046875*^9, 3.472127646703125*^9}, {3.472128904765625*^9, 3.472128931796875*^9}, {3.472129142140625*^9, 3.472129150625*^9}, { 3.4721292209375*^9, 3.4721292335625*^9}, {3.472129293328125*^9, 3.472129315578125*^9}, 3.47212935796875*^9, {3.4721295998125*^9, 3.472129626328125*^9}, {3.47213130903125*^9, 3.472131367265625*^9}, { 3.472131414328125*^9, 3.472131418609375*^9}, {3.472131799859375*^9, 3.472131878125*^9}, {3.472132669203125*^9, 3.472132682578125*^9}, 3.47213466671875*^9, {3.4721349504375*^9, 3.472134957421875*^9}, { 3.47219418753125*^9, 3.472194200296875*^9}, {3.4721978706875*^9, 3.472197898109375*^9}, {3.472197965546875*^9, 3.47219797596875*^9}, { 3.472198010078125*^9, 3.4721980131875*^9}, {3.472198316359375*^9, 3.472198356453125*^9}, {3.472198984640625*^9, 3.472198996203125*^9}, { 3.472200280484375*^9, 3.472200302921875*^9}}], Cell[TextData[{ "The exact solution for various initial conditions ", Cell[BoxData[ FormBox[ SubscriptBox["h", "0"], TraditionalForm]]], " and time ranges can be studied in the next interactive display:" }], "Text", CellChangeTimes->{{3.472200355984375*^9, 3.472200443*^9}, { 3.472200506328125*^9, 3.472200512015625*^9}, {3.472200544171875*^9, 3.472200601875*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Plot", "[", RowBox[{ RowBox[{"hExact", "[", RowBox[{"t", ",", "h0"}], "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "tMax"}], "}"}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"t", ",", RowBox[{"h", "[", "t", "]"}]}], "}"}]}], ",", RowBox[{ "PlotLabel", "\[Rule]", " ", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"tMax", ",", "2.5"}], "}"}], ",", "0.1", ",", "20"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"h0", ",", "1"}], "}"}], ",", "0.1", ",", "10"}], "}"}]}], "\[IndentingNewLine]", "]"}]], "Input", CellChangeTimes->{{3.472132270609375*^9, 3.472132292796875*^9}, { 3.472132386390625*^9, 3.47213264428125*^9}, {3.472133011890625*^9, 3.472133015859375*^9}, {3.4721334513125*^9, 3.47213353053125*^9}, { 3.472133756921875*^9, 3.47213378465625*^9}, {3.47213383584375*^9, 3.4721338366875*^9}, {3.472134005375*^9, 3.472134019828125*^9}, { 3.472134072203125*^9, 3.472134086328125*^9}, {3.47213415465625*^9, 3.47213420453125*^9}, {3.472134259625*^9, 3.472134260546875*^9}, 3.47213431025*^9, {3.472134497609375*^9, 3.472134506890625*^9}, { 3.472134604640625*^9, 3.472134755015625*^9}, {3.472134848046875*^9, 3.47213486628125*^9}, 3.472134906046875*^9, {3.472135065421875*^9, 3.472135066171875*^9}, {3.472135163953125*^9, 3.47213516940625*^9}, { 3.472135230140625*^9, 3.472135235609375*^9}, {3.472135278046875*^9, 3.47213528315625*^9}, {3.4721353250625*^9, 3.472135333015625*^9}, { 3.4721353681875*^9, 3.472135407484375*^9}, {3.472143877265625*^9, 3.472143968328125*^9}, {3.47214417675*^9, 3.472144177875*^9}, { 3.472144726203125*^9, 3.472144739828125*^9}, {3.4721447945*^9, 3.4721449166875*^9}, 3.472145031546875*^9, {3.472145078234375*^9, 3.472145078875*^9}, 3.47214521946875*^9, {3.472148598921875*^9, 3.4721486301875*^9}, 3.472148684546875*^9, {3.47214875828125*^9, 3.472148792796875*^9}, {3.472187259125*^9, 3.472187348703125*^9}, { 3.472187391453125*^9, 3.472187398765625*^9}, {3.472187507140625*^9, 3.47218752725*^9}, {3.47218765446875*^9, 3.47218766021875*^9}, { 3.47218770028125*^9, 3.472187711234375*^9}, {3.47218776740625*^9, 3.47218790090625*^9}, {3.472187941296875*^9, 3.4721879683125*^9}, 3.47218804984375*^9, 3.47218810103125*^9, 3.4721881578125*^9, { 3.47218818990625*^9, 3.472188217546875*^9}, {3.47218934825*^9, 3.47218936015625*^9}, {3.4721914903125*^9, 3.472191557484375*^9}, { 3.47219162396875*^9, 3.47219169571875*^9}, {3.472191881265625*^9, 3.472191882390625*^9}, {3.472191947109375*^9, 3.47219196096875*^9}, { 3.472192055515625*^9, 3.472192083078125*^9}, {3.472192938921875*^9, 3.47219294925*^9}, {3.472198386921875*^9, 3.472198403203125*^9}, { 3.47219902578125*^9, 3.47219905675*^9}, {3.472199484734375*^9, 3.472199497484375*^9}, 3.47219960571875*^9, {3.472202952203125*^9, 3.47220297915625*^9}, {3.472203011640625*^9, 3.47220302621875*^9}, { 3.47220305671875*^9, 3.472203063828125*^9}, {3.472203915203125*^9, 3.472204004171875*^9}, {3.47220403671875*^9, 3.472204123859375*^9}, { 3.472204157484375*^9, 3.472204189734375*^9}, {3.472206871578125*^9, 3.4722068728125*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`h0$$ = 1, $CellContext`tMax$$ = 2.5, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`tMax$$], 2.5}, 0.1, 20}, {{ Hold[$CellContext`h0$$], 1}, 0.1, 10}}, Typeset`size$$ = { 360., {125., 129.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`tMax$673$$ = 0, $CellContext`h0$674$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`h0$$ = 1, $CellContext`tMax$$ = 2.5}, "ControllerVariables" :> { Hold[$CellContext`tMax$$, $CellContext`tMax$673$$, 0], Hold[$CellContext`h0$$, $CellContext`h0$674$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> Plot[ $CellContext`hExact[$CellContext`t, $CellContext`h0$$], \ {$CellContext`t, 0, $CellContext`tMax$$}, AxesLabel -> {$CellContext`t, $CellContext`h[$CellContext`t]}, PlotLabel -> "The exact solution of the leaking bucket equation"], "Specifications" :> {{{$CellContext`tMax$$, 2.5}, 0.1, 20}, {{$CellContext`h0$$, 1}, 0.1, 10}}, "Options" :> {}, "DefaultOptions" :> {}], ImageSizeCache->{407., {184., 189.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellChangeTimes->{3.47221320303125*^9, 3.472215260984375*^9}] }, Open ]], Cell[TextData[{ "Integrator according to the asynchronous leap - frog method. Notice that \ the function stepALF is defined to take two arguments, the first being of the \ 'type' ", StyleBox["state. ", FontSlant->"Italic"], " In ", StyleBox["Mathematica", FontSlant->"Italic"], " objects have no internal state; the data associated with them have to come \ with the arguments ", StyleBox["x", FontSlant->"Italic"], ", ", StyleBox["v", FontSlant->"Italic"], ", and", StyleBox[" t", FontSlant->"Italic"], ". " }], "Text", CellChangeTimes->{{3.472207471546875*^9, 3.472207503171875*^9}, 3.472207640875*^9, {3.472208635390625*^9, 3.472208641859375*^9}, { 3.472209056640625*^9, 3.47220912946875*^9}, {3.472209165390625*^9, 3.47220932053125*^9}, {3.472214250484375*^9, 3.47221425290625*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"stepALF", "[", RowBox[{ RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], ",", "dt_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"\[Tau]", "=", " ", RowBox[{"dt", "/", "2"}]}], ",", RowBox[{"ta", "=", "t"}], ",", RowBox[{"xa", "=", "x"}], ",", RowBox[{"va", "=", "v"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"ta", "+=", "\[Tau]"}], ";", "\[IndentingNewLine]", RowBox[{"xa", "+=", RowBox[{"va", " ", "\[Tau]"}]}], ";", "\[IndentingNewLine]", RowBox[{"va", " ", "=", " ", RowBox[{ RowBox[{"2", " ", RowBox[{"f", "[", "xa", "]"}]}], "-", "va"}]}], ";", "\[IndentingNewLine]", RowBox[{"xa", "+=", RowBox[{"va", " ", "\[Tau]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ta", "+=", "\[Tau]"}], ";", "\[IndentingNewLine]", RowBox[{"state", "[", RowBox[{"xa", ",", "va", ",", "ta"}], "]"}]}]}], " ", RowBox[{"(*", " ", RowBox[{"return", " ", "value"}], " ", "*)"}], "\[IndentingNewLine]", "]"}], " ", RowBox[{"(*", " ", "1.4", " ", "*)"}]}]], "Input", CellChangeTimes->{{3.4715887518125*^9, 3.471588899640625*^9}, { 3.471589019796875*^9, 3.471589072328125*^9}, {3.47158910915625*^9, 3.471589127125*^9}, {3.4715892146875*^9, 3.47158936934375*^9}, 3.471589558640625*^9, 3.4715911224375*^9, 3.4715931890625*^9, { 3.47159348046875*^9, 3.471593585703125*^9}, {3.47159396259375*^9, 3.471593971*^9}, {3.47210452725*^9, 3.47210455084375*^9}, 3.472121441265625*^9, {3.472123946453125*^9, 3.472124072*^9}, { 3.47212435315625*^9, 3.47212436746875*^9}, {3.472124701578125*^9, 3.472124954453125*^9}, {3.472124999359375*^9, 3.47212505140625*^9}, { 3.472125112171875*^9, 3.47212513028125*^9}, {3.472125706953125*^9, 3.472125856421875*^9}, {3.472125893375*^9, 3.472125954390625*^9}, 3.472193278953125*^9, {3.472193808796875*^9, 3.47219381134375*^9}, { 3.4722075538125*^9, 3.472207576890625*^9}, {3.472208819453125*^9, 3.472208821703125*^9}, {3.47220939725*^9, 3.472209407125*^9}, { 3.472212396875*^9, 3.47221240559375*^9}}], Cell[TextData[{ "Integrator according to the Runge-Kutta second order method. To have the \ same logic as for the leap-frog method, the velocity is made part of the \ state data. Unlike the leap-frog method, the present method needs memory for \ intermediary state data and more than one evaluations of ", StyleBox["f", FontSlant->"Italic"], ". We use this method here for comparison. The method is not reversible and \ the difference in the behavior of the leap-frog method and the Runge-Kutta \ method can be seen in the next display by activating the 'useRK checkbox'." }], "Text", CellChangeTimes->{{3.4722076131875*^9, 3.4722076976875*^9}, { 3.472207765234375*^9, 3.4722079319375*^9}, {3.4722095083125*^9, 3.47220972425*^9}, {3.472211863984375*^9, 3.472211865390625*^9}, 3.472214280296875*^9}], Cell[BoxData[ RowBox[{ RowBox[{"stepRK", "[", RowBox[{ RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], ",", "dt_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"\[Tau]", "=", " ", RowBox[{"dt", "/", "2"}]}], ",", RowBox[{"ta", "=", "t"}], ",", RowBox[{"xa", "=", "x"}], ",", RowBox[{"va", "=", "v"}], ",", "k1", ",", "k2"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"k1", "=", RowBox[{"dt", " ", "va"}]}], ";", "\[IndentingNewLine]", RowBox[{"ta", "+=", "\[Tau]"}], ";", "\[IndentingNewLine]", RowBox[{"k2", "=", " ", RowBox[{"dt", " ", RowBox[{"f", "[", RowBox[{"xa", "+", RowBox[{"k1", "/", "2"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"xa", "+=", "k2"}], ";", "\[IndentingNewLine]", RowBox[{"va", "=", RowBox[{"f", "[", "xa", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ta", "+=", "\[Tau]"}], ";", "\[IndentingNewLine]", RowBox[{"state", "[", RowBox[{"xa", ",", "va", ",", "ta"}], "]"}]}]}], "\[IndentingNewLine]", "]"}], " ", RowBox[{"(*", " ", "1.5", " ", "*)"}]}]], "Input", CellChangeTimes->{{3.4715887518125*^9, 3.471588899640625*^9}, { 3.471589019796875*^9, 3.471589072328125*^9}, {3.47158910915625*^9, 3.471589127125*^9}, {3.4715892146875*^9, 3.47158936934375*^9}, 3.471589558640625*^9, 3.4715911224375*^9, 3.4715931890625*^9, { 3.47159348046875*^9, 3.471593585703125*^9}, {3.47159396259375*^9, 3.471593971*^9}, {3.47210452725*^9, 3.47210455084375*^9}, 3.472121441265625*^9, {3.472123946453125*^9, 3.472124072*^9}, { 3.47212435315625*^9, 3.47212436746875*^9}, {3.472124701578125*^9, 3.472124954453125*^9}, {3.472124999359375*^9, 3.47212505140625*^9}, { 3.472125112171875*^9, 3.47212513028125*^9}, {3.472125706953125*^9, 3.472125856421875*^9}, {3.472125893375*^9, 3.472125954390625*^9}, 3.472193278953125*^9, {3.472193808796875*^9, 3.47219381134375*^9}, { 3.4722075538125*^9, 3.472207576890625*^9}, 3.472207978765625*^9, { 3.4722088229375*^9, 3.4722088240625*^9}, {3.472213902703125*^9, 3.472213913796875*^9}, 3.472214288296875*^9}], Cell["What follows is a common interface of the two integrators :", "Text", CellChangeTimes->{{3.472207983890625*^9, 3.47220804703125*^9}, { 3.472210937984375*^9, 3.47221093884375*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"step", "[", RowBox[{ RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], ",", "dt_", ",", "rk_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"rk", "\[Equal]", "True"}], ",", RowBox[{"stepRK", "[", RowBox[{ RowBox[{"state", "[", RowBox[{"x", ",", "v", ",", "t"}], "]"}], ",", "dt"}], "]"}], ",", RowBox[{"stepALF", "[", RowBox[{ RowBox[{"state", "[", RowBox[{"x", ",", "v", ",", "t"}], "]"}], ",", "dt"}], "]"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4715887518125*^9, 3.471588899640625*^9}, { 3.471589019796875*^9, 3.471589072328125*^9}, {3.47158910915625*^9, 3.471589127125*^9}, {3.4715892146875*^9, 3.47158936934375*^9}, 3.471589558640625*^9, 3.4715911224375*^9, 3.4715931890625*^9, { 3.47159348046875*^9, 3.471593585703125*^9}, {3.47159396259375*^9, 3.471593971*^9}, {3.47210452725*^9, 3.47210455084375*^9}, 3.472121441265625*^9, {3.472123946453125*^9, 3.472124072*^9}, { 3.47212435315625*^9, 3.47212436746875*^9}, {3.472124701578125*^9, 3.472124954453125*^9}, {3.472124999359375*^9, 3.47212505140625*^9}, { 3.472125112171875*^9, 3.47212513028125*^9}, {3.472125706953125*^9, 3.472125856421875*^9}, {3.472125893375*^9, 3.472125954390625*^9}, 3.472193278953125*^9, {3.472193808796875*^9, 3.47219381134375*^9}, { 3.4722075538125*^9, 3.472207576890625*^9}, 3.472207978765625*^9, { 3.472208831125*^9, 3.4722088326875*^9}}], Cell["\<\ These access functions let type state behave as if it were a class with \ internal data (attributes):\ \>", "Text", CellChangeTimes->{{3.4722109613125*^9, 3.472211047453125*^9}, { 3.47221431946875*^9, 3.472214324671875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"time", "[", RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], "]"}], ":=", "t"}], " ", RowBox[{"(*", " ", "1.6", " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"h", "[", RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], "]"}], ":=", " ", "x"}], " ", RowBox[{"(*", " ", "1.7", " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"hDot", "[", RowBox[{"state", "[", RowBox[{"x_", ",", "v_", ",", "t_"}], "]"}], "]"}], ":=", " ", "v", " ", RowBox[{"(*", " ", "1.8", " ", "*)"}]}]}], "Input", CellChangeTimes->{{3.471589728515625*^9, 3.471589795828125*^9}, { 3.471591705328125*^9, 3.4715917775*^9}, {3.471591972203125*^9, 3.471592002796875*^9}, {3.47159404709375*^9, 3.471594100609375*^9}, { 3.471594138765625*^9, 3.47159414325*^9}, {3.47159423453125*^9, 3.471594235703125*^9}, {3.471596155359375*^9, 3.47159617521875*^9}, { 3.472046033859375*^9, 3.472046041390625*^9}, 3.472050578875*^9, { 3.47205074*^9, 3.472050906515625*^9}, {3.47205103121875*^9, 3.4720510618125*^9}, {3.472051095484375*^9, 3.472051096671875*^9}, { 3.472051212046875*^9, 3.472051214015625*^9}, {3.4720513513125*^9, 3.47205135871875*^9}, {3.472051395234375*^9, 3.47205139628125*^9}, { 3.472051676640625*^9, 3.472051678140625*^9}, {3.4721043419375*^9, 3.472104342515625*^9}, {3.472104420171875*^9, 3.4721044220625*^9}, { 3.472104599984375*^9, 3.472104601421875*^9}, {3.4721065988125*^9, 3.472106600328125*^9}, {3.472116741015625*^9, 3.472116763359375*^9}, { 3.47220883425*^9, 3.47220883925*^9}, 3.472213555578125*^9, { 3.47221434034375*^9, 3.47221437746875*^9}}], Cell["\<\ The following interactive display lets the bucket run empty and then change \ the time direction and evolves the state back to the the initial point 0 in \ time. We may switsch between leap-frog integration and second order \ Runge-Kutta. Also, we may choose to inspect the velocity (rate of change of \ the water level) instead of the water level itself. Notice the main point: \ Although the leap-frog integration represents emptying with sufficient \ accuracy from a practical point of view, the slightly non-constant and \ non-zero 'empty' state still carries the information concerning the instant \ of actual emptying and thus allows to follow the trajectory backwards in \ time. Although the asynchronous leap-frog method is exactly reversible, \ numerical noise may prevent actual reversion of computed trajectories over \ very long time spans. \ \>", "Text", CellChangeTimes->{{3.472211123015625*^9, 3.4722111521875*^9}, { 3.472211197703125*^9, 3.4722112218125*^9}, {3.4722112755625*^9, 3.472211447625*^9}, {3.4722115098125*^9, 3.472211793109375*^9}, { 3.472212009890625*^9, 3.47221227390625*^9}, {3.4722133845*^9, 3.472213417828125*^9}, {3.472214420890625*^9, 3.47221459525*^9}, 3.472214639078125*^9, {3.472214696296875*^9, 3.47221482721875*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ "v0", ",", "h0", ",", "t0", ",", "s0", ",", "val", ",", "valr", ",", "lp1", ",", "lp2", ",", RowBox[{"tMin", "=", "0"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"v0", "=", RowBox[{"f", "[", "x0", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"h0", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"showV", "==", "True"}], ",", "v0", ",", "x0"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"t0", "=", "0"}], ";", "\[IndentingNewLine]", RowBox[{"val", "=", RowBox[{"{", RowBox[{"{", RowBox[{"t0", ",", "h0"}], "}"}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"s0", "=", RowBox[{"state", "[", RowBox[{"x0", ",", "v0", ",", "t0"}], "]"}]}], ";", "\n", RowBox[{"While", "[", RowBox[{ RowBox[{"t0", "<", " ", "tMax"}], ",", RowBox[{ RowBox[{"s0", "=", RowBox[{"step", "[", RowBox[{"s0", ",", "dt", ",", "useRK"}], "]"}]}], ";", " ", RowBox[{"t0", "=", RowBox[{"time", "[", "s0", "]"}]}], ";", " ", RowBox[{"h0", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"showV", "==", "True"}], ",", RowBox[{"hDot", "[", "s0", "]"}], ",", RowBox[{"h", "[", "s0", "]"}]}], "]"}]}], ";", RowBox[{"val", "=", RowBox[{"Append", "[", RowBox[{"val", ",", RowBox[{"{", RowBox[{"t0", ",", "h0"}], "}"}]}], "]"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"lp1", "=", RowBox[{"ListLinePlot", "[", RowBox[{"val", ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"t", ",", RowBox[{"h", "[", "t", "]"}]}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ "PlotLabel", "\[Rule]", " ", "\"\\""}]}], "\[IndentingNewLine]", "]"}]}], ";", RowBox[{"(*", " ", RowBox[{ "doing", " ", "a", " ", "line", " ", "plot", " ", "of", " ", "the", " ", "natural", " ", "motion"}], " ", "*)"}], "\n", RowBox[{"valr", "=", RowBox[{"{", RowBox[{"{", RowBox[{"t0", ",", "h0"}], "}"}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{"t0", ">", " ", "tMin"}], ",", " ", RowBox[{ RowBox[{"s0", "=", RowBox[{"step", "[", RowBox[{"s0", ",", RowBox[{"-", "dt"}], ",", "useRK"}], "]"}]}], ";", " ", RowBox[{"t0", "=", RowBox[{"time", "[", "s0", "]"}]}], ";", RowBox[{"h0", "=", RowBox[{"If", "[", RowBox[{ RowBox[{"showV", "==", "True"}], ",", RowBox[{"hDot", "[", "s0", "]"}], ",", RowBox[{"h", "[", "s0", "]"}]}], "]"}]}], ";", RowBox[{"valr", "=", RowBox[{"Append", "[", RowBox[{"valr", ",", RowBox[{"{", RowBox[{"t0", ",", "h0"}], "}"}]}], "]"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"lp2", "=", RowBox[{"ListPlot", "[", RowBox[{"valr", ",", RowBox[{"PlotStyle", "\[Rule]", "Red"}]}], "]"}]}], ";", " ", RowBox[{"(*", RowBox[{ "doing", " ", "a", " ", "list", " ", "plot", " ", "of", " ", "the", " ", "reverse", " ", "motion"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Show", "[", RowBox[{"{", RowBox[{"lp1", ",", "lp2"}], "}"}], "]"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x0", ",", "1"}], "}"}], ",", "0", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"showV", ",", RowBox[{"{", RowBox[{"False", ",", "True"}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{"useRK", ",", RowBox[{"{", RowBox[{"False", ",", "True"}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"dt", ",", "0.02"}], "}"}], ",", "0.001", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"tMax", ",", "2.5"}], "}"}], ",", "1", ",", "10"}], "}"}]}], "]"}], "\[IndentingNewLine]"}]], "Input", CellChangeTimes->{{3.471590241859375*^9, 3.47159024459375*^9}, { 3.471591227125*^9, 3.471591238875*^9}, {3.471592090015625*^9, 3.47159210546875*^9}, {3.471592206890625*^9, 3.47159221746875*^9}, 3.471593778453125*^9, 3.47159381525*^9, {3.471594433734375*^9, 3.4715944510625*^9}, {3.471594495421875*^9, 3.471594511671875*^9}, 3.471594688609375*^9, {3.471595316546875*^9, 3.471595329484375*^9}, { 3.47159590834375*^9, 3.471595917140625*^9}, {3.471596028578125*^9, 3.471596049703125*^9}, 3.471596151140625*^9, {3.4715965165*^9, 3.471596542578125*^9}, 3.471596828828125*^9, 3.47187683865625*^9, { 3.47187690575*^9, 3.47187690709375*^9}, 3.4720431464375*^9, 3.47204636753125*^9, 3.472046658125*^9, {3.472050387671875*^9, 3.472050392046875*^9}, {3.472051600125*^9, 3.4720516610625*^9}, 3.472051702234375*^9, 3.472104322296875*^9, {3.47210663753125*^9, 3.472106729015625*^9}, {3.4721069000625*^9, 3.47210693190625*^9}, { 3.472106981375*^9, 3.47210699928125*^9}, {3.4721131075*^9, 3.472113114234375*^9}, {3.472113212515625*^9, 3.472113220125*^9}, 3.47211326709375*^9, {3.472113386046875*^9, 3.472113439765625*^9}, { 3.472113654265625*^9, 3.472113673828125*^9}, {3.47211372553125*^9, 3.472113751984375*^9}, {3.4721140744375*^9, 3.47211414278125*^9}, { 3.472114232296875*^9, 3.472114251*^9}, 3.472114611703125*^9, { 3.47211660196875*^9, 3.472116608890625*^9}, {3.47211664746875*^9, 3.472116659328125*^9}, {3.472116721890625*^9, 3.472116722453125*^9}, { 3.47211679590625*^9, 3.47211680115625*^9}, 3.472116874890625*^9, 3.47211691396875*^9, {3.472117039953125*^9, 3.47211708428125*^9}, { 3.472117123234375*^9, 3.47211714440625*^9}, {3.4721172225*^9, 3.47211722875*^9}, {3.4721215470625*^9, 3.472121548546875*^9}, { 3.47212168165625*^9, 3.472121808875*^9}, {3.472121845484375*^9, 3.4721218500625*^9}, {3.4721219315*^9, 3.472122009671875*^9}, { 3.472122081125*^9, 3.472122141953125*^9}, {3.472122208046875*^9, 3.472122212671875*^9}, {3.472122335375*^9, 3.47212233975*^9}, { 3.472122528328125*^9, 3.472122529546875*^9}, {3.47212257734375*^9, 3.472122604171875*^9}, {3.47212268096875*^9, 3.4721227553125*^9}, { 3.47212279546875*^9, 3.472122800390625*^9}, {3.472122841046875*^9, 3.472122866796875*^9}, 3.472122951421875*^9, {3.472122994828125*^9, 3.472122996296875*^9}, {3.4721230523125*^9, 3.47212307384375*^9}, { 3.47212313034375*^9, 3.47212313596875*^9}, {3.472123202125*^9, 3.472123205921875*^9}, {3.472125980796875*^9, 3.472126022484375*^9}, { 3.472126411625*^9, 3.472126415578125*^9}, 3.47212646803125*^9, { 3.472126519703125*^9, 3.472126520515625*^9}, {3.472132875671875*^9, 3.47213290571875*^9}, {3.47213331978125*^9, 3.4721333895625*^9}, { 3.47214455540625*^9, 3.472144588140625*^9}, {3.47219217915625*^9, 3.472192330125*^9}, {3.472192435265625*^9, 3.472192439453125*^9}, 3.472192617890625*^9, {3.47219286046875*^9, 3.47219286265625*^9}, 3.472207126375*^9, 3.472207164296875*^9, {3.472207196203125*^9, 3.472207200890625*^9}, {3.472207237*^9, 3.47220724803125*^9}, { 3.472208486453125*^9, 3.47220850159375*^9}, 3.472208841203125*^9, { 3.47221011359375*^9, 3.472210133046875*^9}, {3.47221019859375*^9, 3.47221022171875*^9}, {3.472210275578125*^9, 3.4722102789375*^9}, 3.472210355296875*^9, {3.472210411671875*^9, 3.47221059684375*^9}, { 3.47221071478125*^9, 3.472210779328125*^9}, {3.472210829390625*^9, 3.472210830265625*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`dt$$ = 0.02, $CellContext`showV$$ = False, $CellContext`tMax$$ = 2.5, $CellContext`useRK$$ = False, $CellContext`x0$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`x0$$], 1}, 0, 2}, { Hold[$CellContext`showV$$], {False, True}}, { Hold[$CellContext`useRK$$], {False, True}}, {{ Hold[$CellContext`dt$$], 0.02}, 0.001, 1}, {{ Hold[$CellContext`tMax$$], 2.5}, 1, 10}}, Typeset`size$$ = { 360., {135., 139.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`x0$710$$ = 0, $CellContext`showV$711$$ = False, $CellContext`useRK$712$$ = False, $CellContext`dt$713$$ = 0, $CellContext`tMax$714$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`dt$$ = 0.02, $CellContext`showV$$ = False, $CellContext`tMax$$ = 2.5, $CellContext`useRK$$ = False, $CellContext`x0$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`x0$$, $CellContext`x0$710$$, 0], Hold[$CellContext`showV$$, $CellContext`showV$711$$, False], Hold[$CellContext`useRK$$, $CellContext`useRK$712$$, False], Hold[$CellContext`dt$$, $CellContext`dt$713$$, 0], Hold[$CellContext`tMax$$, $CellContext`tMax$714$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> Module[{$CellContext`v0$, $CellContext`h0$, $CellContext`t0$, \ $CellContext`s0$, $CellContext`val$, $CellContext`valr$, $CellContext`lp1$, \ $CellContext`lp2$, $CellContext`tMin$ = 0}, $CellContext`v0$ = $CellContext`f[$CellContext`x0$$]; \ $CellContext`h0$ = If[$CellContext`showV$$ == True, $CellContext`v0$, $CellContext`x0$$]; $CellContext`t0$ = 0; $CellContext`val$ = {{$CellContext`t0$, $CellContext`h0$}}; \ $CellContext`s0$ = $CellContext`state[$CellContext`x0$$, $CellContext`v0$, \ $CellContext`t0$]; While[$CellContext`t0$ < $CellContext`tMax$$, $CellContext`s0$ = \ $CellContext`step[$CellContext`s0$, $CellContext`dt$$, $CellContext`useRK$$]; \ $CellContext`t0$ = $CellContext`time[$CellContext`s0$]; $CellContext`h0$ = If[$CellContext`showV$$ == True, $CellContext`hDot[$CellContext`s0$], $CellContext`h[$CellContext`s0$]]; $CellContext`val$ = Append[$CellContext`val$, {$CellContext`t0$, $CellContext`h0$}]]; \ $CellContext`lp1$ = ListLinePlot[$CellContext`val$, AxesLabel -> {$CellContext`t, $CellContext`h[$CellContext`t]}, PlotLabel -> "Approximative solution of the leaking bucket equation. \n \ Red dots mark the reversed trajectory. Try the useRK-box ! "]; \ $CellContext`valr$ = {{$CellContext`t0$, $CellContext`h0$}}; While[$CellContext`t0$ > $CellContext`tMin$, $CellContext`s0$ = \ $CellContext`step[$CellContext`s0$, -$CellContext`dt$$, $CellContext`useRK$$]; \ $CellContext`t0$ = $CellContext`time[$CellContext`s0$]; $CellContext`h0$ = If[$CellContext`showV$$ == True, $CellContext`hDot[$CellContext`s0$], $CellContext`h[$CellContext`s0$]]; $CellContext`valr$ = Append[$CellContext`valr$, {$CellContext`t0$, $CellContext`h0$}]]; \ $CellContext`lp2$ = ListPlot[$CellContext`valr$, PlotStyle -> Red]; Show[{$CellContext`lp1$, $CellContext`lp2$}]], "Specifications" :> {{{$CellContext`x0$$, 1}, 0, 2}, {$CellContext`showV$$, {False, True}}, {$CellContext`useRK$$, { False, True}}, {{$CellContext`dt$$, 0.02}, 0.001, 1}, {{$CellContext`tMax$$, 2.5}, 1, 10}}, "Options" :> {}, "DefaultOptions" :> {}], ImageSizeCache->{407., {225., 230.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellChangeTimes->{3.472213203078125*^9, 3.472215261078125*^9}] }, Open ]] }, Open ]] }, WindowToolbars->"EditBar", WindowSize->{983, 779}, WindowMargins->{{81, Automatic}, {Automatic, 109}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, ShowSelection->True, CellLabelAutoDelete->True, ShowCellTags->True, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (January 30, 2009)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 123, 1, 83, "Title"], Cell[693, 25, 239, 3, 49, "Subtitle"], Cell[935, 30, 1625, 31, 155, "Text"], Cell[2563, 63, 2820, 61, 72, "Input"], Cell[5386, 126, 378, 9, 29, "Text"], Cell[CellGroupData[{ Cell[5789, 139, 3481, 64, 92, "Input"], Cell[9273, 205, 2023, 40, 390, "Output"] }, Open ]], Cell[11311, 248, 818, 24, 47, "Text"], Cell[12132, 274, 2248, 48, 192, "Input"], Cell[14383, 324, 815, 14, 65, "Text"], Cell[15201, 340, 2275, 48, 212, "Input"], Cell[17479, 390, 188, 2, 29, "Text"], Cell[17670, 394, 1511, 32, 31, "Input"], Cell[19184, 428, 237, 5, 29, "Text"], Cell[19424, 435, 1734, 34, 72, "Input"], Cell[21161, 471, 1287, 19, 101, "Text"], Cell[CellGroupData[{ Cell[22473, 494, 8265, 177, 412, "Input"], Cell[30741, 673, 4534, 80, 472, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)