Lab4 - Conditional Probability, Bayes' Theorem
Lab4 - Conditional Probability, Bayes' Theorem
Probability theory
and mathematical
statistics
CONDITIONAL PROBABILITY, BAYES'
THEOREM
Exercise 5.4 (M2)
Two dice are rolled. Find the probability that the sum of the numbers
obtained is 7 given the sum is odd.
𝐴−𝑡h𝑒 𝑠𝑢𝑚𝑖𝑠7
( 𝐴 ∨𝐵 )= 𝑃 ( 𝐴𝐵 )
𝑃
𝑃 ( 𝐵)
( 𝐴 𝐵 )= 6
6 7 8 9 10 11 12
𝑃
5 6 7 8 9 10 11 36
4 5 6 7 8 9 10
3 4 5 6 7 8 9
2 3 4 5 6 7 8 ( 𝐵 )= 18
𝑃
36
1 2 3 4 5 6 7
1 2 3 4 5 6
( 𝐴 ∨𝐵 )= 6/ 36 6
𝑃 = =1 /3
18/ 36 18
Exercise 5.5 (M3)
Two dice are rolled. Find the probability that at least one of them shows
six, given they show different values.
Hint:
6
5
(1;6)
(1;5)
(2;6)
(2;5)
(3;6)
(3;5)
(4;6)
(4;5)
(5;6)
(5;5)
(6;6)
(6;5)
𝐴 −𝑎𝑡 𝑙𝑒𝑎𝑠𝑡 𝑜𝑛𝑒 𝑠h𝑜𝑤𝑠6
2
𝑃 ( 𝐴𝐵 ) 4
𝑃 ( 𝐴 ∨𝐵 )= = = 2/ 3
𝑃 ( 𝐵) 3
4
Exercise 5.8*
Choose two points randomly from the unit interval. Find the probability
that both points are closer to a previously specified end point of the
interval, given their distance is less than 1/2.
1< 𝑦−𝑥< 1
−
Hint: 2 2
1
𝑦=
𝑥+ 2 ( 𝐴 ∨𝐵 )= 𝑃 ( 𝐴𝐵 )
𝑃
𝑃 ( 𝐵)
𝑦=𝑥
−
1
2
( 𝐵 )= 3
𝑃
1
2 4
( 𝐴 𝐵 )= 1
𝑃
4
1
1
2 𝑃 ( 𝐴 ∨𝐵 )=
3
Exercise 5.14
In a TV quiz show the player has to choose one from three envelopes. In
the first envelope there are 5 cards saying 'Sorry, next time', 3 cards
with 'You have won 100 euros' and 2 cards with 'You have won 500
euros'. The content of the second envelope: 2 cards 'Sorry, next time', 7
cards 'You have won 100 euros' and 1 card 'You have won 500 euros'.
The third envelope contains only 'Sorry, next time' cards. The player
chooses randomly an envelope and from the chosen envelope he
chooses a card. What is the probability that the player wins 500 euros?
𝐴 − 𝑤𝑖𝑛𝑛𝑖𝑛𝑔500 𝑒𝑢𝑟𝑜𝑠
( 𝐴 ∨𝐵 1) = 2
𝑃 ( 𝐴 ∨𝐵 2) = 1
𝑃 ( 𝐴 ∨𝐵 3 )= 0
𝑃
10 10 10
∑ 𝑃 ( 𝐴|𝐵 𝑖 ) 𝑃 ( 𝐵𝑖 )
𝑖=1
( 𝐵 4∨ 𝐴 ) = 2079
𝑃
9698
Exercise 5.22
During one of his journeys Ulysses arrives to a triple turnout. The first
road leads to Athens, the second to Mycenae, the third to Sparta.
Athenians are merchants, they like to sham their guests and in two third
of the cases they lie. Mycenaean are a bit better: they lie only in each
second case. Due to their strict traditions Spartans are honest, they
always tell the truth. Ulysses does not know where to go (the directions
are not indicated), so he chooses a road randomly. After arriving to the
city at the end of the road Ulysses asks a local man, how much is and
the answer is 4. What is the probability that Ulysses has arrived to
Athens?
𝐴−𝑎𝑟𝑟𝑖𝑣𝑒𝑑𝑡𝑜 𝐴𝑡h𝑒𝑛𝑠
( 𝐴 ∨𝐵 )= 𝑃 ( 𝐵∨ 𝐴 ) 𝑃 ( 𝐴 ) = 2
𝑃
𝑃 ( 𝐵) 11
Exercise 5.24
In an office equipped with mechanized administration three machines
classify the files. The first can process 10 files per day, the second 15,
while the third 25. The average numbers of misclassified files are 0.3,
0.9 and 0.5 per day, respectively. We choose a file randomly from the
daily production and we find that it has been misclassified. What is the
probability that the file was processed by the first machine?
𝐴 − 𝑚𝑖𝑠𝑐𝑙𝑎𝑠𝑠𝑖𝑓𝑖𝑒𝑑
𝑃 ( 𝐴 ∨ 𝐵𝑖 ) 𝑃 ( 𝐵𝑖 )
( 𝐵 𝑖∨ 𝐴 ) =
𝑃 3
∑ 𝑃 ( 𝐴|𝐵 𝑗 ) 𝑃 ( 𝐵 𝑗 )
𝑗=1
3 1
∗
100 5 3
𝑃 ( 𝐵 1∨ 𝐴 ) = =
3 10 6 15 2 25 17
∗ + ∗ + ∗
100 50 100 50 100 50
Exercise M1
Write a MATLAB code, that simulates 100000000 coin tosses and stores
the result of all the tosses in a single row vector! (head=0, tail=1)
Count the number of heads and tails and display the result!
tic tic
n=100000000 v2=randi(2,1,100000000)-1;
v=rand(1,n); sum(v2)
for i=1:n toc
if v(i)<0.5
v(i)=0;
else v(i)=1;
end
end
sum(v)
toc
Exercise M2
Write a MATLAB code, that simulates the experiment in Exercise 5.4!
Two dice are rolled. Find the probability that the sum of the numbers
obtained is 7 given the sum is odd.
s=0;
k=0;
for i=1:1000000
p=randi(6,1,2);
if rem(sum(p),2)==1
s=s+1;
if sum(p)==7
k=k+1;
end
end
end
disp('Number of cases when the sum is odd:')
s
disp('Number of cases when the sum is seven:')
k
k/s
Exercise M3
Write a MATLAB code, that simulates the experiment in Exercise 5.5!
Two dice are rolled. Find the probability that at least one of them shows
six, given they show different values.
s=0;
k=0;
for i=1:1000000
p=randi(6,1,2);
if p(1)~=p(2)
s=s+1;
if p(1)==6 | p(2)==6
k=k+1;
end
end
end
disp('Number of cases when they show different values:')
s
disp('Number of cases when at least one of them shows
six:')
k
k/s