Write a MATLAB program to simulate the following experiments

Write a MATLAB program to simulate the following experiments. Draw a dice 100 times. That is, generate a sequence of 100 random numbers from the set {1, ..., 6}. Call this sequence X_1, ..., X_100. Plot the histogram of X_1, ..., X_100, with bin centers {1, ..., 6}. Do not use a for-loop in your code. Submit your program and plot. Repeat (a) by drawing the dice 10000 times. Draw another dice 100 times. Call this sequence Y_1..., Y_100- Let Z_i = X_i + Y_i for i = 1, ..., 100. Plot the histogram of Z_1, ..., Z_100. Submit your plot. Repeat (d) by drawing the dices 10000 times. Using the histogram found in (d), find the probability that 4

Solution

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.

 Write a MATLAB program to simulate the following experiments. Draw a dice 100 times. That is, generate a sequence of 100 random numbers from the set {1, ..., 6
 Write a MATLAB program to simulate the following experiments. Draw a dice 100 times. That is, generate a sequence of 100 random numbers from the set {1, ..., 6

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site