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: 3546606 • 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 trial, and the 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 obrained in the simulation, as well as the theoretical percent relative frequency distribution, and save these results to an ASCII file. Import the file into Excel and generate a graph of the results that provides a visual comparison of the two distributions.

Explanation / Answer

clc; clear all; close all; N = input('trials to be done : '); n = input('coins in the experiment : '); H=zeros(1,n); % number of heads in each trials for i=1:N %calculate number of heads in each trial count=0; m=randi([0 1],1,n); % generate random 0 & 1 in every loop for j=1:n if m(1,j)==0 count=count+1; end end if count>0 H(count)=H(count)+1; end end
for i=1:n P(i)=(H(i)-min(H))/100; end plot(P); % Plot of number of heads in each trial experimently
%theoretically %c(n,k) = n!/(n-k)!k! p(n,k) = c(n,k)/2^n H1=zeros(1,n); for i=1:n H1(i)=factorial(n)/(factorial(n-i)*factorial(i)); P1(i)=H1(i)/2^n; end figure; plot(P1);
clc; clear all; close all; N = input('trials to be done : '); n = input('coins in the experiment : '); H=zeros(1,n); % number of heads in each trials for i=1:N %calculate number of heads in each trial count=0; m=randi([0 1],1,n); % generate random 0 & 1 in every loop for j=1:n if m(1,j)==0 count=count+1; end end if count>0 H(count)=H(count)+1; end end
for i=1:n P(i)=(H(i)-min(H))/100; end plot(P); % Plot of number of heads in each trial experimently
%theoretically %c(n,k) = n!/(n-k)!k! p(n,k) = c(n,k)/2^n H1=zeros(1,n); for i=1:n H1(i)=factorial(n)/(factorial(n-i)*factorial(i)); P1(i)=H1(i)/2^n; end figure; plot(P1);
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