(*********************************************************************** 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[ 9442, 332]*) (*NotebookOutlinePosition[ 10285, 359]*) (* CellTagsIndexPosition[ 10241, 355]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ StyleBox["Areas", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->33, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox[" ", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->27, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox["&", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->23, FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox[" ", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->28, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox["Volumes: ", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->33, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox["Monte Carlo Method", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->19, FontWeight->"Plain", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], StyleBox["\nby Dan Bach, Diablo Valley College", TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->19, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}] }], "Title", CellFrame->True, TextAlignment->Center, AspectRatioFixed->True, FontFamily->"Times", FontSize->33, FontWeight->"Bold", FontSlant->"Italic", FontTracking->"Plain", FontColor->RGBColor[1, 0, 0], Background->GrayLevel[0.849989], FontVariations->{"Underline"->False, "Outline"->False, "Shadow"->False}], Cell[CellGroupData[{ Cell["\<\ Say you wanted the area A under y = f (x) , say y = sin(x).\ \>", \ "Section"], Cell[BoxData[ \(<< Graphics`FilledPlot`\)], "Input"], Cell[BoxData[{ \(\(?FilledPlot\)\), "\n", \(Options[FilledPlot]\)}], "Input"], Cell[BoxData[ \(\(FilledPlot[Sin[x], {x, 0, \[Pi]}, PlotStyle \[Rule] Thickness[ .012]];\)\)], "Input"], Cell[BoxData[ \(\(FilledPlot[{0, Sin[x]}, {x, 0, \[Pi]}, PlotStyle \[Rule] Thickness[ .012]];\)\)], "Input"], Cell[BoxData[ \(\(FilledPlot[{0, Sin[x], 1}, {x, 0, \[Pi]}, PlotStyle \[Rule] Thickness[ .012]];\)\)], "Input"], Cell[BoxData[ \(\(graf = FilledPlot[{0, Sin[x], 1}, {x, 0, \[Pi]}, PlotStyle \[Rule] Thickness[ .012], Fills \[Rule] {{{1, 2}, RGBColor[ .5, 1, .5]}, {{2, 3}, RGBColor[1, .6, .5]}}, Curves \[Rule] Front];\)\)], "Input"], Cell[CellGroupData[{ Cell["\<\ The area under the curve is a certain fraction of the rectangle; let's scatter random points and count the proportions!\ \>", "Subsection"], Cell[BoxData[{ RowBox[{\(n = 300\ ;\), StyleBox[ RowBox[{" ", StyleBox[" ", FontWeight->"Plain"]}]], StyleBox[\( (*\ number\ of\ points\ in\ sample\ *) \), FontWeight->"Plain"]}], "\n", \(xs = Table[\[Pi]*Random[], {n}];\), "\n", \(ys = Table[1*Random[], {n}];\), "\n", \(coords = Transpose[{xs, ys}];\), "\n", \(pts = ListPlot[coords];\)}], "Input"], Cell[BoxData[ \(\(Show[graf, pts];\)\)], "Input"], Cell[BoxData[{ \(\(colpts = Graphics[ Table[{PointSize[ .015], \[IndentingNewLine]Hue[ If[coords[\([i, 2]\)] < Sin[coords[\([i, 1]\)]], .6, .05]], Point[coords[\([i]\)]]}, {i, 1, n}]];\)\), "\n", \(\(Show[colpts];\)\)}], "Input"], Cell[BoxData[ \(\(Show[graf, colpts];\)\)], "Input"], Cell[BoxData[ \(hits = Length[Select[coords, #[\([2]\)] < Sin[#[\([1]\)]] &]]\)], "Input"], Cell[BoxData[ \(hitpct = 100 N[hits/n, 8]\)], "Input"], Cell[BoxData[ \(An = N[\[Pi]*\((hits/n)\), 8]\)], "Input"], Cell[BoxData[ \(A = N[\[Integral]\_0\%\[Pi] Sin[x] \[DifferentialD]x, 8]\)], "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Now in 3D: to estimate the volume V under z = f (x,y)...", "Section"], Cell[CellGroupData[{ Cell["\<\ Let's fill a big box with random points and count how many are \ under the surface.\ \>", "Subsection"], Cell[BoxData[ \(f[x_, y_] := 2 - Sin[x\ y]\)], "Input"], Cell[BoxData[ \(\(surf\ = \ Plot3D[f[x, y], {x, \(-2\), 2}, {y, \(-1\), 2}, ViewPoint \[Rule] {1, 3, 1}, PlotPoints \[Rule] 25, PlotRange \[Rule] {0, 3}];\)\)], "Input"], Cell[BoxData[{ \(\(net := Graphics3D[surf] /. Polygon[{a_, b_, c_, d_}] \[RuleDelayed] {Hue[ .35], Line[{a, b, c, d, a}]};\)\), "\[IndentingNewLine]", \(\(Show[net];\)\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Ok, this is a 4 x 3 x 3 box, Vbox = 36. We fill the box with n \ points.\ \>", "Subsection"], Cell[BoxData[ \(<< Graphics`Graphics3D`\)], "Input"], Cell[BoxData[{ \(\(n\ = \ 300;\)\), "\[IndentingNewLine]", \(\(xs = Table[\(-2\) + 4*Random[], {n}];\)\), "\n", \(\(ys = Table[\(-1\) + 3*Random[], {n}];\)\), "\n", \(\(zs = Table[\ 0\ + \ 3*Random[], {n}];\)\), "\n", \(\(coords = Transpose[{xs, ys, zs}];\)\), "\n", \(\(pts = ScatterPlot3D[coords];\)\)}], "Input"], Cell[BoxData[ \(Do[Show[pts, ViewPoint \[Rule] {8 Cos[t], 8 Sin[t], 3}, SphericalRegion \[Rule] True, Axes \[Rule] None], {t, 1, 1.1, .01}]\)], "Input"], Cell[BoxData[ \(Do[Show[net, pts, ViewPoint \[Rule] {8 Cos[t], 8 Sin[t], 3}, SphericalRegion \[Rule] True, Axes \[Rule] None], {t, 1, 2, .1}]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ The points below the surface are blue, the ones above it are \ orange.\ \>", "Subsection"], Cell[BoxData[{ \(\(c3Dpts = Graphics3D[ Table[{PointSize[ If[n < 1000, .015, .007]], \[IndentingNewLine]Hue[ If[coords[\([i, 3]\)] < f[coords[\([i, 1]\)], coords[\([i, 2]\)]], .6, .05]], Point[coords[\([i]\)]]}, {i, 1, n}]];\)\), "\n", \(\(Show[c3Dpts];\)\)}], "Input"], Cell[BoxData[ \(\(Show[net, c3Dpts];\)\)], "Input"], Cell[BoxData[ \(Do[Show[net, c3Dpts, ViewPoint \[Rule] {8 Cos[t], 8 Sin[t], 3}, SphericalRegion \[Rule] True, Axes \[Rule] None], {t, 1, 1.3, .02}]\)], "Input"], Cell[BoxData[ \(hits = Length[Select[ coords, #[\([3]\)] < f[#[\([1]\)], #[\([2]\)]] &]]\)], "Input"], Cell[BoxData[ \(hitpct = 100 N[hits/n, 8]\)], "Input"], Cell[BoxData[ \(Vn = N[36*\((hits/n)\), 8]\)], "Input"], Cell[BoxData[ \(V = Chop[N[\[Integral]\_\(-2\)\%2\(\[Integral]\_\(-1\)\%2 f[x, y] \[DifferentialD]y \[DifferentialD]x\), 8]]\)], "Input"] }, Open ]] }, Open ]] }, Open ]] }, FrontEndVersion->"4.0 for Macintosh", ScreenRectangle->{{0, 800}, {0, 580}}, WindowSize->{728, 508}, WindowMargins->{{9, Automatic}, {Automatic, 21}}, MacintoshSystemPageSetup->"\<\ AVU/I@1804P000002NbWD?oQon82n@9613N3D0VYAbP0AP1Y06`0I@1^0649k:M@ 2Nbf/1000004=h<`2JU7:4IYK6E^HFeU000000W/][09k;K@400000@gPa09ZDLX ?mB" ] (*********************************************************************** 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, 2563, 97, 152, "Title"], Cell[CellGroupData[{ Cell[4327, 152, 90, 3, 56, "Section"], Cell[4420, 157, 56, 1, 27, "Input"], Cell[4479, 160, 86, 2, 43, "Input"], Cell[4568, 164, 116, 2, 27, "Input"], Cell[4687, 168, 121, 2, 27, "Input"], Cell[4811, 172, 124, 2, 27, "Input"], Cell[4938, 176, 274, 5, 59, "Input"], Cell[CellGroupData[{ Cell[5237, 185, 149, 3, 64, "Subsection"], Cell[5389, 190, 435, 10, 91, "Input"], Cell[5827, 202, 53, 1, 27, "Input"], Cell[5883, 205, 290, 6, 75, "Input"], Cell[6176, 213, 56, 1, 27, "Input"], Cell[6235, 216, 101, 2, 27, "Input"], Cell[6339, 220, 59, 1, 27, "Input"], Cell[6401, 223, 62, 1, 27, "Input"], Cell[6466, 226, 89, 1, 42, "Input"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[6604, 233, 78, 0, 56, "Section"], Cell[CellGroupData[{ Cell[6707, 237, 114, 3, 46, "Subsection"], Cell[6824, 242, 59, 1, 27, "Input"], Cell[6886, 245, 205, 4, 43, "Input"], Cell[7094, 251, 225, 5, 59, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7356, 261, 102, 3, 46, "Subsection"], Cell[7461, 266, 56, 1, 27, "Input"], Cell[7520, 269, 346, 6, 107, "Input"], Cell[7869, 277, 177, 3, 43, "Input"], Cell[8049, 282, 179, 3, 43, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8265, 290, 100, 3, 46, "Subsection"], Cell[8368, 295, 369, 8, 75, "Input"], Cell[8740, 305, 55, 1, 27, "Input"], Cell[8798, 308, 185, 3, 43, "Input"], Cell[8986, 313, 122, 3, 27, "Input"], Cell[9111, 318, 59, 1, 27, "Input"], Cell[9173, 321, 59, 1, 27, "Input"], Cell[9235, 324, 167, 3, 43, "Input"] }, Open ]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)