Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and test a MATLAB program that simulates the experiment of rolling two die

ID: 671773 • Letter: W

Question

Write and test a MATLAB program that simulates the experiment of rolling two die. Your program should: Define a 6 by 6 matrix. Fill the matrix with elements whose values are ai = i + j. Prompt the user for a number between 2 and 12. Determine the probability that a roll of two die will result in the number that the user has specified. Repeat until the user provides a negative number as input. Simulate experiments that involve rolling two die. Allow the user to specify the number of times die are to be rolled. Keep track of the number of outcomes for each possible combination. Print out matrices that show the relative frequency of each outcome for experiments that simulate 36,1000 and 10,000 rolls of the die.

Explanation / Answer

clear all;
input_matrix=zeros(6,6);
for i=1:6
for j=1:6
input_matrix(i,j)=i+j;
end
end
disp(input_matrix);
i=1;
probability=0;
while(true)
choice=input('Enter number between 2 and 12');
if(choice<=-1)
break;
end
if(choice<=6)
probability=(choice-1)/36;
else
probability=(13-choice)/36;
end
disp(probability);
end
choice=input('Enter the No. of time dice should rolled');
result=zeros(1,11);
for i=1:choice
n1=round(rand*6);
n2=round(rand*6);
if n1<1
n1=1;
end
if n2<1
n2=1;
end
result(1,n1+n2-1)=result(1,n1+n2-1)+1;
n1=0;
n2=0;
end
disp('result');
disp(result);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote