Download Homework set 3

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Elementary mathematics wikipedia , lookup

Cartesian coordinate system wikipedia , lookup

Central limit theorem wikipedia , lookup

Tweedie distribution wikipedia , lookup

Law of large numbers wikipedia , lookup

Negative binomial distribution wikipedia , lookup

Exponential distribution wikipedia , lookup

Transcript
Homework set 3 - Solutions
Math 3200 – Renato Feres
1. Playing darts, I. In this experiment a person throws darts on a dartboard of radius 1. Each time the dart is
thrown, it is assumed to hit at a random point with coordinates (X , Y ) centered at the origin (the bull’s-eye),
where X and Y are normal random variables with mean 0 and standard deviations 0.2 and 0.1, respectively.
(These numbers indicate the level of skill of the player; big standard deviation is characteristic of a bad player.)
The next figure depicts the dart board with a circle of radius 0.3 in dashed lines, and 50 hit marks.
Do the following experiment: simulate 10000 throws of the dart and determine empirically (i.e., simply by counting the number of good hits over total number of throws) the probability that the player can hit within a radius
0.3 from the center. (The code used to produce the above figure is shown next. Although no graph is asked for
in this problem, you may find some of this script useful.)
#Draw a circle of radius 1 centered at the origin, in solid line:
a=seq(from=0,to=2*pi,length.out=100)
C=cos(a)
S=sin(a)
plot(C,S,type=’l’,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(-1,1)),ylim=range(c(-1,1)))
par(new=TRUE) #Superimpose the smaller circle to the one just drawn
#Draw another circle, now of radius 0.3, in dashed line
C1=0.3*cos(a)
S1=0.3*sin(a)
plot(C1,S1,type=’l’,lty=’dashed’,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(-1,1)),ylim=range(c(-1,1)))
#Now generate the random points and plot them over the dartboard
X=rnorm(100,mean=0,sd=0.2)
Y=rnorm(100,mean=0,sd=0.1)
par(new=TRUE)
plot(X,Y, cex=0.2,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(-1,1)),ylim=range(c(-1,1)))
Solution. Using the script:
N =
r =
sx =
sy =
X =
Y =
D =
n =
n/N
10000 #Number of throws of the dart
0.3
#Radius of aimed at region
0.2
#standard deviation of x-coordinate
0.1
#standard deviation of y-coordinate
rnorm(N,0,sx) #N values of X-coordinates
rnorm(N,0,sy) #N values of Y-coordinates
sqrt(X^2+Y^2) #distance to center (vector of length N)
sum(D<=r)
#number of hits within radius r
#ratio of successes over the total number of attempts
I obtained the approximate probability p ≈ n/N = 0.8384. (Taking bigger values of N I obtained: p ≈ 0.8356 for
N = 105 , p ≈ 0.8350 for N = 106 and p ≈ 0.8350 for N = 107 .)
2. Playing darts, II. Imagine that a truly awful player is playing darts in his room. A dartboard of radius 1 hangs at
the center of one wall. The rectangular wall has sides 6 by 8. Now the assumption is that all points on the wall
are equally likely to be hit. In other words, the coordinates X and Y of a hit are uniformly distributed over the
intervals [0, 6] and [0, 8], respectively.
(a) What is the exact probability that this player will hit the dartboard at all? (Do this by hand.)
(b) Obtain by simulation an approximation of the probability asked for in the first part of this problem. Suggestion: simulate 10000 throws and count the fraction that hit the dartboard. How well does your approximation compare with the exact value? (You may like to explore bigger numbers than10000, if it does not
take too long to run in your computer.)
(c) Draw a graphic similar to the above, now representing the rectangular wall in solid line, the dartboard at
the center of the wall in dashed line, and 200 hit marks generated from the uniform distribution.
Solution. (a) Under the assumption of uniform probability distribution, the probability of hitting inside the
dartboard is the quotient of areas:
p=
π
π
Area of dartboard
=
=
≈ 0.06545.
Area of wall
6 × 8 48
(b) One run of the following script produced the value 0.0671. This is a roughly in the ballpark. Using instead
N = 107 (which took about 2 seconds to run), I obtained the ratio n/N = 0.06543, which is quite a good approximation of the exact value. The script is this:
N=10^7
X=runif(N,0,8)
#Number of throws
#X coordinates of hit points
2
Y=runif(N,0,6)
#Y coordinates of hit points
H=((X-4)^2+(Y-3)^2<=1) #Vector of Trues (hit inside dartboard) or Falses
sum(H)/N
#Fraction of inside hits.
(c) For this I used the following script:
#Draw the rectangle
Xr = c(0,8,8,0,0)
Yr = c(0,0,6,6,0)
plot(Xr,Yr,type=’l’,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(0,8)),ylim=range(c(0,6)))
#Draw circle
par(new=TRUE)
a = seq(from=0,to=2*pi,length.out=100)
C = 4+cos(a)
S = 3+sin(a)
plot(C,S,type=’l’,lty=’dashed’,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(0,8)),ylim=range(c(0,6)))
#Draw hit marks
par(new=TRUE)
N=200
X = runif(N,0,8)
Y = runif(N,0,6)
plot(X,Y,cex=0.2,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(0,8)),ylim=range(c(0,6)))
The resulting graphic is below.
3. Movement of a (mathematical) water bug, I. Imagine a little water bug hopping about over the surface of a
lake according to the following rule. It starts at time T0 = 0 at the middle of the lake (coordinates (0, 0)); then at
random times T1 < T2 < . . . it jumps from its current position (X , Y ) to a new position (X + ∆X , Y + ∆Y ). The
time intervals ∆Ti = Ti+1 − Ti are independent exponential random variables with rate λ = 1, and the x and y
components of the jumps are independent normal variables of mean 0 and standard deviation 0.1.
(a) Draw (in solid line) a graph of the X -coordinate of the bug’s position as a function of time over the course
of 1000 steps.
(b) Draw (without connecting the dots) a graph containing 10000 points, each representing the final point of
an independent 100-steps path. This roughly shows the distribution of final positions of the bug’s motion.
3
(Here and below, use aspect ratio asp=1 for a nice graph. As a reference, I suggest that you draw a circle of
radius 1 in dashed line centered at the origin. When superimposing two graphs, make sure to set the range
of the x and y coordinates some that a common scale is set for both. You’ll need very small points to better
see the result; see the command cex I used for the dartboard figure.)
Solution. (a) The movement can be obtained from the following script:
N
lambda
sigma
T0
tau
Times
X0
Y0
Dx
Dy
X
Y
=
=
=
=
=
=
=
=
=
=
=
=
1000
1
0.01
0
rexp(N,lambda)
c(T0,T0+cumsum(tau))
0
0
rnorm(N,0,sigma)
rnorm(N,0,sigma)
c(X0,X0+cumsum(Dx))
c(Y0,Y0+cumsum(Dy))
The graph of the x-coordinate as a function of time is then given by
plot(Times,X,type=’l’,main=’X-coordinate of path versus time’)
X
0.0
0.2
0.4
0.6
X−coordinate of path versus time
0
200
400
600
Times
(b) This can be obtained as follows:
M
N
sigma
Xv
Yv
for (i
X0
Y0
Dx
Dy
= 10000
= 100
= 0.1
= matrix(0,1,N)
= matrix(0,1,N)
in 1:M){
= 0
= 0
= rnorm(N,0,sigma)
= rnorm(N,0,sigma)
4
800
1000
Xv[i]
Yv[i]
= sum(Dx)
= sum(Dy)
}
plot(Xv,Yv,cex=0.01,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(-4,4)),ylim=range(c(-4,4)))
par(new=TRUE)
a=seq(from=0,to=2*pi,length.out=100)
C=3*cos(a)
S=3*sin(a)
plot(C,S,type=’l’,lty=’dashed’,asp=1,axes=FALSE,xlab=’’,ylab=’’,
xlim=range(c(-4,4)),ylim=range(c(-4,4)))
4. Movement of a water bug, II. Suppose the same situation described in the previous problem. Assume that the
exponential rate parameter is λ = 10 min−1 .
(a) Let N be the random number of times the bug jumps over the course of 1 minute. Obtain 10000 values of
N by simulation and plot a histogram. Superimpose to your histogram the graph of the probability mass
function of a Poisson distribution with mean λ = 10. How good an agreement do you observe?
(b) Obtain 10000 values of the time it takes for the bug to jump 5 times and plot a histogram. Superimpose
to it the graph of the probability density function of the Gamma distribution with shape parameter 5 and
rate parameter 10. How good an agreement do you observe? (For a nice graph, I suggest: 100 bins and the
density plot drawn over the interval from 0 to 2.)
Solution. (a) The following graph
The script used to produce the above graph was
M=10000
tfinal=1
5
0.08
0.06
0.00
0.02
0.04
Density
0.10
0.12
Poisson, mean=10
0
5
10
15
20
25
number
lambda=10
Number=c(1:M)
for (i in 1:M){
t=0
N=-1
while (t<tfinal){
N=N+1
t=t+rexp(1,lambda)
}
Number[i]=N
}
hist(Number,breaks=-0.5+c(0:26),freq=FALSE,main=’Poisson, mean=10’,
xlab=’number’)
x=c(0:25)
lines(x,dpois(x,lambda),type=’b’)
The agreement is good.
(b) For this problem we may use the following script:
M
= 10000
N
= 5
lambda = 10
T=c(1:M)
for (i in 1:M){
T[i]=sum(rexp(N,lambda)) #Time of N jumps
}
hist(T,100,freq=FALSE,main=’Gamma distribution, shape=5, rate=10’,
6
1.0
0.0
0.5
Density
1.5
2.0
Gamma distribution, shape=5, rate=10
0.0
0.5
1.0
1.5
2.0
time
xlab=’time’)
x=seq(from=0,to=2,length.out=500)
lines(x,dgamma(x,5,10),type=’l’) #Density function of the gamma distribution.
The agreement seems fairly good.
7