Choose independently two numbers B and C at random from the interval [0, 1] with uniform density. Prove that B and C are proper probability distributions. Note that the point (B,C) is then chosen at random in the unit square.
Solution:
B and C are chosen randomly from the interval of unifrom density, so they should create uniform distribution with density 1/[0,1] or 1. Let’s test it.
# Clear plots
if(!is.null(dev.list())) dev.off()
## null device
## 1
# Clear console
cat("\014")
# Clean workspace
rm(list=ls())
B<-runif(100000,0,1)
C<-runif(100000,0,1)
hist(B)
hist(C)
The histograms look uniform
Find the probability that
Mathematical solution:
Please note that solving B+C=1/2. We get C=1/2-B
C1 <- function(B1) {0.5-B1}
# because C cannot be negative B will be from 0 to 0.5
integrate(C1,lower=0, upper=0.5)
## 0.125 with absolute error < 1.4e-15
Analytical solution
prob<-0
x<-c(0.0)
y<-c(0.0)
max<-500
for (i in (1:max))
{for (j in (1:max))
{ if (B[i]+C[j]<0.5) {prob<-prob+1/max^2
x<-c(x,B[i])
y<-c(y,C[j])
}
}
}
prob
## [1] 0.115836
plot(x,y)
Answer is pretty close.
C1 <- function(B1) {0.5/B1}
# because C cannot be more than 1 then for B from 0 to 0.5 it will be 1
myintegral<-integrate(C1,lower=0.5, upper=1)
1*0.5+myintegral$value
## [1] 0.8465736
Analytical solution
prob<-0
x<-c(0.0)
y<-c(0.0)
max<-300
for (i in (1:max))
{for (j in (1:max))
{if (B[i]*C[j]<0.5)
{prob<-prob+1/max^2
x<-c(x,B[i])
y<-c(y,C[j])
}
}
}
prob
## [1] 0.8359444
plot(x,y)
Answer is pretty close.
# We have for B on interval [0,0.5)
C1 <- function(B1) {B1+0.5}
# And we have for B on interval [0.5,1]
C2<-function(B1) {B1-0.5}
# We need to subtract integral of C2 from 1*0.5
integrate(C1,lower=0, upper=0.5)$value+(0.5-integrate(C2,lower=0.5, upper=1)$value)
## [1] 0.75
Analytical solution
prob<-0
x<-c(0.0)
y<-c(0.0)
max<-300
for (i in (1:max))
{for (j in (1:max))
{
if (abs(B[i]-C[j])<0.5) {prob<-prob+1/max^2
x<-c(x,B[i])
y<-c(y,C[j])
}
}
}
prob
## [1] 0.7502444
plot(x,y)
Close
This one is easy to solve using analytical method
prob<-0
x<-c(0.0)
y<-c(0.0)
max<-400
for (i in (1:max))
{for (j in (1:max))
{
if (max(B[i],C[j])<0.5) {
prob<-prob+1/max^2
x<-c(x,B[i])
y<-c(y,C[j])
}
}
}
prob
## [1] 0.2374313
plot(x,y)
Answer is 0.25
This one is easy to solve using analytical method
prob<-0
x<-c(0.0)
y<-c(0.0)
max<-400
for (i in (1:max))
{for (j in (1:max))
{
if (min(B[i],C[j])<0.5) {
prob<-prob+1/max^2
x<-c(x,B[i])
y<-c(y,C[j])
}
}
}
prob
## [1] 0.7375687
plot(x,y)
Answer is 0.75