Monte Carlo Method for Definite Integration

Similar documents
B. Examples Set up the integral(s) needed to find the area of the region bounded by

MATH 104 Sample problems for first exam - Fall MATH 104 First Midterm Exam - Fall (d) 256 3

VARIANCE REDUCTION TECHNIQUES IN MONTE CARLO SIMULATIONS K. Ming Leung

Math 1206 Calculus Sec. 5.6: Substitution and Area Between Curves (Part 2) Overview of Area Between Two Curves

Lecture 5. If, as shown in figure, we form a right triangle With P1 and P2 as vertices, then length of the horizontal

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

Newton s Method. Example : Find the root of f (x) =

Basic Exercises about Mathematica

Integration. Volume Estimation

Monte Carlo Integration

AP Calculus AB Unit 2 Assessment

HSC Mathematics - Extension 1. Workshop E2

Representations of Curves and Surfaces, and of their Tangent Lines, and Tangent Planes in R 2 and R 3 Robert L.Foote, Fall 2007

NUMERICAL INTEGRATION AND FUNCTION FUNCTIONS

The base of a solid is the region in the first quadrant bounded above by the line y = 2, below by

AP * Calculus Review. Area and Volume

Monte Carlo Simula/on and Copula Func/on. by Gerardo Ferrara

Graphs of Exponential

Factoring. Factor: Change an addition expression into a multiplication expression.

B.Stat / B.Math. Entrance Examination 2017

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Vertical and Horizontal Translations

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

Solved Examples. Parabola with vertex as origin and symmetrical about x-axis. We will find the area above the x-axis and double the area.

ISyE 6416: Computational Statistics Spring Lecture 13: Monte Carlo Methods

14.5 Directional Derivatives and the Gradient Vector

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

MAT Business Calculus - Quick Notes

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

MAT 110 WORKSHOP. Updated Fall 2018

Algebra. Mathematica QuickStart for Calculus 101C. Solving Equations. Factoring. Exact Solutions to single equation:

EE 301 Lab 1 Introduction to MATLAB

Evolutionary Algorithms. Workgroup 1

18.02 Final Exam. y = 0

Applications of Integration. Copyright Cengage Learning. All rights reserved.

Math 265 Exam 3 Solutions

4.7 Approximate Integration

Find the specific function values. Complete parts (a) through (d) below. f (x,y,z) = x y y 2 + z = (Simplify your answer.) ID: 14.1.

Math 226A Homework 4 Due Monday, December 11th

Albertson AP Calculus AB AP CALCULUS AB SUMMER PACKET DUE DATE: The beginning of class on the last class day of the first week of school.

10.4 Linear interpolation method Newton s method

Computational modeling

Double integrals over a General (Bounded) Region

Volumes of Solids of Revolution Lecture #6 a

Quickstart: Mathematica for Calculus I (Version 9.0) C. G. Melles Mathematics Department United States Naval Academy September 2, 2013

Chapter 1. Fundamentals of Higher Order Programming

Downloaded from

Functions. Copyright Cengage Learning. All rights reserved.

8 Piecewise Polynomial Interpolation

Math 209 (Fall 2007) Calculus III. Solution #5. 1. Find the minimum and maximum values of the following functions f under the given constraints:

Calculus I Review Handout 1.3 Introduction to Calculus - Limits. by Kevin M. Chevalier

Contents. MATH 32B-2 (18W) (L) G. Liu / (TA) A. Zhou Calculus of Several Variables. 1 Homework 1 - Solutions 3. 2 Homework 2 - Solutions 13

A. Incorrect! This would be the negative of the range. B. Correct! The range is the maximum data value minus the minimum data value.

Problem #3 Daily Lessons and Assessments for AP* Calculus AB, A Complete Course Page Mark Sparks 2012

1. Practice the use of the C ++ repetition constructs of for, while, and do-while. 2. Use computer-generated random numbers.

Scientific Computing with MATLAB

What is log a a equal to?

Chapter 1. Introduction

Math 250A (Fall 2009) - Lab I: Estimate Integrals Numerically with Matlab. Due Date: Monday, September 21, INSTRUCTIONS

What Secret the Bisection Method Hides? by Namir Clement Shammas

Jim Lambers MAT 169 Fall Semester Lecture 33 Notes

Homework Set #2-3, Math 475B

If statements and For loops

Homework: Study 6.1 # 1, 5, 7, 13, 25, 19; 3, 17, 27, 53

