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

Write a program using MATLAB that performs a simulated experiment of N trials, w

ID: 3546760 • Letter: W

Question

Write a program using MATLAB that performs a simulated experiment of N trials, where each trial simulates flipping a sequence of n fair coins, identified as coin-1 through coin-n. The program must allow the user to enter the number of coins to be used in each trial, and the total number of trials. The program is to keep count of the number of trials that resulted in zero heads, one head, two heads, and so on. The program must compute the percent relative frequency distribution of trials associated with each number of heads obtained in the simulation, as well as the theoretical percent relative frequency distribution. As an application, obtain the simulation and theoretical distributions for an experiment of 100 trials, with 30 coins being used in each trial.

Explanation / Answer

clc;

clear all;

close all;


N = input('trials');

n = input('coins');

for i=1:N %calculate number of heads in each trial (zero is heads)

count=0;

m=randint(1,n);

for j=1:n

if m(1,j)==0

count=count+1;

end

end

l(i)=count;

end


for j=1:n %grouping into number of trial with j heads

c=0;

for i=1:N

if l(i)==j

c=c+1;

end

end

p(j)=c;

end


percent=(p./n)*100; %percentage distribution

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