Coin toss simulation test
21 次查看(过去 30 天)
显示 更早的评论
Through the simulation, show that probability of getting HEAD by tossing a fair coin is about 0.5. Write your observation from the simulation run.
if possible please explain the steps as I am new
1 个评论
per isakson
2022-1-20
编辑:per isakson
2022-1-20
One way
vec = randi([0,1],1,1000);
number_of_heads = sum( vec );
number_of_tails = 1000 - number_of_heads
采纳的回答
KSSV
2022-1-20
编辑:KSSV
2022-1-20
n = 1000 ; % number of tosses
H = 0 ; % initialize Head count
T = 0 ; % initialize Tails count
% loop of toss
for i = 1:n
if rand > 0.5 % count as heads if random number is > 0.5
H = H+1 ;
else % count as tails if random num,ber is < 0.5
T = T+1 ;
end
end
% getting head
ph = H/n
% Getting Tails
Pt = T/n
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!