# how can I use matlab to solve this probability problem?

5 views (last 30 days)
chafah zachary on 24 Mar 2014
Commented: Star Strider on 25 Mar 2014
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.

Star Strider on 25 Mar 2014
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.
Star Strider on 25 Mar 2014
OK. I read it differently at the outset.

Roger Stafford on 24 Mar 2014
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?