How to perform Matlab programming for the biased coin toss simulation

Watch
vokoyo
Badges: 2
Rep:
?
#1
Report Thread starter 3 years ago
#1
Let the bias be the probability of turning up a head and denoted by the parameter q.

If we use a coin with the bias specified by q to conduct a coin flipping process d times, the outcome will be a sequence of heads and tails.

Then the probability - where nH is the number of heads turned up during d trials.

Now using such a simulated coin with q = ½ to conduct the experiments based on a sequence of outcomes generated by the random generator from computer.

For example, if the number generated by the random generator is less than 1/2, it assigned to be 0; otherwise, it will be assigned 1.

I would like to perform the Matlab programming with certain parameters for the Pattern Recognition (such as Binomial Distribution) as below -

(1) d = 100 and n =100 using a simulated coin with q = ¼ and ½.

(2) d = 10 and n =1000 using a simulated coin with q = ¼ and ½.

(3) d = 100 and n = 1000 using a simulated coin with q = ¼ and ½.

Kindly please provide your opinion and suggestion thus I will be able to improve my computing skills.

(The result of the execution from program will be drawn into histogram on the PowerPoint)
0
reply
Kevin De Bruyne
Badges: 21
Rep:
?
#2
Report 3 years ago
#2
(Original post by vokoyo)
Let the bias be the probability of turning up a head and denoted by the parameter q.

If we use a coin with the bias specified by q to conduct a coin flipping process d times, the outcome will be a sequence of heads and tails.

Then the probability - where nH is the number of heads turned up during d trials.

Now using such a simulated coin with q = ½ to conduct the experiments based on a sequence of outcomes generated by the random generator from computer.

For example, if the number generated by the random generator is less than 1/2, it assigned to be 0; otherwise, it will be assigned 1.

I would like to perform the Matlab programming with certain parameters for the Pattern Recognition (such as Binomial Distribution) as below -

(1) d = 100 and n =100 using a simulated coin with q = ¼ and ½.

(2) d = 10 and n =1000 using a simulated coin with q = ¼ and ½.

(3) d = 100 and n = 1000 using a simulated coin with q = ¼ and ½.

Kindly please provide your opinion and suggestion thus I will be able to improve my computing skills.

(The result of the execution from program will be drawn into histogram on the PowerPoint)
https://www.mathworks.com/help/stats/binornd.html

Binornd does part of what you're looking for.

I imagine you can produce nd observations in an n by d matrix, then apply functions to the rows or colums
0
reply
vokoyo
Badges: 2
Rep:
?
#3
Report Thread starter 3 years ago
#3
Matlab Programming Method - I get some errors for my coding sample as below



(1)



x = rand(0,1);

if(x<0.25),

toss = 0; %Head

else

toss = 1; %Tail

end

n = 100;

d = 100;

hist(y,0:n)



x = rand(0,1);

if(x<0.5),

toss = 0; %Head

else

toss = 1; %Tail

end

n = 100;

d = 100;

hist(y,0:n)
0
reply
NonIndigenous
Badges: 20
Rep:
?
#4
Report 3 years ago
#4
(Original post by vokoyo)
Matlab Programming Method - I get some errors for my coding sample as below



(1)



x = rand(0,1);

if(x<0.25),

toss = 0; %Head

else

toss = 1; %Tail

end

n = 100;

d = 100;

hist(y,0:n)



x = rand(0,1);

if(x<0.5),

toss = 0; %Head

else

toss = 1; %Tail

end

n = 100;

d = 100;

hist(y,0:n)
Image
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

What support do you need with your UCAS application?

I need help researching unis (20)
14.49%
I need help researching courses (8)
5.8%
I need help with filling out the application form (7)
5.07%
I need help with my personal statement (55)
39.86%
I need help with understanding how to make my application stand out (35)
25.36%
I need help with something else (let us know in the thread!) (3)
2.17%
I'm feeling confident about my application and don't need any help at the moment (10)
7.25%

Watched Threads

View All