CS211 Lab Policy:
Instructions:
You will create one MATLAB program file named lab5.m for this lab. For each step below, add appropriate MATLAB code and label each step with appropriate comments. Comments should always be placed above (or to the right) of the code they are explaining. You should nicely format all of your output using fprintf. Use the %d format descriptor to display logical values. Note that the fprintf function will display 0 for false and 1 for true and this is OK.
A = true; B = false; C = true; |
and then add code that evaluates and displays the logical values (either 0 or
1) for each of the following expressions.
A = true;
B = true;
C = true;
fprintf('%d & %d & %d produces %d\n', A, B, C, (A & B & C) );
A = true;
B = true;
C = false;
fprintf('%d & %d & %d produces %d\n', A, B, C, (A & B & C) );
etc.
rand(1,100)
|
% produces an row vector of 100 random values in the range [0.0, 1.0)
|
rand(1,100) * 6
|
% produces an row vector of 100 random values in the range [0.0, 6.0) |
floor(rand(1,100) * 6) |
% produces an row vector of 100 random integer values in the range [0, 5]. The floor function converts a floating point number into an integer value by removing any fractional part of the number. Therefore, floor(2.34) is equal to 2, and floor(5.95) is equal to 5.
|
floor(rand(1,100) * 6) + 1
|
% produces an row vector of 100 random integer values in the range [1, 6] |
Using the code in the algorithm section of lesson 5 as your guide, write code that generates 1000 random rolls of a die and counts the number of times a 6 is rolled. Display your answer to the screen.
Using the method of simulating die rolls from question 5, simulate the roll of two dice 1000 times and count the number of times that "snake eyes" (double 1) is rolled. Display your answer to the screen.
Turn-in:
Submit your lab5.m file.