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.
B <- runif(100, min=0, max=1)
C <- runif(100, min=0, max=1)
# sum of probablity equals 1
punif(0.5, min(B),max(B)) + (1- punif(0.5, min(B),max(B)))
## [1] 1
punif(0.5, min(C),max(C)) + (1- punif(0.5, min(C),max(C)))
## [1] 1
# uniform distribution graph
# base/width= 1-0
# height/fx = 1/w
x=seq(0,1,length=100)
y=rep(1,100)
plot(x,y,type="l",xlim=c(0,1),ylim=c(0,1.5),lwd=2,col="red",ylab="p")
polygon(c(0,x,1),c(0,y,0),col="lightgray",border=NA)
lines(x,y,type="l",lwd=2,col="red")
Find the probability that
sum((B+C) < 1/2)/length(B)
## [1] 0.11
a <- 0
for (i in 1:length(B)){
if ((B[i] + C[i]) < 1/2){
a <- a + 1
}
}
a/length(B)
## [1] 0.11
sum((B*C) < 1/2)/length(B)
## [1] 0.86
b <- 0
for (i in 1:length(B)){
if ((B[i] * C[i]) < 1/2){
b <- b + 1
}
}
b/length(B)
## [1] 0.86
sum( abs((B-C)) < 1/2)/length(B)
## [1] 0.73
c <- 0
for (i in 1:length(B)){
if (abs(B[i] - C[i]) < 1/2){
c <- c + 1
}
}
c/length(B)
## [1] 0.73
d <- 0
for (i in 1:length(B)){
if (max(B[i],C[i]) < 1/2){
d <- d + 1
}
}
d/length(B)
## [1] 0.23
e <- 0
for (i in 1:length(B)){
if (min(B[i],C[i]) < 1/2){
e <- e + 1
}
}
e/length(B)
## [1] 0.79