(* 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[ 16323, 556] NotebookOptionsPosition[ 14771, 505] NotebookOutlinePosition[ 15129, 521] CellTagsIndexPosition[ 15086, 518] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[StyleBox["Random Exponential/Polynomial Growth", FontWeight->"Bold"]], "Text", TextAlignment->Center, FontSize->18], Cell[TextData[{ "In this project, we generate stochastic processes of the form ", Cell[BoxData[ FormBox[ SubscriptBox["Z", "t"], TraditionalForm]]], " = B\[Times]", Cell[BoxData[ FormBox[ SuperscriptBox["A", "t"], TraditionalForm]]], " and ", Cell[BoxData[ FormBox[ SubscriptBox["Z", "t"], TraditionalForm]]], " = B\[Times] ", Cell[BoxData[ FormBox[ SuperscriptBox["t", "A"], TraditionalForm]]], " where B ~ U[c, d] and A ~ U[r, s] with A independent of B. \n\n We \ calculate the sample mean and deviation at a specified time t of randomly \ generated paths in order to compare with the true theoretical values. \ Likewise, we compute sample average area up to time T to compare it with the \ theoretical average area under the curve and the area under the average \ curve." }], "Text", CellChangeTimes->{3.410632985969205*^9}], Cell[TextData[{ "\n", StyleBox["Name", FontWeight->"Bold"], ":" }], "Text", FontSize->16], Cell[CellGroupData[{ Cell["Exercise 0", "Section"], Cell[TextData[{ "(a) Type your name above.\n(b) Execute the codes for ", StyleBox["Z = B*A^t", FontWeight->"Bold"], " below." }], "Text", CellChangeTimes->{{3.4101839592192373`*^9, 3.41018397583152*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Z = B*A^t", "Section", CellChangeTimes->{{3.410183986083476*^9, 3.410183986863902*^9}}], Cell["\<\ Clear variables that will be used :\ \>", "Text", CellChangeTimes->{{3.410184446607888*^9, 3.410184468983819*^9}}], Cell[BoxData[ RowBox[{"Clear", "[", RowBox[{"t", ",", "A", ",", "Z", ",", "B", ",", "g"}], "]"}]], "Input", CellChangeTimes->{3.41018300811569*^9}], Cell["\<\ Enter Initial Parameters :\ \>", "Text", CellChangeTimes->{{3.410184473854265*^9, 3.410184484584455*^9}, { 3.410184546645288*^9, 3.410184547001996*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"num", "=", "3000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"c", "=", "1000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"d", "=", "2000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "=", "0.90"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "=", "1.05"}], ";"}]}], "Input", CellChangeTimes->{3.410183107118846*^9}], Cell["\<\ Create i Random Paths for i from 1 to num and Display the First 20 paths :\ \>", "Text", CellChangeTimes->{ 3.410184489656685*^9, {3.410184548786393*^9, 3.410184568644161*^9}}], Cell[BoxData[ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"B", "[", "i", "]"}], "=", RowBox[{"Random", "[", RowBox[{"Real", ",", RowBox[{"{", RowBox[{"c", ",", "d"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{"A", "[", "i", "]"}], "=", RowBox[{"Random", "[", RowBox[{"Real", ",", RowBox[{"{", RowBox[{"r", ",", "s"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{"Z", "[", RowBox[{"i", ",", "t_"}], "]"}], "=", RowBox[{ RowBox[{"B", "[", "i", "]"}], "*", RowBox[{ RowBox[{"A", "[", "i", "]"}], "^", "t"}]}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}]], "Input"], Cell[BoxData[{ RowBox[{ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{"g", "[", "i", "]"}], "=", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Z", "[", RowBox[{"i", ",", "t"}], "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "20"}], "}"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "20"}], "}"}]}], "]"}], ";"}], "\n", RowBox[{"Show", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"g", "[", "i", "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "20"}], "}"}]}], "]"}], "]"}]}], "Input", CellChangeTimes->{{3.410183062094983*^9, 3.410183083084879*^9}}], Cell["\<\ Graph the Average Curve :\ \>", "Text", CellChangeTimes->{{3.410632988919388*^9, 3.410632999508305*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"av", "[", "t_", "]"}], "=", RowBox[{ FractionBox[ RowBox[{"c", "+", "d"}], "2"], "*", FractionBox[ RowBox[{ SuperscriptBox["s", RowBox[{"t", "+", "1"}]], "-", SuperscriptBox["r", RowBox[{"t", "+", "1"}]]}], RowBox[{ RowBox[{"(", RowBox[{"1", "+", "t"}], ")"}], RowBox[{"(", RowBox[{"s", "-", "r"}], ")"}]}]]}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"av", "[", "t", "]"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "30"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.410632751912032*^9, 3.410632822110539*^9}, { 3.410632906571475*^9, 3.4106329153152943`*^9}, {3.410633937226713*^9, 3.410633953051179*^9}}], Cell["\<\ Compute Sample Mean and Theoretical Mean and Sample Deviation and True Deviation at a Specified Time t:\ \>", "Text", CellChangeTimes->{{3.410184499193055*^9, 3.410184520193096*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"t", "=", "5"}], ";"}], "\n", RowBox[{ RowBox[{"xbar", "=", RowBox[{"Mean", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Z", "[", RowBox[{"i", ",", "t"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{"dev", "=", RowBox[{"StandardDeviation", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Z", "[", RowBox[{"i", ",", "t"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{"realavg", "=", RowBox[{"av", "[", "t", "]"}]}], ";"}], "\n", RowBox[{ RowBox[{"realdev", "=", RowBox[{"Sqrt", "[", RowBox[{ RowBox[{ FractionBox[ RowBox[{ SuperscriptBox["c", "2"], "+", RowBox[{"c", "*", "d"}], "+", SuperscriptBox["d", "2"]}], "3"], "*", FractionBox[ RowBox[{ SuperscriptBox["s", RowBox[{ RowBox[{"2", "*", "t"}], "+", "1"}]], "-", SuperscriptBox["r", RowBox[{ RowBox[{"2", "*", "t"}], "+", "1"}]]}], RowBox[{ RowBox[{"(", RowBox[{"1", "+", RowBox[{"2", "*", "t"}]}], ")"}], RowBox[{"(", RowBox[{"s", "-", "r"}], ")"}]}]]}], "-", RowBox[{ RowBox[{"(", RowBox[{"av", "[", "t", "]"}], ")"}], "^", "2"}]}], "]"}]}], ";"}], "\n", RowBox[{"TableForm", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"xbar", ",", "realavg"}], "}"}], ",", RowBox[{"{", RowBox[{"dev", ",", "realdev"}], "}"}]}], "}"}], ",", RowBox[{"TableHeadings", "\[Rule]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], "}"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.410182827852233*^9, 3.410182880662513*^9}, { 3.41018291624737*^9, 3.410182983097466*^9}, {3.410183419855513*^9, 3.410183479553926*^9}, 3.41063284305389*^9, {3.4106339817581463`*^9, 3.410633001249152*^9}}], Cell["\<\ Average Area Under Curve at Specified time T:\ \>", "Text", CellChangeTimes->{{3.410184526804809*^9, 3.410184533929719*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", "x", "]"}], ";", RowBox[{"T", "=", "5"}], ";"}], "\n", RowBox[{"N", "[", RowBox[{ FractionBox[ RowBox[{"c", "+", "d"}], RowBox[{"2", RowBox[{"(", RowBox[{"s", "-", "r"}], ")"}]}]], "*", RowBox[{"(", RowBox[{ SubsuperscriptBox["\[Integral]", "r", "s"], RowBox[{ FractionBox[ RowBox[{ SuperscriptBox["x", "T"], "-", "1"}], RowBox[{"Log", "[", "x", "]"}]], RowBox[{"\[DifferentialD]", "x"}]}]}], ")"}]}], "]"}]}], "Input", CellChangeTimes->{ 3.410183407102543*^9, {3.4101835611185226`*^9, 3.410183588681602*^9}, 3.410799570394072*^9}], Cell["\<\ Area Under the Average Curve at Same time T:\ \>", "Text", CellChangeTimes->{{3.410184529713772*^9, 3.410184536073732*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", "t", "]"}], ";", RowBox[{"T", "=", "5"}], ";"}], "\n", RowBox[{"N", "[", RowBox[{ SubsuperscriptBox["\[Integral]", "0", "T"], RowBox[{ RowBox[{"av", "[", "t", "]"}], RowBox[{"\[DifferentialD]", "t"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.410183576965584*^9, 3.410183592996059*^9}, { 3.4106340028443937`*^9, 3.410633006261405*^9}}], Cell[TextData[{ "\nSample Average of Area Under the Curves \nwhere ", Cell[BoxData[ RowBox[{ SubsuperscriptBox["\[Integral]", "0", "T"], RowBox[{ RowBox[{"Z", "[", RowBox[{"i", ",", "t"}], "]"}], RowBox[{"\[DifferentialD]", "t"}]}]}]], CellChangeTimes->{{3.410183609281313*^9, 3.410183653431478*^9}}], " = ", Cell[BoxData[ RowBox[{ SubsuperscriptBox["\[Integral]", "0", "T"], RowBox[{ RowBox[{"B", "[", "i", "]"}], "*", RowBox[{ RowBox[{"A", "[", "i", "]"}], "^", "t"}], " ", RowBox[{"\[DifferentialD]", "t"}]}]}]], CellChangeTimes->{{3.410183609281313*^9, 3.410183653431478*^9}}], " = ", Cell[BoxData[ FractionBox[ RowBox[{ RowBox[{"B", "[", "i", "]"}], "*", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"A", "[", "i", "]"}], "^", "T"}], " ", "-", " ", "1"}], ")"}]}], RowBox[{"Log", "[", RowBox[{"A", "[", "i", "]"}], "]"}]]], CellChangeTimes->{{3.410183576965584*^9, 3.410183592996059*^9}}] }], "Text", CellChangeTimes->{{3.410183765778747*^9, 3.410183771248948*^9}, { 3.410183833389183*^9, 3.410183936591518*^9}}], Cell[BoxData[ RowBox[{"Mean", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"B", "[", "i", "]"}], "*", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"A", "[", "i", "]"}], "^", "T"}], "-", "1"}], ")"}], "/", RowBox[{"Log", "[", RowBox[{"A", "[", "i", "]"}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}], "]"}]], "Input", CellChangeTimes->{{3.4101837929093723`*^9, 3.410183819164358*^9}}], Cell["\<\ Re-enter Initial Parameters with Exponential Base Greater than 1 and create \ new random paths:\ \>", "Text", CellChangeTimes->{{3.410184473854265*^9, 3.410184484584455*^9}, { 3.410184546645288*^9, 3.410184547001996*^9}, {3.410184592813706*^9, 3.410184616821692*^9}, {3.410184647080739*^9, 3.410184655397716*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"num", "=", "3000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"c", "=", "1000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"d", "=", "2000"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r", "=", "1.2"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"s", "=", "1.5"}], ";"}]}], "Input", CellChangeTimes->{{3.410184243987191*^9, 3.4101842841468773`*^9}}], Cell[BoxData[ RowBox[{"Do", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"B", "[", "i", "]"}], "=", RowBox[{"Random", "[", RowBox[{"Real", ",", RowBox[{"{", RowBox[{"c", ",", "d"}], "}"}]}], "]"}]}], ";", RowBox[{ RowBox[{"A", "[", "i", "]"}], "=", RowBox[{"Random", "[", RowBox[{"Real", ",", RowBox[{"{", RowBox[{"r", ",", "s"}], "}"}]}], "]"}]}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}]], "Input", CellChangeTimes->{3.410184312160452*^9}], Cell["\<\ Compute sample mean of the time to double, where B*A^t = 2 B has solution t = \ Log[2]/Log[A] :\ \>", "Text", CellChangeTimes->{{3.410184671200377*^9, 3.410184742424324*^9}}], Cell[BoxData[ RowBox[{"Mean", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"Log", "[", "2", "]"}], "/", RowBox[{"Log", "[", RowBox[{"A", "[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "num"}], "}"}]}], "]"}], "]"}]], "Input", CellChangeTimes->{{3.410184423509872*^9, 3.4101844256815157`*^9}, { 3.4101848073646297`*^9, 3.410184815588482*^9}}], Cell["Compute the theoretical mean mean of the doubling time :", "Text", CellChangeTimes->{{3.410184759468395*^9, 3.410184778810494*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Log", "[", "2", "]"}], "/", RowBox[{"(", RowBox[{"s", "-", "r"}], ")"}]}], "*", RowBox[{ SubsuperscriptBox["\[Integral]", "r", "s"], RowBox[{ FractionBox["1", RowBox[{"Log", "[", "x", "]"}]], RowBox[{"\[DifferentialD]", "x"}]}]}]}]], "Input", CellChangeTimes->{{3.4101843308884172`*^9, 3.410184393286357*^9}}] }, Closed]], Cell[CellGroupData[{ Cell["Exercise 1", "Section"], Cell[TextData[{ "Copy and paste the ", StyleBox["Z = B*A^t", FontWeight->"Bold"], " Section of Codes below.\n\nMake the following adjustments:\n\n(i) Make \ the process ", Cell[BoxData[ FormBox[ SubscriptBox["Z", "t"], TraditionalForm]]], " = B\[Times] ", Cell[BoxData[ FormBox[ SuperscriptBox["t", "A"], TraditionalForm]]], " instead.\n\n(ii) Change the formulas for the average curve and for ", StyleBox["realavg", FontWeight->"Bold"], " and ", StyleBox["realdev", FontWeight->"Bold"], " to the values needed\nfor ", Cell[BoxData[ FormBox[ SubscriptBox["Z", "t"], TraditionalForm]]], " = B\[Times] ", Cell[BoxData[ FormBox[ SuperscriptBox["t", "A"], TraditionalForm]]], ".\n\n(iii) Change the expressions for the Average Area Under Curve and the\ \nArea Under the Average Curve as needed.\n\n(iv) Execute the program with \ numerous trials using c = 1, d = 4, r = 0.5, s = 3. Find the mean and \ standard deviation at time t = 4, and find the average areas at time T = 4.\n\ \n(v) Edit the codes to compare the sample average time to triple with the \ theoetical time needed to triple." }], "Text", CellChangeTimes->{{3.410184867759946*^9, 3.41018490826202*^9}, { 3.410184968278112*^9, 3.410185030017733*^9}, {3.41063304300378*^9, 3.4106330526036987`*^9}}] }, Closed]] }, WindowSize->{784, 427}, WindowMargins->{{117, Automatic}, {Automatic, 0}}, Magnification->1.25, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 132, 3, 39, "Text"], Cell[703, 26, 860, 24, 130, "Text"], Cell[1566, 52, 95, 6, 61, "Text"], Cell[CellGroupData[{ Cell[1686, 62, 29, 0, 83, "Section"], Cell[1718, 64, 211, 6, 51, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[1966, 75, 94, 1, 45, "Section"], Cell[2063, 78, 126, 4, 51, "Text"], Cell[2192, 84, 152, 3, 33, "Input"], Cell[2347, 89, 166, 5, 51, "Text"], Cell[2516, 96, 400, 11, 110, "Input"], Cell[2919, 109, 190, 6, 70, "Text"], Cell[3112, 117, 733, 24, 53, "Input"], Cell[3848, 143, 663, 20, 53, "Input"], Cell[4514, 165, 116, 4, 51, "Text"], Cell[4633, 171, 802, 25, 83, "Input"], Cell[5438, 198, 194, 5, 70, "Text"], Cell[5635, 205, 2255, 73, 180, "Input"], Cell[7893, 280, 136, 4, 51, "Text"], Cell[8032, 286, 676, 22, 83, "Input"], Cell[8711, 310, 135, 4, 51, "Text"], Cell[8849, 316, 412, 11, 77, "Input"], Cell[9264, 329, 1126, 35, 84, "Text"], Cell[10393, 366, 512, 15, 33, "Input"], Cell[10908, 383, 330, 7, 51, "Text"], Cell[11241, 392, 424, 11, 110, "Input"], Cell[11668, 405, 563, 18, 53, "Input"], Cell[12234, 425, 185, 4, 32, "Text"], Cell[12422, 431, 418, 11, 33, "Input"], Cell[12843, 444, 138, 1, 32, "Text"], Cell[12984, 447, 391, 12, 58, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[13412, 464, 29, 0, 45, "Section"], Cell[13444, 466, 1311, 36, 322, "Text"] }, Closed]] } ] *) (* End of internal cache information *)