MAT LAB PROGRAM TO FIND OUT PROBABILITY OF HEAD AND TAILS COMES IN COIN TOSS

To find out probability of head and tails come in MAT LAB. write down code written below to your m-file and save it and run.
------------------------------------------------------------------------------------------------------------
%MAT LAB program to find out probability of head and tails comes in coin toss
%for simplicity let head=1 and tails=0
clc;
clear all;
n=input(' how many times you want to repeat the experiment : ')
a=rand(1,n);   % give the 1×n matrix of random entries of 0 to 1 value
b=round(a);   %rounding up the value generated by rand() function
probh=(length(find(b==1)))/n;  % formula to find out probability
probt=(length(find(b==0)))/n;
p=[probh probt];
x=[1 0];
bar(x,p)

------------------------------------------------------------------------------------------------------------

after run this program you will see the output as shown in below figure :


Comments

Popular posts from this blog

MATLAB program to find Frequency Modulation