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

Write a MATLAB program to simulate the following experiments. (a) Draw a dice 10

ID: 3371075 • Letter: W

Question

Write a MATLAB program to simulate the following experiments. (a) Draw a dice 100 times. That is, generate a sequence of 100 random numbers from the set 1,... ,6) Call this sequence Xi,... , Xioo. Plot the histogram of X1,..., Xio0, with bin centers {1,... ,6J. Do not tise a for-loop in your eode) Submit your program and plot. (b) Repeat (a) by drawing the dice 10000 times. c) Draw another dice 100 times. Cais sequence Y1,.., Yioo- Let Z, X,Y, for.,100. Plot the histogram of Z1,.... Z1o0- Submit your plot (d) Repeat (d) by drawing the dices 10000 times. (c) Using the histogram found in (d), find the probability that 4

Explanation / Answer

Before writing the program, like to explain the functions required for the program.

According to the program we need to generate a sequence of numbers so Loops are used in the program.

Loops: Loops are MATLAB constructs that permit us to execute a sequence of statements more than once.

For loop:

for k = expr   // k is a loop variable and expr is the loop control expression,

body

end

Example:

for k = 1:5

x = k

end

So we use a loop format for writing a sequence of numbers, X:Y. This is just shorthand for make a list of numbers from 1 to 6 increasing by 1 each step

n = 1e3;

Number_Dice = 1;

Roll1 = NULL // This initiates the variable

Roll2 = NULL

For (i in 1:100)

{

roll1[i] = Roll1dice(1)

roll2[i] = Roll1dice(1)

}

Sum(roll1 == roll2)

print(i)

RF11 = cumsum(S==11)/(1:100);

plot(1:100,RF11) // Plot the values

hold on

RF12 = cumsum(S==12)./(1:100);

plot(1:n,RF12,'r')

xlabel('Number of Rolls')

ylabel('Relative Frequency')

legend('Sum = 11', 'Sum = 12') grid on

figure S_Support = (1*Number_Dice):(6*Number_Dice);

hist(S,S_Support) // to draw the histogram

N_S_Sim = hist((roll1+roll2),density = 100 , breaks = 1:12,prob =T); // Breaks says that bins to start at 1, end at 12.

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