Functions and Graphs. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Convexization in Markov Chain Monte Carlo

LAB 1 General MATLAB Information 1

Section 4.3. Graphing Exponential Functions

WHOLE NUMBER AND DECIMAL OPERATIONS

Sharp EL-9900 Graphing Calculator

1. Show that the rectangle of maximum area that has a given perimeter p is a square.

Computational modeling

Halftoning and quasi-monte Carlo

Computational Methods for Finding Probabilities of Intervals

Machine Learning for Signal Processing Lecture 4: Optimization

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

A Framework for Achieving the Essential Academic Learning. Requirements in Mathematics Grades 8-10 Glossary

Using Arithmetic of Real Numbers to Explore Limits and Continuity

Introduction to MATLAB

Constructive floorplanning with a yield objective

NUMERICAL INTEGRATION

Lecture 17 Appendix B (analytic functions and contour integrals)

Thursday 14 June 2012 Morning

APPM/MATH Problem Set 4 Solutions

Functions of Two variables.

and F is an antiderivative of f

Mathematica for Dirac delta functions and Green functions

The Maximum Area of a Cyclic (n+2)-gon Theorem

ESTIMATING AND CALCULATING AREAS OF REGIONS BETWEEN THE X-AXIS AND THE GRAPH OF A CONTINUOUS FUNCTION v.07

Math 213 Calculus III Practice Exam 2 Solutions Fall 2002

Chapter 8: Applications of Definite Integrals

Making Holes and Windows in Surfaces

Chapter 7. Exercise 7A. dy dx = 30x(x2 3) 2 = 15(2x(x 2 3) 2 ) ( (x 2 3) 3 ) y = 15

AMTH142 Lecture 10. Scilab Graphs Floating Point Arithmetic

Exponential and Logarithmic Functions. College Algebra

Math F302: Octave Miscellany September 28, e 1 x3 dx. Here s how to find a numerical approximation with Octave

Math 7 Glossary Terms

CAS Exercise Examples for Chapter 15: Multiple Integrals

PART 1 PROGRAMMING WITH MATHLAB

Transformations Review

Transcription:

Monte Carlo Method for Definite Integration http://www.mathcs.emory.edu/ccs/ccs215/monte/node13.htm Numerical integration techniques, such as the Trapezoidal rule and Simpson's rule, are commonly utilized for the purpose of approximating the value of a definite integral. However, these methods of approximation will guarantee a particular rate of convergence only when the integrand has continuous derivatives to a certain order. Before it can be applied, a numerical integration technique also requires a certain amount of knowledge about the function, such as the location of its domain, and where any discontinuities may exist. If a function fails to satisfy the requirements associated with a given numerical integration technique, or if it behaves in such a manner that one cannot beforehand discern a sufficient amount of information about the function in order to circumvent any problems that may arise with such an approach, then we can often apply a Monte Carlo method to obtain an approximation of the integral. Clear@"Global` "D; ClearAll@x, yd t1 = Array@x, 810<D; lims = Table@8i, 0, 1<, 8i, t1<d; Knowing that the (##) represents the sequence of arguments supplied to a pure function and (## n) represents the sequence of arguments supplied to a pure function, starting with the n th argument (f[x, ##, y, ##] & [a, b, c, d]-> f[x, a, b, c, d, y, a, b, c, d], or f[##2] &[a, b, c, d] -> f[b, c, d] )

2 Monte_Carlo_Int[1].nb NIntegrateB Exp@ t1.t1d,, Method "AdaptiveMonteCarlo"F & @@ t1.t1 lims 0.0347335 The number of samples used to evaluate Ÿ 0 1 Ÿ0 1 1 x+y y x for different relative tolerances: samplecount@pg_d := Module@8k = 0<, NIntegrate@1 ê Sqrt@x + yd, 8x, 0, 1<, 8y, 0, 1<, PrecisionGoal pg, EvaluationMonitor k++d; k D; The number of samples needed typically increases exponentially with the PrecisionGoal: Table@sampleCount@pgD, 8pg, 2, 12<D 8119, 289, 459, 901, 2125, 5287, 12 716, 32 436, 82 348, 201 518, 440 963<

