필터 지우기
필터 지우기

Fair coin question. How can I find the shaded area under the curve of A whole or a particular bin area to find specific probability of either heads or tails

조회 수: 1 (최근 30일)
Hi, I am trying to develop a Matlab code from which I can enter a number of coins tossed and be able to obtain a normalized histogram from which I can tell the probability of either heads or tails. I want the x-labes to display TAILS and HEADS and the corresponding Bin area. I also want to have the formula from which I can calculate the shaded area of either heads or tails and tell the probability. This is my code.
Also I wish to super position of a Normal Gaussian bell and I want to demonstrate that by adding more coins, the probability approaches 0.5.
Please advise on how to change colors in the Bin area.
Thanks
clear all; %get rid of everything in memory
close all; %close all open figures
clc
%#Define the parameters
number of tossed coins n=10 %This number can vary
%S=["H", "T"]; %example of labels but I do not know how to implement it.
coin=randi([0, 1], 1, n) %probability range between 0 and 1; size of toss matrix is 1 row by n columns
Bins_Centers = [0 1]; %2 coins
d = diff(Bins_Centers)/2;
Bins_Edges = [Bins_Centers(1)-d(1), Bins_Centers(1:end-1)+d, Bins_Centers(end)+d(end)];
Bins_Edges(2:end) = Bins_Edges(2:end)+eps(Bins_Edges(2:end))
%Figure 1
screensize = get( groot, 'Screensize' );
f1=figure('Position', screensize)
ax1 = gca;
% edge= [0 1];%specify the edge of the histogram (as a vector)
h=hist(coin, Bins_Centers)
bar(Bins_Centers, h)
title(sprintf('Histogram generated from %d coin tosses', n));
xlabel(sprintf('Number of heads (0) and tails (1) in %d in coins', n));
ylabel('Count');
hold(ax1,'on')
%Figure 2
screensize = get( groot, 'Screensize' );
f2=figure('Position', screensize)
ax2 = gca;
freqs=histogram(coin, Bins_Edges);
title(sprintf('Histogram generated from %d coin tosses', n));
xlabel(sprintf('Number of heads (0) and tails (1) in %d in coins', n));
ylabel('Count');
hold(ax2,'on')
  댓글 수: 4
Torsten
Torsten 2023년 5월 3일
편집: Torsten 2023년 5월 3일
P(k tails in n trials) = P((n-k) heads in n trials)
This is reflected by
nchoosek(n,k) = nchoosek(n,n-k)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by