summaryrefslogtreecommitdiff
path: root/3808/CH7/EX7.8/Ex7_8.sce
blob: 583f32afd9306b292331ca998a67c3aad3859e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Chapter 07: Discrete Probability

clc;
clear;

times=7       //no of times flipped
total_outcomes=2**times          //outcomes power times flipped

function result=combination(n,r) //function definition
i=n
num=1
denominator=1
l=(n-r)+1
u=n
for i=l:u //to compute the value of the numerator
num=num*i
end
for j=1:r //to compute the value of the denominator
denominator=denominator*j
end
result=num/denominator 
return result
endfunction

reqd_heads=4      //no of heads coming up
ways_heads=combination(times,reqd_heads)
pH=2/3             //biased coin with probability of heads for 1 head
pT=1-pH         //probability of tails is total probability-heads probability
rpH=pH**reqd_heads    //probability of 4 heads outcome
rpT=pT**(times-reqd_heads)    //probability of tails outcome

prob_four_heads=ways_heads*rpH*rpT       //probability of exactly four heads appearing

disp(prob_four_heads,'The probability of exactly four heads appearing is')