Monte_Carlo_Int[1].nb 3 ListLogPlot@%, Joined TrueD 10 5 10 4 1000 2 4 6 8 10 It can be time-consuming to compute functions symbolically: f@x_d := Nest@Sin@ +Sin@2 DD &, x, 20D NIntegrate@f@xD, 8x, 0, 1<D êê Timing 81.109, 0.947747< Restricting the function definition avoids symbolic evaluation: g@x_?numericqd := Nest@Sin@ +Sin@2 DD &, x, 20D

4 Monte_Carlo_Int[1].nb NIntegrate@g@xD, 8x, 0, 1<D êê Timing 80., 0.947747< points = ReapANIntegrateABooleAHx1L 2 + Hx2 1L 2 < 1E + BooleAHx1L 2 + Hx3 1L 2 < 1E, 8x1, 0, 1<, 8x2, 0, 2<, 8x3, 0, 2<, Method 8"GlobalAdaptive", Method 8"TrapezoidalRule", "Points" 3<, "SingularityHandler" None<, PrecisionGoal 4, EvaluationMonitor Sow@8x1, x2, x3<dee@@2, 1DD;

Monte_Carlo_Int[1].nb 5 Graphics3D@Point@pointsDD There are two methods of Monte Carlo integration that we shall be discussing: the hit or miss method and the sample mean method. Let y = f(x) be a function that is bounded and non-negative on the interval [a,b]. Then there must be some real number c, c > 0, such

6 Monte_Carlo_Int[1].nb that f(x) c 0 for all x in [a,b]. Now, the definite integral : Ÿ b a f HxL x represents the area of the region beneath the graph of y = f(x) and above the x-axis on [a,b]. Let us denote this region as R. Then this region R is contained entirely within the rectangle bounded by the lines x = a, x = b, y = 0, and y = c, and which has an area of c(b - a). Let A be the area of region R--the value of this definite integral. Then the fraction of the rectangle that the region R represents is given by A/c(b - a). Suppose that we randomly select a point (x1, y1) from within this rectangle (including its boundary). Now, to randomly select (x1,y1) from within the rectangle implies that we randomly select x1 from the interval [a,b] and y1 from the interval [0,c]. The probability that this point will lie within region R will then be p = A/c(b-a). This means that the point (x1,y1) has probability p that it will satisfy the relation y1 f(x1). We shall consider is the approximation of the area of the region between the x - axis and the graph of the curve y = 1/x on the interval [1, 2]. This implies that we are finding an approximation to Ÿ 2 1 1 ê x x=ln(2) On the interval [1,2], the curve y = 1/x satisfies the bounds 0 1/x 1=>the region is contained within the rectangle bounded by the lines x = 1, x = 2, y = 0, and y = 1, having an area of 1 square unit. The ratio ln(2)/1=ln(2) is then approximated by randomly choosing points (x,y) such that 1 x 2 and 0 y 1and then by finding the ratio of the number that satisfy y(x) 1/x to the total.

Monte_Carlo_Int[1].nb 7 p1@x_d := 1 ê x; nmbr := 1 Do@event = 0; Do@u = Random@D; v = Random@D; x = 1 + u; y = v; If@y p1@xd, event = event + 1D, 8i, 1, nmbr<d; Print@"nr.= ", nmbr, " average = ", event 1. ê nmbrd; nmbr = 2 nmbr, 8j, 1, 22<D nr.= 1 average = 1. nr.= 2 average = 1. nr.= 4 average = 0.25 nr.= 8 average = 0.625 nr.= 16 average = 0.6875 nr.= 32 average = 0.53125 nr.= 64 average = 0.5625 nr.= 128 average = 0.671875 nr.= 256 average = 0.695313 nr.= 512 average = 0.660156 nr.= 1024 average = 0.716797 nr.= 2048 average = 0.687012 nr.= 4096 average = 0.708496 nr.= 8192 average = 0.694336 nr.= 16 384 average = 0.68811 nr.= 32 768 average = 0.695709 nr.= 65 536 average = 0.690002 nr.= 131 072 average = 0.694077 nr.= 262 144 average = 0.694744 nr.= 524 288 average = 0.692966 nr.= 1 048 576 average = 0.692958 nr.= 2 097 152 average = 0.692826

