Numerical Methods & Scientific Computing: lecture notes
Stochastic simulation
Statistical errors
Week 4: aim to cover
Monte Carlo integration, floating point numbers, roundo↵ error (Lecture 7)
Confidence intervals, MC integration, roundo↵ error (Lab 4) Error propagation (Lecture 8)
Numerical Methods & Scientific Computing: lecture notes
Stochastic simulation
Statistical errors
Monte Carlo integration
It is frequently necessary to compute definite integrals. The functions being integrated are often quite complicated and it may not be possible to find an indefinite integral in closed form. Since what is wanted is a numerical result, computers are used to find numerical approximations to the definite integral. In the simplest case, we are given a function f (x ) and two limits of integration a and b and the object is to approximate
Zb
f (x)dx.
a
There are methods that are completely deterministic — every time you run the program you will get exactly the same answer.
There is another class of methods that use random numbers to compute the value of definite integrals — they are called Monte Carlo methods, after the famous Monaco casino. They are uncompetitive for simple one-dimensional integrals, but prove to be superior for complicated integrals over many variables.
Numerical Methods & Scientific Computing: lecture notes
Stochastic simulation
Statistical errors
Hit-and-Miss method
One method — so-called hit-and-miss Monte Carlo — uses the relation of the integral to the area under the graph of f (x). Suppose we want the
value of Z b
f(x)dx
a
where f (x) 0 and we know the maximum value of f (x) over [a,b]: 0 f (x) M
Then the rectangle just including all the graph of f (x ) over [a,b] has area (b a)M. In other words, the fraction of the rectangle lying under the
c u r v e y = f ( x ) i s j u s t R ab f ( x ) d x
(b a)M
In the hit-and-miss method, we generate points uniformly in the rectangle (generate an x-coordinate from U(a,b), generate a y-coordinate from U(0,M), then form the point (x,y)) and count the fraction of them that lie under the curve y = f (x).
Numerical Methods & Scientific Computing: lecture notes
Stochastic simulation
Statistical errors
Bu↵on’s needle (1733)
If we randomly toss a needle of length l = 1 onto a floor with floorboards of width d = 2, what is the probability the needle crosses over a crack between floorboards?
The needle crosses a crack if y < l sin ✓ where y is the distance of the 2
centre of the needle to the nearest crack, and ✓ is the angle of the upper part of the needle relative to the cracks, measured from the positive direction.Since0