Ask your own question, for FREE!
Mathematics 19 Online
OpenStudy (raffle_snaffle):

Matlab

OpenStudy (raffle_snaffle):

% Many games require the player to roll two dice. The number on each % die can vary from 1 to 6. % (a) Use the rand function in combination with a rounding function % to create a simulation of one roll of one die. % (b) Use your results from part (a) to create a simulation of the % value rolled with a second die. % (c) Add your two results to create a value representing the total % rolled during each turn. % (d) Use your program to determine the values rolled in a favorite % board game, or use the game shown in Figure P3.20.

OpenStudy (raffle_snaffle):

@Kainui

OpenStudy (raffle_snaffle):

Currently watching youtube. I think i am overcomplicating this problem.....

OpenStudy (raffle_snaffle):

I am more stump on the math portion.

OpenStudy (reemii):

HOW TO DRAW RANDOM INTEGERS FROM {1,2,...,N} BASED ON THE \(\verb+rand()+\) FUNCTION. Draw the number of numbers you want. ``` randomnumbers = rand(2) ``` Since it's the uniform distribution, use this: \( X\sim \mathrm{Unif}(0,1) \Rightarrow 6X \sim \mathrm{Unif}(0,6)\). Therefore, multiply by 6 the randomnumbers: ``` randomnumbers6 = 5 * randomnumbers ``` Use `round` on \(\verb++\). You should use the \(\verb+ceiling+\) function: - any value from (0,1] -> 1 - any value from (1,2] -> 2 - any value from (2,3] -> 3 - etc. After these two operations, you obtained your die-results from rand() numbers.

OpenStudy (reemii):

The MATLAB function is called \(\verb+ceil(...)+\).

OpenStudy (reemii):

Try this: \(\verb+ceil(6* rand(2))+\). What is the result?

OpenStudy (raffle_snaffle):

ans = 1 5 5 1

OpenStudy (raffle_snaffle):

why are we using rand(2) though?

OpenStudy (raffle_snaffle):

why not rand(3 or 4 or 5)

OpenStudy (reemii):

sorry , I thought you needed to compute generate several numbers at the same type. Try: ceil(6*rand()).

OpenStudy (raffle_snaffle):

>> ceil(6*rand()) ans = 4

OpenStudy (reemii):

lots of times... you should see it works.. generating numbers from 1 to 6.

OpenStudy (raffle_snaffle):

@reemii what?

OpenStudy (reemii):

I meant: execute "ceil(6*rand())" many times, it should convince yourself that it gives numbers from 1 to 6.. with a probably uniform distribution

OpenStudy (raffle_snaffle):

okay I see.

jimthompson5910 (jim_thompson5910):

as I'm sure you can see, `rand(2)` will generate a random 2x2 matrix rand(3) will generate a random 3x3 matrix rand(4) will generate a random 4x4 matrix ... ... ... rand(N) will generate a random NxN matrix since you want a single random number, you want a random 1x1 matrix. Matlab thinks of scalar numbers as a 1x1 matrix. So you can say `rand(1)` or just say `rand()` to ensure the random result is between 1 and 6, you'll have to do 2 steps step 1) multiply the result of rand() by 6. This is so you get a result in the targeted range you want. In code, it would look like this `6*rand()` step 2) Use the ceiling function to ensure you land on a whole number. In code, it looks like this `ceil(6*rand())`

OpenStudy (raffle_snaffle):

Brb

OpenStudy (jtvatsim):

did you end up solving the problem @raffle_snaffle ? : )

OpenStudy (raffle_snaffle):

@jtvatsim no I didn't get b or c yet

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!