Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Random Numbers/Provability

Subject: Random Numbers/Provability

From: Jose Valerio

Date: 18 Mar, 2009 02:13:01

Message: 1 of 8

Hello all,

I'm working with provability now and this is what I'm trying to do. Toss a dice for 100000 times (loop) and find the number of times the number 7 comes out. Then I have to find the empirical probability and conceptual probability.

Subject: Random Numbers/Provability

From: Roger Stafford

Date: 18 Mar, 2009 02:27:03

Message: 2 of 8

"Jose Valerio" <lapenda@gmail.com> wrote in message <gpplbd$ge6$1@fred.mathworks.com>...
> Hello all,
>
> I'm working with provability now and this is what I'm trying to do. Toss a dice for 100000 times (loop) and find the number of times the number 7 comes out. Then I have to find the empirical probability and conceptual probability.

  Hint: If you call on 'rand', multiply it by six, and apply 'ceil', guess what you've got!

Roger Stafford

Subject: Random Numbers/Provability

From: Jose Valerio

Date: 18 Mar, 2009 02:38:01

Message: 3 of 8

Great hint. I think I got it. At least the first part, I think I can handle the rest. Thanks a lot. I rounded out the numbers which make sence

nrep = 100000;
toss = round(rand(10000,2).*6);
r = sum(toss(:,1) + toss(:,2) == 7)

Subject: Random Numbers/Provability

From: Roger Stafford

Date: 18 Mar, 2009 02:47:02

Message: 4 of 8

"Jose Valerio" <lapenda@gmail.com> wrote in message <gppmq9$jld$1@fred.mathworks.com>...
> Great hint. I think I got it. At least the first part, I think I can handle the rest. Thanks a lot. I rounded out the numbers which make sence
>
> nrep = 100000;
> toss = round(rand(10000,2).*6);
> r = sum(toss(:,1) + toss(:,2) == 7)

  Don't use 'round'. There is a probability of 1/12 that you'll get a 'toss' of zero, which I don't think you want, and the probability of a six is only 1/12, which I also doubt if you want.

Roger Stafford

Subject: Random Numbers/Provability

From: Jose Valerio

Date: 18 Mar, 2009 02:57:01

Message: 5 of 8

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gppnb6$nde$1@fred.mathworks.com>...
> "Jose Valerio" <lapenda@gmail.com> wrote in message <gppmq9$jld$1@fred.mathworks.com>...
> > Great hint. I think I got it. At least the first part, I think I can handle the rest. Thanks a lot. I rounded out the numbers which make sence
> >
> > nrep = 100000;
> > toss = round(rand(10000,2).*6);
> > r = sum(toss(:,1) + toss(:,2) == 7)
>
> Don't use 'round'. There is a probability of 1/12 that you'll get a 'toss' of zero, which I don't think you want, and the probability of a six is only 1/12, which I also doubt if you want.
>
> Roger Stafford

but I will be getting decimal points when I execute the rand, a dice doesn't have decimal points.

Subject: Random Numbers/Provability

From: Matt Fig

Date: 18 Mar, 2009 03:03:02

Message: 6 of 8

hist(round(rand(1,100000)*6),7)
figure
hist(ceil(rand(1,100000)*6),6)

Hmmmm.....





%kWal,}mi`_}m}}fCrckscn}t_najm_}}Kf>cew}csgjmfmlgm__r8`__r%

Subject: Random Numbers/Provability

From: Jose Valerio

Date: 18 Mar, 2009 03:15:06

Message: 7 of 8

"Matt Fig" <spamanon@yahoo.com> wrote in message <gppo96$nlg$1@fred.mathworks.com>...
> hist(round(rand(1,100000)*6),7)
> figure
> hist(ceil(rand(1,100000)*6),6)
>
> Hmmmm.....
>
>
>
>
>
> %kWal,}mi`_}m}}fCrckscn}t_najm_}}Kf>cew}csgjmfmlgm__r8`__r%

now I get it, I had not used ceil before thanks

Subject: Random Numbers/Provability

From: Steven Lord

Date: 18 Mar, 2009 14:51:52

Message: 8 of 8


"Jose Valerio" <lapenda@gmail.com> wrote in message
news:gppmq9$jld$1@fred.mathworks.com...
> Great hint. I think I got it. At least the first part, I think I can
> handle the rest. Thanks a lot. I rounded out the numbers which make sence
>
> nrep = 100000;
> toss = round(rand(10000,2).*6);
> r = sum(toss(:,1) + toss(:,2) == 7)

If you're using release R2008b or later, use the RANDI function instead of
calling RAND and using ROUND, CEIL, FIX or FLOOR.

http://www.mathworks.com/access/helpdesk/help/techdoc/rn/brqyzsl-1.html#brqyzsl-3

You can also simplify your last line by making use of the dimension argument
to the SUM function. Suppose your instructor asked you to sum up ten
thousand trials of the sum of 10 six-sided dice and count how many trials
added up to 35. You wouldn't want to have to write toss(:, 1) + toss(:, 2)
+ toss(:, 3) + ... + toss(:, 10) would you? Try playing around with the
dimension argument of SUM and see if you can generalize this so you don't
need to list each column.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us