8 Monte_Carlo_Int[1].nb NIntegrate@1 ê x, 8x, 1, 2<D 0.693147 Let y = f(x) be a function that is bounded on the interval [a,b]. Then the mean or average value of f(x) on [a,b] is given by et y = f(x) be a function that is bounded on the interval [a,b]. Then the mean or average value of f(x) on [a,b] is given by fmed= 1 b-a Ÿ b a f HxL dx Now suppose that we randomly select n values,x1,x2,...xn, from the interval [a,b]. Then we would expect to be able to approximate the average value of f(x) on [a,b] by averaging the values of f(x) at the xi: fmed º 1 n n i=1 f HxiL Thus we see that Ÿ a b f HxL dx º b-a n p i=1 f HxiL This then yields a method of approximating the definite integral of f(x) on [a,b], known as the sample mean method of Monte Carlo integration. Let us once again consider how to approximate the area of the region above the x-axis and beneath the graph of the function y = f(x), where

Monte_Carlo_Int[1].nb 9 f(x)=sin(50x)cos(120x)+1 on the interval [0,p]. In this case we shall utilize the sample mean method of Monte Carlo integration to find the value of the definite integral Ÿ 0 p @SinH50 xl CosH120 xl + 1D x We incorporate the sample mean method of Monte Carlo integration to obtain a sequence of approximations of the average value of this function on [0,p] by means of the Mathematica program p2@x_d := IntegerPart@Sin@50 xd Cos@120 xd + 1D a = 0.0; b = Pi; nmbr := 1 Do@smm = 0.0; Do@x = a + Random@D Hb al; y = p2@xd; smm = smm + y, 8i, 1, nmbr<d; Print@"nr. = ", nmbr, " average = ", smm ê nmbrd; nmbr = 2 nmbr, 8j, 1, 22<D nr. = 1 average = 1. nr. = 2 average = 0.5 nr. = 4 average = 0.5 nr. = 8 average = 0.5 nr. = 16 average = 0.4375 nr. = 32 average = 0.4375 nr. = 64 average = 0.453125 nr. = 128 average = 0.46875 nr. = 256 average = 0.53125 nr. = 512 average = 0.488281 nr. = 1024 average = 0.518555 nr. = 2048 average = 0.50293

10 Monte_Carlo_Int[1].nb nr. = 4096 average = 0.494873 nr. = 8192 average = 0.497803 nr. = 16 384 average = 0.500183 nr. = 32 768 average = 0.501221 nr. = 65 536 average = 0.5009 nr. = 131 072 average = 0.499077 nr. = 262 144 average = 0.49894 nr. = 524 288 average = 0.501053 nr. = 1 048 576 average = 0.499733 nr. = 2 097 152 average = 0.499512 From this data it appears that the average is approximately 0.500, which yields a value of 3.142*0.500=1.571 for the area of the region

Monte_Carlo_Int[1].nb 11 NIntegrate@Sin@50 xd Cos@120 xd + 1, 8x, 0,π<D 3.14159 Monte Carlo Method for Definite Integration Steven Keltner and Scott Sloan University of Missouri-Rolla 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. 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. The first part of the program defines the parameters :

12 Monte_Carlo_Int[1].nb h@x_d = Exp@xD ^2 x + 1; H you can use any function =?? L x0 = 2; H begining of the interval L xm = 2; H ending of the interval L stepsize = 2000 ; H step size L it0 = 1000 ; H smallest iterations L itm = 2000 ; H largest iterations L trials = 100 ; H repeats for same iterations L l1 = 8<; H empty list L l2 = 8< ; H empty list L The second step is to 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." y0 = Min@Table@N@h@xDD, 8x, x0, xm, 0.01<DD; ym = Max@Table@N@h@xDD, 8x, x0, xm, 0.01<DD; The third step of the program generates random coordinates and determines how each point should be counted. If the random y value r is less than or equal to the function evaluated at the random x value s, it is counted. Do@Do@Counter = 0; Do@r = Random@Real, 8y0, ym<d; s = Random@Real, 8x0, xm<d; If@r <= h@sd && r >= 0, Counter = Counter + 1, Counter = CounterD; If@r >= h@sd && r < 0, Counter = Counter 1, Counter = CounterD, 8i, 1, k<d; AppendTo@l2, N@HCounter ê kl HHxm x0l Hym y0lldd; AppendTo@l1, kd, 8j, 1, trials<d;, 8k, it0, itm, stepsize<d; In the forth step after transposing the data, the information is plotted:

Monte_Carlo_Int[1].nb 13 data = Transpose@8l1, l2<d; ListPlot@data, PlotRange > AllD 1.0 0.5 500 1000 1500 2000 0.5 1.0