ENGR 17 Assignment 10 Due: Next Tuesday Create an A10 folder to hold all your work After solving each problem, copy any numeric answers into your script and comment out the whole problem 1) Script prob1.m: A smooth sine wave can be constructed with the equation V = 100 * sin( t/100 ) where t is a vector ranging from 0 to 1000 in steps of 1 Create 2 side-by-side subplots. In the first, plot the sinewave V and in the second plot the histogram, saving as prob1.jpg. Find the probability that -75 < V < 75 for any randomly chosen sample of V. Also, find the mean and standard deviation of the sinewave. Copy and paste all numeric results into your script. 2) Script prob2.m: PROBLEM STATEMENT: A game begins by choosing between dice A and dice B with some probability p. The dice thus selected is then tossed until a white face appears, at which time the game is concluded. Dice A has 4 red and 2 white sides. Dice B has 2 red and 4 white sides. After playing the game 1000 times it is observed that the probability that a game is concluded in exactly 3 tosses of the selected dice is 1/10. Find the value of probability p used to choose Dice A. SOLUTION: We'll begin by creating a function file for diceA and one for diceB. These functions will roll their respective dice (using a loop) until a white face appears and return the number of throws it took. Here's an example for diceA: function throws = diceA() throws=1; % we will throw at least once roll = floor(6*rand) + 1 % the value of our dice (1 to 6) while roll < 5 % as long as it's 1 – 4 (red) roll = floor(6*rand) + 1 % throw again throws=throws+1; % keep track of throws end Type in diceA and try it out at the command line to check that it works properly. When you are satisfied, suppress output by putting ; after each line. Make your diceB function in a similar fashion. Find the expected value of the values returned by diceA and diceB. Now in your prob2.m file, we are going to build a vector of 1000 game runs. We'll call it game. First establish p and set it equal to 0.5. This means we have a 50% chance of choosing either diceA or diceB. We'll create a loop where k counts from 1 to 1000. We'll generate a uniform random value between 0 and 1 and if the value is less than p we'll choose diceA, otherwise we'll choose diceB. Here are some code pieces to get you going: % prob2.m Finding p for dice game p = 0.5; % the probability of choosing diceA for k = 1:1000 if rand < p % we'll choose diceA with prob p game(k) = diceA % store the # throws of using diceA in cell k else % store the # throws using diceB in cell k of game end end Running your script now will produce the game vector of outcomes. To answer the question you now only have to do three things: a) determine the probability of finding a 3 in your game vector b) adjust p and rerun the script until you obtain a probability close to 0.1, with at 1% error (a final probability say between 0.0999 and 0.0101 c) Plot the histogram of the number of throws in the games vector using an x vector of [1:20] save as prob2.jpg 3) (1 point extra credit) Script prob3.m: If you live in Marina, a typical commute to MPC involves about 2 miles of surface streets where the speeds follow the probabilities: Speed Probablity 40 10% 30 70% 20 10% 5 10% There follows a 10 mile stretch of freeway where your speed can be either 70 mph (20% probability) or 55 mph (80% probability). There is then the dreaded stoplight at Aguajito: 30 seconds green and 90 seconds red To model surface streets, generate a uniform random value, val = rand; Then, use an if, elseif elseif else block to choose the speed. For example, if val < 0.1 speed = 40 elseif val < 0.8 speed = 30 etc... Once speed is selected you can compute the time for surface streets using surfTime = speed * 2 * 60; where the units will be in minutes. To model the stoplight, generate a new random value, stop = rand, and realize that ¼ of the time (stop<0.25) it is green and the wait is 0, while the rest of the time the wait is (1-stop)*120 seconds, where stop is the random value between 0 and 1. After 1000 commutes to work, plot the histogram of your commute time in minutes, and compute the expected value and standard deviation of it. Additional Final Project Ideas in Probability and Statistics: OPTION A: OPTION B: continued...
© Copyright 2026 Paperzz