how can I use matlab to solve this probability problem?

Consider a binary code with 6 bits (0 or 1) in each code word.
(a) How many code words have exactly three successive 0’s? (b) What is the probability of the code word 000111?
I tried using matlab to no avail.

 Accepted Answer

I guess I’m revealing my intellectual ineptitude for all to see, but I actually wrote a short routine to explore that.
First, the probability of 000111 is 1/64. That is obvious.
Allowing for repeated occurrences, so that 0000 would count as two occurrences for instance, this codelet surprised me with the result (length(z)):
for k1 = 1:64
q(k1,:) = dec2bin(k1-1,6);
z3{k1} = strfind(q(k1,:),'000');
end
z = find(cell2mat(z3));
I wouldn’t mind an analytical proof of this. It’s not obvious to me.

4 Comments

I interpret the phrase "exactly three successive 0’s" to mean that, say, "000000" is not included, since it has more than exactly three successive 0's. With that understanding, the three successive zeros can occur at four different places. In the one where they start at the beginning, the fourth one must be a 1 and that leaves four possibilities for the final two. In the case the three start at the second place, both the first and the fifth place must be 1's which leaves just two possibilities for the sixth. This is a total of six possibilities. The remaining cases are a mirror image of these six, which gives us twelve possibilities altogether, hence a probability of 3/16.
When I though about it (before I wrote the codelet to explore all the possibilities), I got four possibilities in the more restrictive definition of ‘exactly three successive zeros’:
[000111], [100011], [110001], and [111000]
That comes out to 1/16. Combinations such as [000101], [000100], etc. don’t change that as I see it, since the other positions are not ‘three successive zeros’. Maybe I’m missing something.
The request stated "How many code words have exactly three successive 0’s?" It doesn't say, "how many have just three zeros and these must be successive." I see precisely twelve different six-bit words that have exactly three successive zeros, regardless of whether there might be other zeros:
000100
000101
000110
000111
001000
010001
011000
100010
100011
101000
111000
110001
However Chafah is the final arbiter of what was meant in the request.
OK. I read it differently at the outset.

Sign in to comment.

More Answers (1)

That's the kind of problem that can be solved mentally faster than a program can be written to do it. So why bother using matlab?

Community Treasure Hunt

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

Start Hunting!