(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of 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[ 40899, 1433]*) (*NotebookOutlinePosition[ 41798, 1464]*) (* CellTagsIndexPosition[ 41754, 1460]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Using a Monte Carlo Method for Definite Integration", "Title", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Steven Keltner and Scott Sloan\nUniversity of Missouri-Rolla"], "Subtitle", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Times", FontSize->14], Cell[TextData[ "Mathematica in Education\nVolume 3 Number 1\nWinter 1994\n(c) \ TELOS/Springer-Verlag"], "Subsubtitle", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell[TextData["Introduction"], "Section", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[StyleBox[ "During our second semester Calculus class, we learned about many types of \ integration. After learning about integrating by using antiderivatives, we \ explored numerical integration with the Trapezoid Method and Simpson's Rule. \ Our professor mentioned that it would be possible to evaluate definite \ integrals by generating random points and determining whether or not they \ fell under the area of the function. He said that a Mathematica program \ could be created that would perform the operations. We were very interested \ in exploring the idea of using a Monte Carlo method to evaluate definite \ integrals. Since we wanted to test the accuracy and precision of the method, \ it was necessary to design a program that would perform the procedure several \ times with varying numbers of random points for each calculation.", FontFamily->"Palatino"]], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData[ "Programming a Monte Carlo Method of Integration "], "Section", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "The program evaluates definite integrals by creating a \"box\" with \ dimensions defined by the limits of integration and the maximum and minimum \ values of the function on the selected interval. The computer randomly \ generates the coordinates of a point within the box. The function is \ evaluated at the randomly selected x value. If the random point falls within \ the area of the integral, it is counted by Mathematica. After performing the \ procedure for the specified number of points (iterations), the computer \ calculates the final result by multiplying the total area of the box by the \ percentage of points that fell within the bounds of the integral. Of course, \ many functions have regions that fall below the line y=0. If the program \ encounters a point that is within the area of the integral but below the \ x-axis, it subtracts one from the total number of points counted.\n One \ would expect that the more points generated for each evaluation of the \ integral, the more accurate the answer will be. Since random numbers are \ used, however, there will always be variation from one determination to the \ next. Because of the lack of precision, the program is designed to perform \ many calculations with a varying number of iterations. Doing so makes it \ possible to \"zero in on\" the actual answer.\n The first part of the \ program defines the parameters: "], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "f[x_]= Sin[x];\nbegint= -1;\nendint= 1;\nminit= 100;\nmaxit= 300;\nstepsize= \ 100;\ntrial= 3;\n"], "Input", AspectRatioFixed->True], Cell[TextData[{ "The function is input as ", StyleBox["f[x]", FontWeight->"Bold"], ", while the limits of integration are specified by ", StyleBox["begint", FontWeight->"Bold"], " and", StyleBox[" endint", FontWeight->"Bold"], ". Since the program graphs the approximated value of the definite \ integral versus the number of iterations (points) used, the minimum and \ maximum number of iterations must be input as ", StyleBox["minit", FontWeight->"Bold"], " and ", StyleBox["maxit", FontWeight->"Bold"], " . The distance between successive iteration values is determined by the \ ", StyleBox["stepsize", FontWeight->"Bold"], ". The number of calculations performed at each value is specified by the", StyleBox[" trial", FontWeight->"Bold"], " statement. \tThus, given the parameters above, the computer would use 100 \ random points in each of three separate determinations, 200 points each in \ three additional calculations, and 300 points for three final computations.\n \ The following lines determine the maximum and minimum value of the \ function on the specified interval. The program uses these results as \ boundaries between which random y values are selected. The values are also \ necessary to determine the area of the \"box.\"" }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "miny = Min[Table[N[f[x]],{x,begint,endint,0.01}]];\nmaxy = \ Max[Table[N[f[x]],{x,begint,endint,0.01}]];"], "Input", AspectRatioFixed->True], Cell[TextData[{ " The next part of the program generates random coordinates and \ determines how each point should be counted. If the random y value ", StyleBox["r", FontWeight->"Bold"], " is less than or equal to the function evaluated at the random x value ", StyleBox["s", FontWeight->"Bold"], ", it is counted." }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "Do[Do[Counter = 0;\nDo[r = Random[Real, {miny,maxy}]; \ns = \ Random[Real,{begint,endint}];\nIf[r <= f[s] && r >= 0, Counter=Counter+1, \ Counter=Counter];\nIf[r >= f[s] && r < 0, Counter=Counter-1, \ Counter=Counter];\n {i,1,k}];"], "Input", AspectRatioFixed->True], Cell[TextData[{ " The portion of the program that follows determines the final result \ for each trial. The number of points counted is divided by the total number \ of points,", StyleBox[" k", FontWeight->"Bold"], ", and multiplied by the area of the box. The process is repeated for \ values of ", StyleBox["k", FontWeight->"Bold"], " ranging from ", StyleBox["minit", FontWeight->"Bold"], " to ", StyleBox["maxit", FontWeight->"Bold"], "." }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "AppendTo[v,N[(Counter/k)*((endint-begint)*(maxy-miny))]];\n\ AppendTo[z,k],{j,1,trials}];\n,{k,minit,maxit,stepsize}];"], "Input", AspectRatioFixed->True], Cell[TextData[ " After transposing the data, the information is plotted:"], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "data=Transpose[{z,v}];\nListPlot[data,PlotRange->All];\n"], "Input", AspectRatioFixed->True], Cell[TextData[ " In order to test the accuracy of the results, we ran the program for a \ function that could be easily integrated. The actual value of the definite \ integral was plotted along with the Monte Carlo results by replacing the two \ lines above with the following commands:"], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "data=Transpose[{z,v}];\n\ points=ListPlot[data,DisplayFunction->Identity,PlotRange->All];\n\ value=NIntegrate[f[x],{x,begint,endint}];\nactualval=Plot[value,{x,minit - \ 25, maxit},DisplayFunction->\n Identity];\n\ Show[points,actualval,DisplayFunction->$DisplayFunction]"], "Input", AspectRatioFixed->True], Cell[TextData[ "The parameters used in Graph 1 are as follows:\n f[x] = x^2 - 1\n \ begint = 0\n endint = 2\n minit = 1000\n maxit = 9000\n \ stepsize = 2000\n trials = 9"], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[GraphicsData["PostScript", "\<\ %! %%Creator: Mathematica %%AspectRatio: 0.61803 MathPictureStart /Courier findfont 10 scalefont setfont % Scaling calculations -0.0790793 0.000105527 -0.484102 1.24704 [ [(2000)] 0.13197 0.01472 0 2 Msboxa [(4000)] 0.34303 0.01472 0 2 Msboxa [(6000)] 0.55408 0.01472 0 2 Msboxa [(8000)] 0.76514 0.01472 0 2 Msboxa [(10000)] 0.97619 0.01472 0 2 Msboxa [(0.5)] -0.00716 0.13942 1 0 Msboxa [(0.6)] -0.00716 0.26412 1 0 Msboxa [(0.7)] -0.00716 0.38883 1 0 Msboxa [(0.8)] -0.00716 0.51353 1 0 Msboxa [ -0.001 -0.001 0 0 ] [ 1.001 0.61903 0 0 ] ] MathScale % Start of Graphics 1 setlinecap 1 setlinejoin newpath %%Object: Graphics [ ] 0 setdash 0 setgray gsave gsave 0.002 setlinewidth 0.13197 0.01472 moveto 0.13197 0.02097 lineto stroke grestore [(2000)] 0.13197 0.01472 0 2 Mshowa gsave 0.002 setlinewidth 0.34303 0.01472 moveto 0.34303 0.02097 lineto stroke grestore [(4000)] 0.34303 0.01472 0 2 Mshowa gsave 0.002 setlinewidth 0.55408 0.01472 moveto 0.55408 0.02097 lineto stroke grestore [(6000)] 0.55408 0.01472 0 2 Mshowa gsave 0.002 setlinewidth 0.76514 0.01472 moveto 0.76514 0.02097 lineto stroke grestore [(8000)] 0.76514 0.01472 0 2 Mshowa gsave 0.002 setlinewidth 0.97619 0.01472 moveto 0.97619 0.02097 lineto stroke grestore [(10000)] 0.97619 0.01472 0 2 Mshowa gsave 0.001 setlinewidth 0.17419 0.01472 moveto 0.17419 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.2164 0.01472 moveto 0.2164 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.25861 0.01472 moveto 0.25861 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.30082 0.01472 moveto 0.30082 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.38524 0.01472 moveto 0.38524 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.42745 0.01472 moveto 0.42745 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.46966 0.01472 moveto 0.46966 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.51187 0.01472 moveto 0.51187 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.59629 0.01472 moveto 0.59629 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.6385 0.01472 moveto 0.6385 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.68071 0.01472 moveto 0.68071 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.72293 0.01472 moveto 0.72293 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.80735 0.01472 moveto 0.80735 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.84956 0.01472 moveto 0.84956 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.89177 0.01472 moveto 0.89177 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.93398 0.01472 moveto 0.93398 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.08976 0.01472 moveto 0.08976 0.01847 lineto stroke grestore gsave 0.001 setlinewidth 0.04755 0.01472 moveto 0.04755 0.01847 lineto stroke grestore gsave 0.002 setlinewidth 0 0.01472 moveto 1 0.01472 lineto stroke grestore gsave 0.002 setlinewidth 0.00534 0.13942 moveto 0.01159 0.13942 lineto stroke grestore [(0.5)] -0.00716 0.13942 1 0 Mshowa gsave 0.002 setlinewidth 0.00534 0.26412 moveto 0.01159 0.26412 lineto stroke grestore [(0.6)] -0.00716 0.26412 1 0 Mshowa gsave 0.002 setlinewidth 0.00534 0.38883 moveto 0.01159 0.38883 lineto stroke grestore [(0.7)] -0.00716 0.38883 1 0 Mshowa gsave 0.002 setlinewidth 0.00534 0.51353 moveto 0.01159 0.51353 lineto stroke grestore [(0.8)] -0.00716 0.51353 1 0 Mshowa gsave 0.001 setlinewidth 0.00534 0.03966 moveto 0.00909 0.03966 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.0646 moveto 0.00909 0.0646 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.08954 moveto 0.00909 0.08954 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.11448 moveto 0.00909 0.11448 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.16436 moveto 0.00909 0.16436 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.1893 moveto 0.00909 0.1893 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.21424 moveto 0.00909 0.21424 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.23918 moveto 0.00909 0.23918 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.28906 moveto 0.00909 0.28906 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.31401 moveto 0.00909 0.31401 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.33895 moveto 0.00909 0.33895 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.36389 moveto 0.00909 0.36389 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.41377 moveto 0.00909 0.41377 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.43871 moveto 0.00909 0.43871 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.46365 moveto 0.00909 0.46365 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.48859 moveto 0.00909 0.48859 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.53847 moveto 0.00909 0.53847 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.56341 moveto 0.00909 0.56341 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.58835 moveto 0.00909 0.58835 lineto stroke grestore gsave 0.001 setlinewidth 0.00534 0.6133 moveto 0.00909 0.6133 lineto stroke grestore gsave 0.002 setlinewidth 0.00534 0 moveto 0.00534 0.61803 lineto stroke grestore grestore gsave gsave gsave 0.008 setlinewidth 0.02645 0.60332 Mdot 0.02645 0.26412 Mdot 0.02645 0.46365 Mdot 0.02645 0.20427 Mdot 0.02645 0.33396 Mdot 0.02645 0.32398 Mdot 0.02645 0.45367 Mdot 0.02645 0.17434 Mdot 0.02645 0.01472 Mdot 0.2375 0.35059 Mdot 0.2375 0.34061 Mdot 0.2375 0.39382 Mdot 0.2375 0.43705 Mdot 0.2375 0.15438 Mdot 0.2375 0.2874 Mdot 0.2375 0.24417 Mdot 0.2375 0.32066 Mdot 0.2375 0.33396 Mdot 0.44856 0.43572 Mdot 0.44856 0.45367 Mdot 0.44856 0.42175 Mdot 0.44856 0.53748 Mdot 0.44856 0.32997 Mdot 0.44856 0.17434 Mdot 0.44856 0.36788 Mdot 0.44856 0.4018 Mdot 0.44856 0.32797 Mdot 0.65961 0.35676 Mdot 0.65961 0.37956 Mdot 0.65961 0.29548 Mdot 0.65961 0.34108 Mdot 0.65961 0.40522 Mdot 0.65961 0.32683 Mdot 0.65961 0.28408 Mdot 0.65961 0.35819 Mdot 0.65961 0.32826 Mdot 0.87066 0.39382 Mdot 0.87066 0.33839 Mdot 0.87066 0.35613 Mdot 0.87066 0.38384 Mdot 0.87066 0.37275 Mdot 0.87066 0.38716 Mdot 0.87066 0.30292 Mdot 0.87066 0.32398 Mdot 0.87066 0.33728 Mdot grestore grestore gsave gsave gsave 0.004 setlinewidth 0.02381 0.34726 moveto 0.06349 0.34726 lineto 0.10317 0.34726 lineto 0.14286 0.34726 lineto 0.18254 0.34726 lineto 0.22222 0.34726 lineto 0.2619 0.34726 lineto 0.30159 0.34726 lineto 0.34127 0.34726 lineto 0.38095 0.34726 lineto 0.42063 0.34726 lineto 0.46032 0.34726 lineto 0.5 0.34726 lineto 0.53968 0.34726 lineto 0.57937 0.34726 lineto 0.61905 0.34726 lineto 0.65873 0.34726 lineto 0.69841 0.34726 lineto 0.7381 0.34726 lineto 0.77778 0.34726 lineto 0.81746 0.34726 lineto 0.85714 0.34726 lineto 0.89683 0.34726 lineto 0.93651 0.34726 lineto 0.97619 0.34726 lineto stroke grestore grestore grestore grestore 0 0 moveto 1 0 lineto 1 0.61803 lineto 0 0.61803 lineto closepath clip newpath % End of Graphics MathPictureEnd\ \>"], "Graphics", Evaluatable->False, AspectRatioFixed->True, ImageSize->{282, 174}, ImageMargins->{{34, Inherited}, {Inherited, Inherited}}, ImageCache->GraphicsData["Bitmap", "\<\ CF5dJ6E]HGAYHf4PAg9QL6QYHg?l00``0bOl001?o00?l00``0bOl001?o00?l00``0JOl0 0``0?l00``0bOl0 01?o00S o`03301Mo`0000@l00Wo00"], ImageRangeCache->{{{0, 281}, {173, 0}} -> {92.992302, 0.358344, 36.965218, 0.003128}}], Cell[TextData[{ "Graph 1. Monte Carlo Integration of x", StyleBox["2", FontVariations->{"CompatibilityType"->"Superscript"}], " - 1\n" }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[{ "The graph demonstrates that the accuracy and precision of the results \ change as the number of points used in each calculation increases. \ Generally, the more points that are used, the more accurate and precise the \ output will be.\n One of the most useful applications of the program is \ the evaluation of definite integrals that would otherwise be very difficult \ to calculate. Graph 2 is a plot of the function Sin[1/x] on the interval -1 \ \[LessEqual] x \[LessEqual] 3. Although ", StyleBox["Mathematica", FontSlant->"Italic"], " cannot integrate the function on this interval, results may be obtained \ using the Monte Carlo method. Because the program uses the ", StyleBox["Min", FontWeight->"Bold"], " and ", StyleBox["Max", FontWeight->"Bold"], " commands, however, it does not work well for intervals having an \ endpoint that is undefined. When this problem occurs, we recommend choosing \ an endpoint that is slightly larger or smaller than the original value (for \ example, select 0.001 instead of 0 for the function Sin[1/x] ). Graph 3 is a \ plot of the results obtained for the definite integral of Sin[1/x] with -1 \ \[LessEqual] x \[LessEqual] 3.\n " }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[CellGroupData[{ Cell[TextData["Plot[Sin[1/x],{x,-1,3}]"], "Input", AspectRatioFixed->True], Cell[GraphicsData["PostScript", "\<\ %! %%Creator: Mathematica %%AspectRatio: 0.61803 MathPictureStart /Courier findfont 10 scalefont setfont % Scaling calculations 0.261905 0.238095 0.309017 0.294303 [ [(-1)] 0.02381 0.30902 0 2 Msboxa [(1)] 0.5 0.30902 0 2 Msboxa [(2)] 0.7381 0.30902 0 2 Msboxa [(3)] 0.97619 0.30902 0 2 Msboxa [(-1)] 0.2494 0.01471 1 0 Msboxa [(-0.5)] 0.2494 0.16187 1 0 Msboxa [(0.5)] 0.2494 0.45617 1 0 Msboxa [(1)] 0.2494 0.60332 1 0 Msboxa [ -0.001 -0.001 0 0 ] [ 1.001 0.61903 0 0 ] ] MathScale % Start of Graphics 1 setlinecap 1 setlinejoin newpath %%Object: Graphics [ ] 0 setdash 0 setgray gsave gsave 0.002 setlinewidth 0.02381 0.30902 moveto 0.02381 0.31527 lineto stroke grestore [(-1)] 0.02381 0.30902 0 2 Mshowa gsave 0.002 setlinewidth 0.5 0.30902 moveto 0.5 0.31527 lineto stroke grestore [(1)] 0.5 0.30902 0 2 Mshowa gsave 0.002 setlinewidth 0.7381 0.30902 moveto 0.7381 0.31527 lineto stroke grestore [(2)] 0.7381 0.30902 0 2 Mshowa gsave 0.002 setlinewidth 0.97619 0.30902 moveto 0.97619 0.31527 lineto stroke grestore [(3)] 0.97619 0.30902 0 2 Mshowa gsave 0.001 setlinewidth 0.07143 0.30902 moveto 0.07143 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.11905 0.30902 moveto 0.11905 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.16667 0.30902 moveto 0.16667 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.21429 0.30902 moveto 0.21429 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.30952 0.30902 moveto 0.30952 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.35714 0.30902 moveto 0.35714 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.40476 0.30902 moveto 0.40476 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.45238 0.30902 moveto 0.45238 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.54762 0.30902 moveto 0.54762 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.59524 0.30902 moveto 0.59524 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.64286 0.30902 moveto 0.64286 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.69048 0.30902 moveto 0.69048 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.78571 0.30902 moveto 0.78571 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.83333 0.30902 moveto 0.83333 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.88095 0.30902 moveto 0.88095 0.31277 lineto stroke grestore gsave 0.001 setlinewidth 0.92857 0.30902 moveto 0.92857 0.31277 lineto stroke grestore gsave 0.002 setlinewidth 0 0.30902 moveto 1 0.30902 lineto stroke grestore gsave 0.002 setlinewidth 0.2619 0.01471 moveto 0.26815 0.01471 lineto stroke grestore [(-1)] 0.2494 0.01471 1 0 Mshowa gsave 0.002 setlinewidth 0.2619 0.16187 moveto 0.26815 0.16187 lineto stroke grestore [(-0.5)] 0.2494 0.16187 1 0 Mshowa gsave 0.002 setlinewidth 0.2619 0.45617 moveto 0.26815 0.45617 lineto stroke grestore [(0.5)] 0.2494 0.45617 1 0 Mshowa gsave 0.002 setlinewidth 0.2619 0.60332 moveto 0.26815 0.60332 lineto stroke grestore [(1)] 0.2494 0.60332 1 0 Mshowa gsave 0.001 setlinewidth 0.2619 0.04414 moveto 0.26565 0.04414 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.07357 moveto 0.26565 0.07357 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.103 moveto 0.26565 0.103 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.13244 moveto 0.26565 0.13244 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.1913 moveto 0.26565 0.1913 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.22073 moveto 0.26565 0.22073 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.25016 moveto 0.26565 0.25016 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.27959 moveto 0.26565 0.27959 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.33845 moveto 0.26565 0.33845 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.36788 moveto 0.26565 0.36788 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.39731 moveto 0.26565 0.39731 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.42674 moveto 0.26565 0.42674 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.4856 moveto 0.26565 0.4856 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.51503 moveto 0.26565 0.51503 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.54446 moveto 0.26565 0.54446 lineto stroke grestore gsave 0.001 setlinewidth 0.2619 0.57389 moveto 0.26565 0.57389 lineto stroke grestore gsave 0.002 setlinewidth 0.2619 0 moveto 0.2619 0.61803 lineto stroke grestore grestore 0 0 moveto 1 0 lineto 1 0.61803 lineto 0 0.61803 lineto closepath clip newpath gsave gsave 0.004 setlinewidth 0.02381 0.06137 moveto 0.06349 0.03471 lineto 0.08333 0.02297 lineto 0.08829 0.02054 lineto 0.09325 0.01843 lineto 0.09821 0.0167 lineto 0.10069 0.01601 lineto 0.10317 0.01545 lineto 0.10441 0.01523 lineto 0.10565 0.01504 lineto 0.10689 0.01489 lineto 0.10813 0.01479 lineto 0.10938 0.01473 lineto 0.11062 0.01472 lineto 0.11186 0.01475 lineto 0.1131 0.01484 lineto 0.11434 0.01498 lineto 0.11558 0.01518 lineto 0.11806 0.01576 lineto 0.1193 0.01615 lineto 0.12054 0.0166 lineto 0.12302 0.01774 lineto 0.1255 0.01919 lineto 0.12798 0.021 lineto 0.13294 0.0258 lineto 0.1379 0.03248 lineto 0.14286 0.04141 lineto 0.14782 0.05306 lineto 0.15278 0.06796 lineto 0.15774 0.08677 lineto 0.1627 0.11023 lineto 0.17262 0.17444 lineto 0.17758 0.21698 lineto 0.18254 0.26748 lineto 0.19246 0.39232 lineto 0.19742 0.46302 lineto 0.20238 0.53175 lineto 0.20486 0.56167 lineto 0.2061 0.57457 lineto 0.20734 0.5856 lineto 0.20858 0.59437 lineto 0.20982 0.6004 lineto 0.21106 0.60319 lineto 0.2123 0.60219 lineto 0.21354 0.59681 lineto 0.21478 0.58645 lineto 0.21602 0.5705 lineto 0.21726 0.54838 lineto 0.21974 0.48386 lineto 0.22098 0.44099 lineto Mistroke 0.22222 0.39125 lineto 0.22718 0.14922 lineto 0.22842 0.09225 lineto 0.22966 0.04654 lineto 0.2309 0.01916 lineto 0.23214 0.01785 lineto 0.23338 0.04988 lineto 0.23462 0.11998 lineto 0.2371 0.36032 lineto 0.23834 0.49418 lineto 0.23958 0.58754 lineto 0.24082 0.5903 lineto 0.24206 0.46693 lineto 0.2433 0.24088 lineto 0.24454 0.04064 lineto 0.24578 0.07157 lineto 0.24702 0.39375 lineto 0.2495 0.20798 lineto 0.25074 0.12908 lineto 0.25198 0.57553 lineto 0.25322 0.08874 lineto 0.25446 0.14673 lineto 0.2557 0.11922 lineto 0.25694 0.53512 lineto 0.25818 0.03825 lineto 0.25942 0.01954 lineto 0.26066 0.41348 lineto 0.2619 0.40534 lineto 0.26314 0.20456 lineto 0.26438 0.59849 lineto 0.26563 0.57978 lineto 0.26687 0.08292 lineto 0.26811 0.49881 lineto 0.26935 0.4713 lineto 0.27059 0.5293 lineto 0.27183 0.0425 lineto 0.27307 0.48895 lineto 0.27431 0.41006 lineto 0.27555 0.01925 lineto 0.27679 0.22429 lineto 0.27803 0.54646 lineto 0.27927 0.5774 lineto 0.28051 0.37715 lineto 0.28175 0.1511 lineto 0.28299 0.02773 lineto 0.28423 0.03049 lineto 0.28547 0.12385 lineto 0.28671 0.25771 lineto 0.28795 0.39089 lineto 0.28919 0.49805 lineto Mistroke 0.29043 0.56816 lineto 0.29167 0.60019 lineto 0.29291 0.59888 lineto 0.29415 0.57149 lineto 0.29663 0.46881 lineto 0.29911 0.34332 lineto 0.30159 0.22678 lineto 0.30283 0.17704 lineto 0.30407 0.13418 lineto 0.30531 0.09842 lineto 0.30655 0.06965 lineto 0.30779 0.04754 lineto 0.30903 0.03159 lineto 0.31027 0.02122 lineto 0.31151 0.01584 lineto 0.31275 0.01484 lineto 0.31399 0.01763 lineto 0.31523 0.02367 lineto 0.31647 0.03243 lineto 0.32143 0.08629 lineto 0.33135 0.22571 lineto 0.34127 0.35055 lineto 0.34623 0.40105 lineto 0.35119 0.44359 lineto 0.35615 0.47888 lineto 0.36111 0.50781 lineto 0.37103 0.55007 lineto 0.37599 0.56498 lineto 0.38095 0.57663 lineto 0.38591 0.58556 lineto 0.39087 0.59223 lineto 0.39583 0.59704 lineto 0.39831 0.59884 lineto 0.40079 0.6003 lineto 0.40327 0.60143 lineto 0.40451 0.60189 lineto 0.40575 0.60227 lineto 0.40699 0.60259 lineto 0.40823 0.60285 lineto 0.40947 0.60305 lineto 0.41071 0.60319 lineto 0.41195 0.60328 lineto 0.41319 0.60332 lineto 0.41443 0.60331 lineto 0.41567 0.60325 lineto 0.41691 0.60314 lineto 0.41815 0.603 lineto 0.41939 0.60281 lineto 0.42063 0.60258 lineto 0.46032 0.58332 lineto Mistroke 0.5 0.55666 lineto 0.53968 0.5315 lineto 0.57937 0.50963 lineto 0.61905 0.49101 lineto 0.65873 0.47519 lineto 0.69841 0.4617 lineto 0.7381 0.45011 lineto 0.77778 0.44008 lineto 0.81746 0.43132 lineto 0.85714 0.42362 lineto 0.89683 0.41681 lineto 0.93651 0.41075 lineto 0.97619 0.40531 lineto Mfstroke grestore grestore % End of Graphics MathPictureEnd\ \>"], "Graphics", Evaluatable->False, AspectRatioFixed->True, ImageSize->{282, 174}, ImageMargins->{{34, Inherited}, {Inherited, Inherited}}, ImageCache->GraphicsData["Bitmap", "\<\ CF5dJ6E]HGAYHf4PAg9QL6QYHgko`00;Ol00c`04?l013<01/`700Go00k o`00;_l00c`03ol013<01/`700Go00ko`00;_l00c`03ol01C?01C0700Go00o`05ko`00;ol00c`03_l0 1C?01C0700Go00o`05ko`00;ol00c`03_l01C?01C070003o005c`Kc^ol002oo00Ol8?`W`1P<5c1;o00l1?o00_l013`01Ol53`k`5?l00c`07?l00``0S_l003[o00@l00Go1@l>l1Co00_l013`01Ol53`K`00?<00G35Ol0 0c`05ol00c`0T_l003[o00@l00Go00D?`0K`00?<00G35Ol00c`05Ol00``0U?l003[o00@l00Go00D? `0K`00?l00G35_l00c`04_l00``0U_l003[o00<`00Ko00D?`0K`00?l00G35_l00c`04Ol00``0Uol0 03[o00<`00Ko00D?`0K`00?l00G35ol00c`03_l00``0VOl003_o00<<00Go00<000Po00?l00G?6?l0 0c`02ol00``0Vol003_o00<<00Oo00"], ImageRangeCache->{{{0, 281}, {173, 0}} -> {-1.110242, -1.041286, 0.014966, 0.012108}}] }, Open ]], Cell[TextData[ "Graph 2. Sin[1/x] for -1 \[LessEqual] x \[LessEqual] 3\n"], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[GraphicsData["PICT", "\<\ \>"], "Graphics", Evaluatable->False, AspectRatioFixed->True, ImageSize->{282, 174}, ImageMargins->{{0, Inherited}, {Inherited, Inherited}}], Cell[TextData[ "Graph 3. Monte Carlo Integration of Sin[1/x] With -1 \[LessEqual] x \ \[LessEqual] 3\n"], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"] }, Closed]], Cell[CellGroupData[{ Cell[TextData["The Program"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "The following is a listing of the entire program. It may be useful to \ insert "], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData["Print[N[(Counter/k)*((endint-begint)*(maxy-miny))]]"], "Input", AspectRatioFixed->True], Cell[TextData[{ "inside the second ", StyleBox["Do", FontWeight->"Bold"], " loop so that ", StyleBox["Mathematica", FontSlant->"Italic"], " displays the numerical result for each iteration as it is computed." }], "Text", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Palatino"], Cell[TextData[ "\nf[x_]= ; (*function = ??*) \nbegint = ; (*begin interval*)\nendint = \ ; (*end interval*)\nminit = ; (*smallest # iterations*)\nmaxit = ; \ (*largest # iterations*)\nstepsize = ; (*step size*)\ntrials = ; \ (*repeats for same # iterations*)\nz = {}; (*empty list*)\nv = {}; (*empty \ list*)\n\nminy = Min[Table[N[f[x]],{x,begint,endint,0.01}]];\nmaxy = \ Max[Table[N[f[x]],{x,begint,endint,0.01}]];\n\nDo[Do[Counter = 0;\nDo[r = \ Random[Real, {miny,maxy}]; \ns = Random[Real,{begint,endint}];\nIf[r <= f[s] \ && r >= 0, Counter=Counter+1, Counter=Counter];\nIf[r >= f[s] && r < 0, \ Counter=Counter-1, Counter=Counter],{i,1,k}];\n\n\ AppendTo[v,N[(Counter/k)*((endint-begint)*(maxy-miny))]];\n\ AppendTo[z,k],{j,1,trials}];\n,{k,minit,maxit,stepsize}];\n\n\ data=Transpose[{z,v}];\nListPlot[data,PlotRange->All];\n"], "Input", AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell[TextData["The Authors"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Steven Keltner\nRt 3 Box 515\nWillard, MO 65781\n(417) 742-2311\n\nScott \ Sloan\nRt 2 Box 146\nPlattsburg, MO 64477\n(816) 539-2007"], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Open ]] }, FrontEndVersion->"NeXT 3.0", ScreenRectangle->{{0, 1053}, {0, 832}}, WindowToolbars->{}, CellGrouping->Automatic, WindowSize->{520, 600}, WindowMargins->{{Automatic, 68}, {Automatic, 71}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, 128}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, CharacterEncoding->"NeXTAutomaticEncoding" ] (*********************************************************************** 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[1731, 51, 116, 2, 174, "Title"], Cell[1850, 55, 178, 5, 57, "Subtitle"], Cell[2031, 62, 167, 4, 94, "Subsubtitle"], Cell[CellGroupData[{ Cell[2223, 70, 115, 3, 51, "Section"], Cell[2341, 75, 950, 14, 174, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[3328, 94, 156, 4, 31, "Section"], Cell[3487, 100, 1479, 21, 270, "Text"], Cell[4969, 123, 150, 3, 108, "Input"], Cell[5122, 128, 1400, 36, 190, "Text"], Cell[6525, 166, 158, 3, 36, "Input"], Cell[6686, 171, 425, 12, 62, "Text"], Cell[7114, 185, 288, 5, 108, "Input"], Cell[7405, 192, 569, 20, 62, "Text"], Cell[7977, 214, 172, 3, 48, "Input"], Cell[8152, 219, 157, 4, 30, "Text"], Cell[8312, 225, 110, 2, 48, "Input"], Cell[8425, 229, 377, 7, 62, "Text"], Cell[8805, 238, 329, 6, 108, "Input"], Cell[9137, 246, 283, 6, 142, "Text"], Cell[9423, 254, 11575, 487, 182, 7033, 426, "GraphicsData", "PostScript", "Graphics"], Cell[21001, 743, 233, 8, 54, "Text"], Cell[21237, 753, 1317, 26, 222, "Text"], Cell[CellGroupData[{ Cell[22579, 783, 76, 1, 24, "Input"], Cell[22658, 786, 15706, 564, 182, 8422, 469, "GraphicsData", "PostScript", "Graphics"] }, Open ]], Cell[38379, 1353, 161, 4, 46, "Text"], Cell[38543, 1359, 179, 5, 182, 48, 1, "GraphicsData", "PICT", "Graphics"], Cell[38725, 1366, 189, 5, 46, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[38951, 1376, 88, 2, 32, "Section"], Cell[39042, 1380, 181, 5, 30, "Text"], Cell[39226, 1387, 104, 1, 24, "Input"], Cell[39333, 1390, 312, 11, 46, "Text"], Cell[39648, 1403, 886, 13, 360, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[40571, 1421, 88, 2, 32, "Section"], Cell[40662, 1425, 209, 4, 158, "Text"] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)