Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB HELP 1. Create a new matlab script file and type all of the code shown in grey below. Make sure to enter your name,

MATLAB HELP

image text in transcribed

1. Create a new matlab script file and type all of the code shown in grey below. Make sure to enter your name, the date and the file name at the top of your script. Do not try and use a copy/paste to do this since it generally will not work. Try to run your script and make sure that the script prints out a number close to 0.16 2. Modify the script so that it models the toss of 3 dice and estimates the probability that the sum of the 3 dice is 9 or 10 or 11. 3. Run the script 5 times and record the results 4. Print out your completed script and write the results of your five trials at the bottom of the page. 5. Submit this document at the start of the next class. % Last modified by: your name here % On: current date here % File Name: name of script file % ECE Dept CSUN clear all % clears all variables from the work space format compact % minimizes blank line in the output on the command window clc % clears the command window Since we are going to be using the random number generator, we next need to initialize it with the following two commands. rng('default'); Start random number gnerator rng('shuffle'); %and initialize to a random state As an example, we will use the rolling of a pair of dice and estimate the probability of getting a particular result. In this case we will try to estimate the probability of getting a total of either 3 or 5 on the faces of the two dice. First, we will set up the required parameters that will control the simulation. These fall into two classes. 1. The first class contains values that must be initialized. An example from this case is the "numGoodResults must be set to zero. 2. In contrast the second class contains values which can be selected by the user. We could have "Matlab" ask the user for these values but to keep things simple, we will just "hard wire" them in the code. The user can always just change these values in the script before re-running it. An example of a member of this class is "maxTries" which needs to be large enough to get a "good" estimate of the probabilities. numGoodResults - @; max Tries - 1800; The next step is to create a for loop that will simulate the roll of the dice. Notice that we will use the "randi(6,1)"function to generate single random numbers between 1 and 6. for rollCount - 1:maxTries di - randi(6,1); d2 - randi(6,1); dSum - dl + d2; if dSum-3 | Sum=-5 numGoodResults - numGoodResults +1; end end Next we estimate the probability by dividing the "numGoodResults" by "maxRolls" pSuccess - numGoodResults/maxTries pSuccess - 0.1680

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

Students also viewed these Databases questions