How to perform Matlab programming for the biased coin toss simulation
댓글 수: 3
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)
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개)
참고 항목
카테고리
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!