You are on page 1of 2

Assignment 6 and last

July 30
Assigned: Nov. 23 50 points
Due: Dec. 7 6
August

Problem 1

A Bernoulli matrix is one where all the elements are 1 or −1. Write a function BernoulliSings(N,T)
that uses Monte Carlo search with T trials to estimate the fraction of N × N Bernoulli matrices that
are singular (i.e. have rank less than N ). 20
For instance for N = 2 there are 16 Bernoulli matrices, of which 8 are singular (those where the
second row is equal to the first row, and those in which the second row is the negative of the first
row), so for large values of T, BernoulliSings(2,T) should return about 0.5.
It is believed that for large N, the value is on the order of 1/2N , so in experimenting you should
choose T to be at least about 100 · 2N to get meaningful answers. Of course, this in turn means that
you will not be able to run your program for values of N larger than 25 or 30 or so.

Problem 2

In n-dimensional space, the solid sphere of radius r at point p is the set of points x such that
Dist(x, p) ≤ r.
Write a function VolumeSphereIntersect(P,Q,R,S,T,W) which uses a Monte Carlo method with
T trials to compute the volume of the intersection of a sphere of radius R centered at P with a sphere
of radius S centered at Q. The function should return a confidence interval with confidence W. Here
P and Q are n-dimensional vectors; R, S are positive floating numbers, T is a positive integer; and W
is an floating point number between 0 and 1. 30
(It is possible to compute the exact answer, with some geometry and some calculus, but that is not
the assignment.)
To carry out the Monte Carlo method, use a uniform distribution within the box [B1 , C1 ]×[B2 , C2 ]×
[Bn , Cn ] where Bk = max(P[K] − R, Q[K] − S) and Ck = min P[K] + R, Q[K] + S).
Note that if the distance from P to Q is greater than R + S, then the two spheres do not intersect,
and so the function should simply return [0, 0].
Thus for example with

P=[1,0,-1]
Q=[2,1,0]
R=8
S=3
T=10000
W=0.95

you should generate 10,000 points within the box [−1, 5] × [−2, 4] × [−3, 3]. In this case, the sphere
around Q is inside the sphere about P, so it is particularly easy to calculate the exact answer: namely,
the volume of the sphere around Q, 4πS 3 /3 = 36π = 113.097. The volume of the box is 63 = 216,
so the fraction of the points
p in the box is f = 0.5236. The standard deviation of the fraction σ
therefore should be about f (1 − f )/10000 = 0.005. The 95% confidence interval should therefore

1
be about [113 − 1.95 · σ · 216, 113 + 1.95 · σ · 216] ≈ [111, 115], with, of course, some random variation
depending on the particular sample. Thus VolumeSphereIntersect(P,Q,R,S,T,W) should return
approximately [111, 115].

You might also like