(* 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[ 7870, 214] NotebookOptionsPosition[ 7440, 197] NotebookOutlinePosition[ 7879, 214] CellTagsIndexPosition[ 7836, 211] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"RandomPoint", "[", "]"}], ":=", RowBox[{"{", RowBox[{ RowBox[{"RandomReal", "[", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}], "]"}], ",", RowBox[{"RandomReal", "[", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}], "]"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"RandomList", "[", "length_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RandomPoint", "[", "]"}], ",", RowBox[{"{", "length", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"IsIn", "[", "point_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"point", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "^", "2"}], " ", "+", " ", RowBox[{ RowBox[{"point", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "^", "2"}]}], " ", "\[LessEqual]", "1"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"numInside", "[", "points_List", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", "in"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"in", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", " ", "\[LessEqual]", RowBox[{"Length", "[", "points", "]"}]}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"IsIn", "[", RowBox[{ "points", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}], ",", " ", RowBox[{"in", "++"}]}], "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"{", RowBox[{"in", ",", RowBox[{ RowBox[{"Length", "[", "points", "]"}], "-", "in"}]}], "}"}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gen", "[", "points_List", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"label", ",", "inside"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"inside", "=", RowBox[{"numInside", "[", "points", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"label", "=", RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{ RowBox[{ "inside", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "+", RowBox[{ "inside", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "]"}], "<>", "\"\<\\nNumber Inside = \>\"", "<>", RowBox[{"ToString", "[", RowBox[{ "inside", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}], "<>", "\"\<\\nEstimate for \[Pi] = \>\"", "<>", RowBox[{"ToString", "[", RowBox[{"4", "*", RowBox[{"N", "[", RowBox[{ RowBox[{ RowBox[{ "inside", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "/", RowBox[{"(", RowBox[{ RowBox[{ "inside", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "+", RowBox[{ "inside", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ")"}]}], ",", "5"}], "]"}]}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"Labeled", "[", RowBox[{ RowBox[{"Show", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"ListPlot", "[", RowBox[{"points", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"Opacity", "[", "0.5", "]"}]}]}], "]"}], ",", RowBox[{"Graphics", "[", RowBox[{"{", RowBox[{"Thick", ",", RowBox[{"Circle", "[", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", "1"}], "]"}]}], "}"}], "]"}]}], "}"}], ",", RowBox[{"AspectRatio", "\[Rule]", "1"}]}], "]"}], ",", "label"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "Input", CellChangeTimes->{{3.4615132673794937`*^9, 3.461513325393029*^9}, { 3.461513381376292*^9, 3.461513417789442*^9}, {3.461513559790889*^9, 3.46151356298449*^9}, {3.461513600149234*^9, 3.4615136060033007`*^9}, { 3.461513639745823*^9, 3.461513649085218*^9}, {3.461513855460206*^9, 3.461513855606687*^9}, {3.461514003334586*^9, 3.4615140038406553`*^9}, { 3.46151450992754*^9, 3.461514518937469*^9}, {3.461514662274558*^9, 3.461514702833572*^9}, {3.461515774989401*^9, 3.461515818790072*^9}, { 3.461515981198677*^9, 3.461516012639641*^9}, {3.461516073249679*^9, 3.461516088177898*^9}, {3.461516165045474*^9, 3.461516211254129*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"animate", "[", "num_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"list", ",", "rate"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"num", "\[GreaterEqual]", "30"}], ",", " ", "\[IndentingNewLine]", RowBox[{"rate", " ", "=", " ", RowBox[{"Floor", "[", RowBox[{"num", "/", "30"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"rate", " ", "=", " ", "1"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"list", " ", "=", " ", RowBox[{"RandomList", "[", "num", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"ListAnimate", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"gen", "[", RowBox[{"Take", "[", RowBox[{"list", ",", RowBox[{"i", "*", "rate"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "30"}], " ", "}"}]}], "]"}], ",", RowBox[{"AnimationRepetitions", "\[Rule]", "1"}]}], "]"}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input", CellChangeTimes->{{3.4615145637826366`*^9, 3.461514632295391*^9}, { 3.461515044590057*^9, 3.461515049751539*^9}, {3.461515135151441*^9, 3.461515348084248*^9}, {3.461515382954381*^9, 3.461515388536948*^9}, { 3.4615154447819853`*^9, 3.4615154478411503`*^9}, {3.461515589060676*^9, 3.461515591377924*^9}, {3.461515630877488*^9, 3.461515639210246*^9}, { 3.461515827994153*^9, 3.461515846591679*^9}}], Cell[BoxData[ RowBox[{"animate", "[", "5000", "]"}]], "Input", CellChangeTimes->{{3.461516943752108*^9, 3.461516945583417*^9}}] }, WindowSize->{1254, 909}, WindowMargins->{{21, Automatic}, {Automatic, 0}}, Magnification:>FEPrivate`If[ FEPrivate`Equal[FEPrivate`$VersionNumber, 6.], 1.5, 1.5 Inherited], FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (November 10, 2008)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[545, 20, 5072, 131, 459, "Input"], Cell[5620, 153, 1684, 38, 226, "Input"], Cell[7307, 193, 129, 2, 40, "Input"] } ] *) (* End of internal cache information *)