Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Plz write codes using only MATLAB 8. Write and test a MATLAB function for simulating a roll of two dice function [diel, die2, resultstr]-rolldice; %

Plz write codes using only MATLAB

image text in transcribed

8. Write and test a MATLAB function for simulating a roll of two dice function [diel, die2, resultstr]-rolldice; % function [di cel , dice2, resultstr1-rolldice ; % simulates roll of two fair dice % returns % diel an integer in the range [1,6] % die2 an integer in the range [1,6] %resultstr string with result (sumd-die1+die2) ' snake eyes' sumd=2 ace-deuce sumd-3 yo boxcars natural' hard six 3 3 hard four 2 2 sumd=11 sumd=12 sumd=7 This function should not write anything to the screen. Now write a MATLAB program playdice that does the following: a. Set the number of throws, N, and a logical variable printresults. b. Initialize the random number generator using rng(' shuffle . ) c. (Optional, Advanced) Initialize an array roll sums-zeros (1,12) that will hold the number of times each possible outcome (from 2 to 12) occurs. d. In the "calculate games" section, play N throws of the dice using a for loop. Play each throw using the rolldice function. Print out the results (one roll per line) like this: Player rolls a 2 and a 5 natural Player rolls a 6 and a 2: Player rolls a 2 and a 1: ace-deuce Player rolls a 1 and a 4: Player rolls a 2 and a 6: Player rolls a 2 and a 2: hard four Player rolls a 6 and a 3: Player rolls a 3 and a 2: Player rolls a 3 and a 3: hard six Player rolls a 4 and a 1: Player rolls a 1 and a 3: Player rolls a 6 and a 6 boxcars

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe the patterns of business communication.

Answered: 1 week ago

Question

3. Provide two explanations for the effects of mass media

Answered: 1 week ago