lab6 - CS100M Lab Exercise 6 1 Roll a fair die Write a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS100M Lab Exercise 6 1 Roll a fair die Write a function rollDie(n) to simulate the rolling of one six-sided die n times. The function draws a histogram of the result. Below is an example histogram. Use a vector to count the number of times that each face occurs. 1 2 3 4 5 6 0 0.5 1 1.5 2 2.5 3 10 rolls of a fair die Outcome Count For example, use a vector count with six cells such that count(f) is the number of times that face f has occured. Solve this problem without using an if statement. You will need to generate random integers in [1. .6]. You can use a built-in function to create a row (vector) of six zeros: zeros(1,6) . Use the built-in function bar to draw a bar graph: bar(1:6, count) where the ±rst argument (1:6) contains the labels for the bars and the second argument ( count ) contains the counts for the six possible outcomes. Label the axes and the ±gure. 2 Roll multiple dice Write a function rollDice(n,d) to simulate the rolling of d six-sided dice n times. We de±ne the outcome
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This lab report was uploaded on 02/15/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 2

lab6 - CS100M Lab Exercise 6 1 Roll a fair die Write a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online