Solve the problem using matlab codes Pete 2:1.30 points) Canada die following fu
ID: 639055 • Letter: S
Question
Solve the problem using matlab codes Pete 2:1.30 points) Canada die following function f(x): Given x a real random number between 0 and 6, f(x) gives an integer between 1 and 6. You can use this function as a model for rolling a die. Use this idea to write the following programs: (a) Use a for loop to create x. a real random number between 0 and 6, 1000 times. Inside the for loop, you should count how many times you get every single value corresponding to every single face of the die, Therefore, alien the loop is completely executed, you should know how many times each face was read. Finally, by dividing the number counted for each lace by the total number of the rolls of the die (1000 times in this case), calculate the probability of rolling each number (Recall that they should be all close to 1/6). (b) Assume that you are rolling two dice simultaneously (similar to what you would do in the game of backgammon). Use a similar algorithm find out the probability of the following two cases: Cast 1: Both dice roll 6. Case 2: The sum of two dice is 7. Hint: In part (b) you need to create two random numbers in the for loop.Explanation / Answer
disp('****question 1****')
frequency=zeros(1,6);
for i=1:1000
d=randi(6);
frequency(d)=frequency(d)+1;
end
probability=frequency/1000;
disp('probabilities are ...')
disp(probability')
disp('****question 2****')
both_six=0;
sum_seven=0;
for i=1:1000
d=randi(6);
e=randi(6);
if d==6 && e==6
both_six=both_six+1;
end
if d+e==7
sum_seven=sum_seven+1;
end
end
fprintf('probability of geting both 6 is %f and probability of getting sum as 7 is %f ',both_six/1000, sum_seven/1000);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.