필터 지우기
필터 지우기

How to perform Matlab programming for the biased coin toss simulation

조회 수: 10 (최근 30일)
vokoyo
vokoyo 2018년 4월 14일
편집: John D'Errico 2018년 4월 24일
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 (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)
  댓글 수: 3
John D'Errico
John D'Errico 2018년 4월 24일
편집: John D'Errico 2018년 4월 24일

Don't post your attempt as an answer. Moved to a comment, from vokoyo.

Matlab Programming Method - I get some errors for my coding sample as below

 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)
John D'Errico
John D'Errico 2018년 4월 24일
편집: John D'Errico 2018년 4월 24일

But now, tell us what errors you get? If you get an error, then read the error. Think about what it says. If you cannot understand the error message, then post the ENTIRE error message.

So, look at the error. What does it say? In this case, it will be some obscure problem, created because you did not even look at the very first thing you wrote.

x = rand(0,1);
x
x =
  0×1 empty double column vector

Look at the very first line you wrote. EXECUTE IT. LOOK AT THE RESULT. THINK ABOUT WHAT HAPPENED.

What does the help for rand tell you? Does rand(0,1) somehow know that maybe you wanted to generate a random number in the interval [0,1]? Or maybe you wanted it to sample from the integers in that range. How can rand know?

What rand does is go by how it is programmed. Not what you want it to do.

So rand(0,1) generates an empty vector. Not what you wanted of course.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by