Jump to content

How to perform Matlab programming for the biased coin toss simulation

Featured Replies

 

 

 

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)

 

 

 

 

 

Pattern Recognition Project - Matlab Programming Method.doc

Edited by vokoyo

So you want flip a coin d times and plot the outcomes for different parameters of that coin? Or do you want to run a monte carlo simulation to check the probability of getting n heads from d flips? What have you tried so far?

  • Author

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)

 

 

 

Edited by vokoyo

Trouble shooting is one of the most important aspects of programming. I would recommend you go through your code line by line and check it does what you think it does. 

First instance what do you think rand(0,1) is doing? If you run just this line do you get a value of x you expect or something else? Type help rand  into your command window to see why it might not be doing what you expect and some suggested alternatives.

In addition to Prometheus excellent answer, I would just add that saying:

9 hours ago, vokoyo said:

I get some errors for my coding sample as below

is not very helpful. In general you need to say what sort of errors (including the specific error message): syntax errors, execution errors, just the wrong output , etc...

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.