(* 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[ 4788, 170] NotebookOptionsPosition[ 3894, 135] NotebookOutlinePosition[ 4299, 152] CellTagsIndexPosition[ 4256, 149] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Program 01-01: Two dice", "Section", FontColor->RGBColor[1, 0, 0]], Cell["\<\ This program is a simulation for the sum of the face values of two \ distinguishable dice: the dice are rolled 2000 times (see Example 1.1 and \ Problem 1.11) \ \>", "Text", FontSlant->"Italic", FontVariations->{"CompatibilityType"->0}, FontColor->RGBColor[0, 0, 1]], Cell[BoxData[ RowBox[{ RowBox[{"twodice", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", "6"}], "}"}], "]"}], "+", RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", "6"}], "}"}], "]"}]}], "}"}], ",", RowBox[{"{", "2000", "}"}]}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.4404222605562*^9, 3.440422280259*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"sumtwodice", "=", RowBox[{"Flatten", "[", "twodice", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.440421997899*^9, 3.4404220082886*^9}, 3.4404221298438*^9}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"frequency", "=", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"Count", "[", RowBox[{"sumtwodice", ",", "i"}], "]"}], "/", "2000"}], ",", RowBox[{"{", RowBox[{"i", ",", "2", ",", "12"}], "}"}]}], "]"}], "//", "N"}]}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{ "0.0315`", ",", "0.055`", ",", "0.0845`", ",", "0.117`", ",", "0.132`", ",", "0.16`", ",", "0.152`", ",", "0.115`", ",", "0.081`", ",", "0.0455`", ",", "0.0265`"}], "}"}]], "Output", CellChangeTimes->{3.4404219073566*^9, 3.440422140795*^9, 3.4404303144212*^9}] }, Open ]], Cell["\<\ The following bar chart shows the frequencies of the sums. What are the \ corresponding theoretical values?\ \>", "Text", FontSlant->"Italic", FontColor->RGBColor[0, 0, 1]], Cell[BoxData[ RowBox[{"BarChart", "[", RowBox[{"frequency", ",", RowBox[{"ChartLabels", "\[Rule]", RowBox[{"Placed", "[", RowBox[{ RowBox[{"{", RowBox[{ "\"\<2\>\"", ",", "\"\<3\>\"", ",", "\"\<4\>\"", ",", "\"\<5\>\"", ",", "\"\<6\>\"", ",", "\"\<7\>\"", ",", "\"\<8\>\"", ",", "\"\<9\>\"", ",", "\"\<10\>\"", ",", "\"\<11\>\"", ",", "\"\<12\>\""}], "}"}], ",", "Top"}], "]"}]}], ",", RowBox[{"AxesLabel", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\<\>\""}], "}"}]}]}], "]"}]], "Input", CellChangeTimes->{{3.4404224612813997`*^9, 3.4404224758518*^9}, { 3.4404226170629997`*^9, 3.4404226476858*^9}, {3.4404303346544*^9, 3.4404303471812*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"Mean", "[", "sumtwodice", "]"}], "//", "N"}]], "Input"], Cell[BoxData["6.9425`"], "Output", CellChangeTimes->{3.4404219075282*^9, 3.4404221555214*^9, 3.4404303147019997`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"Variance", "[", "sumtwodice", "]"}], "//", "N"}]], "Input"], Cell[BoxData["5.759073286643321`"], "Output", CellChangeTimes->{3.4404219075594*^9, 3.4404221593746*^9, 3.4404303147332*^9} ] }, Open ]], Cell["What are the theoretical mean and variance of the sums?", "Text", FontWeight->"Plain", FontSlant->"Italic", FontColor->RGBColor[0, 0, 1]] }, Open ]] }, WindowSize->{835, 637}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (November 10, 2008)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 73, 1, 71, "Section"], Cell[643, 25, 279, 7, 47, "Text"], Cell[925, 34, 482, 14, 31, "Input"], Cell[1410, 50, 202, 5, 31, "Input"], Cell[CellGroupData[{ Cell[1637, 59, 309, 10, 31, "Input"], Cell[1949, 71, 311, 6, 30, "Output"] }, Open ]], Cell[2275, 80, 184, 5, 29, "Text"], Cell[2462, 87, 754, 18, 52, "Input"], Cell[CellGroupData[{ Cell[3241, 109, 90, 2, 31, "Input"], Cell[3334, 113, 121, 2, 30, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3492, 120, 94, 2, 31, "Input"], Cell[3589, 124, 128, 2, 30, "Output"] }, Open ]], Cell[3732, 129, 146, 3, 29, "Text"] }, Open ]] } ] *) (* End of internal cache information *)